It is currently April 16th, 2024, 2:34 pm

Timezones in Time measures

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Timezones in Time measures

Post by Yincognito »

I have something similar to the following (simplified) code in one of my skins, and I need some sort of an "expert advice" on it:

Code: Select all

[Variables]
Realtime=1
Time=2021-11-18 15:50:00
Rate=1

[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1

---Measures---

[Time]
Group=TimeGroup
Measure=Time
TimeStamp=#Time#
TimeStampFormat=%Y-%m-%d %H:%M:%S
Format=%Y-%m-%d %H:%M:%S
TimeZone=0
DaylightSavingTime=0
OnUpdateAction=[!SetOption Time TimeStamp "((#*Realtime*#=1)?(-1):([*Time:Timestamp*]+#*Rate*#*240))"][!SetOption Time TimeStampFormat ""]
DynamicVariables=1

[TimezoneLocal]
Group=TimeGroup
Measure=Time
Format=%z
RegExpSubstitute=1
Substitute="^(.{1})(.{2})(.{2})$":"\1\2.\3"
DynamicVariables=1

[TimeLocal]
Group=TimeGroup
Measure=Time
TimeStamp=([Time:Timestamp][TimezoneLocal]*60*60)
Format=%Y-%m-%d %H:%M:%S
DynamicVariables=1

---Meters---

[Text]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time
MeasureName2=TimeLocal
MeasureName3=TimezoneLocal
Text="Time         = %1#CRLF#Time (local) = %2#CRLF#Timezone     = %3#CRLF#Realtime     = #Realtime##CRLF#Speed Factor = #Rate#"
LeftMouseUpAction=[!TogglePauseMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MiddleMouseUpAction=[!SetVariable Realtime (1-#Realtime#)][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MouseScrollUpAction=[!SetVariable Rate (Clamp((#Rate#+1),-360,360))][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Rate (Clamp((#Rate#-1),-360,360))][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
DynamicVariables=1
TimeAndTimezones.jpg
Basically, I have a Time measure getting the UTC/GMT time (realtime or 25ms simulated time, depending on the corresponding variable), to which I can assign a "start time" value aka #Time# and then let it "play" either at a realtime or at an adjustable speed (left click pauses time, middle click toggles between realtime and simulated time, scrolling adjusts the simulated time speed factor).

The thing is that I want to "attach" to the said UTC Time measure a local Time measure, automatically if possible via [Time:Timestamp] and local timezone detection (NOT hardcoded!). For now, I use a rather rudimentary method of adding the timezone to the UTC time, but I would preferably avoid doing so if there's a simpler method to do it. I'd also want to take the daylight saving into account (still not entirely sure about that though).

My questions are:
- is it possible to do this "automatically" / simple by using some timezone identifier in the local Time measure, instead of adding all kinds of timezone or daylight saving stuff to the main timestamp?
- if the answer above is no, what method would you recommend (e.g. Time vs SysInfo measures) and what / how exactly should I add them to get the local time equivalent of the UTC? I saw somewhere a skin by jsmorley that did something similar, but I can't remember where and whether all the stuff there would really be necessary in my case...
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Timezones in Time measures

Post by jsmorley »

No idea what you are really going for, TLDR I'm afraid.

But take a look at this skin to see if it helps:

https://forum.rainmeter.net/viewtopic.php?p=160003#p160003
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Timezones in Time measures

Post by Yincognito »

jsmorley wrote: November 20th, 2021, 5:12 pm No idea what you are really going for, TLDR I'm afraid.

But take a look at this skin to see if it helps:

https://forum.rainmeter.net/viewtopic.php?p=160003#p160003
Yes, that's the skin I was talking about, but it does slightly different things than what I need. :D
In short, I'm interested if there's a simple way (i.e. not involving dozens of measures) to "link" a local Time measure to an UTC one. You know, since the %z format code doesn't work for timestamps, and you can't control the displayed time using the Timezone option of Time measures like:

Code: Select all

[TimeUTC]
Group=TimeGroup
Measure=Time
Timestamp=2021-11-18 15:50:00
TimeStampFormat=%Y-%m-%d %H:%M:%S
Format=%Y-%m-%d %H:%M:%S
Timezone=0
DynamicVariables=1

[TimeLoc]
Group=TimeGroup
Measure=Time
Timestamp=2021-11-18 15:50:00
TimeStampFormat=%Y-%m-%d %H:%M:%S
Format=%Y-%m-%d %H:%M:%S
Timezone=local
DynamicVariables=1
and display, say, 2021-11-18 17:50:00 in the TimeLoc measure when the local timezone is +2.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Timezones in Time measures

Post by Yincognito »

jsmorley wrote: November 20th, 2021, 5:12 pmBut take a look at this skin to see if it helps:

https://forum.rainmeter.net/viewtopic.php?p=160003#p160003
Ok, using the hints in your skin and the formulas from the Sysinfo page in the manual, I managed to make my skin correct and relatively simple, I think (the TimeLocal measure):

Code: Select all

[Variables]
Realtime=1
Time=2021-11-18 15:50:00
Rate=1

[Rainmeter]
Update=25
DynamicWindowSize=1
AccurateText=1

---Measures---

[Time]
Group=TimeGroup
Measure=Time
TimeStamp=#Time#
TimeStampFormat=%Y-%m-%d %H:%M:%S
Format=%Y-%m-%d %H:%M:%S
TimeZone=0
DaylightSavingTime=0
OnUpdateAction=[!SetOption Time TimeStamp "((#*Realtime*#=1)?(-1):([*Time:Timestamp*]+#*Rate*#*240))"][!SetOption Time TimeStampFormat ""]
DynamicVariables=1

[TimeZoneBias]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_BIAS

[DSTStatus]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_ISDST

[DSTStandardBias]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_STANDARD_BIAS

[DSTDaylightBias]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_DAYLIGHT_BIAS

[TimeLocal]
Group=TimeGroup
Measure=Time
TimeStamp=([Time:Timestamp]-([TimeZoneBias:]+([DSTStatus:]=-1?0:([DSTStatus:]=0?[DSTStandardBias:]:[DSTDaylightBias:])))*60)
Format=%Y-%m-%d %H:%M:%S
DynamicVariables=1

[TimeZoneOffset]
Group=TimeGroup
Measure=Time
Format=%z
DynamicVariables=1

---Meters---

[Text]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time
MeasureName2=TimeLocal
MeasureName3=TimeZoneOffset
Text="Time         = %1#CRLF#Time (local) = %2#CRLF#Timezone     = %3#CRLF#Realtime     = #Realtime##CRLF#Speed Factor = #Rate#"
LeftMouseUpAction=[!TogglePauseMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MiddleMouseUpAction=[!SetVariable Realtime (1-#Realtime#)][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MouseScrollUpAction=[!SetVariable Rate (Clamp((#Rate#+1),-360,360))][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Rate (Clamp((#Rate#-1),-360,360))][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
DynamicVariables=1
I do have one last question though: is there any way in Rainmeter to get the state of Daylight Savings Time for a past or future date, and not just its current state (assuming its biases don't change; if they do, maybe get the similar biases as well)? If not, would you think it would be a good idea to add such a possibility to Rainmeter? I mean, folks don't always use only the current time in Time measures, and I suppose having the possibility to see if the Daylight Savings Time was or would be in effect 6 months ago or 6 months from now (and know its bias then) would be useful.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Timezones in Time measures

Post by Yincognito »

For reference and in case anyone else needs something similar in the future, I managed to achieve what I wanted by comparing the (UTC converted) DSTStartYYYY and DSTEndYYYY timestamps of the "current" (realtime or simulated) year to the "current" UTC timestamp, in order to set the DST bias accordingly. It should work for any past, present or future date from 01.01.1601 to 31.12.9999. I set the start date to the day just before the date where my local DST changes to better see how it works. In theory, I should have used the local year (and not the UTC year) in the DSTStartYYYY and DSTEndYYYY measures since they work with the local time, but then a DST never falls during the 1st of January anywhere, for this slight inconsistency to matter due to timezone differences when passing in a "new" year:

Code: Select all

[Variables]
Realtime=0
Time=2021-03-27 00:00:00
Rate=15

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[Time]
Group=TimeGroup
Measure=Time
TimeStamp=#Time#
TimeStampFormat=%Y-%m-%d %H:%M:%S
Format=%Y-%m-%d %H:%M:%S
TimeZone=0
DaylightSavingTime=0
OnUpdateAction=[!SetOption Time TimeStamp "((#*Realtime*#=1)?(-1):([*Time:Timestamp*]+#*Rate*#*240))"][!SetOption Time TimeStampFormat ""]
DynamicVariables=1

[Year]
Group=TimeGroup
Measure=Time
TimeStamp=([Time:Timestamp])
Format=%Y
TimeZone=0
DaylightSavingTime=0
DynamicVariables=1

[TimeZoneBias]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_BIAS

[DSTStatus]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_ISDST

[DSTStandardBias]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_STANDARD_BIAS

[DSTDaylightBias]
Group=TimeGroup
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_DAYLIGHT_BIAS

[DSTStart]
Group=TimeGroup
Measure=Time
TimeStamp=DSTStart[Year]
Format=%Y-%m-%d %H:%M:%S
DynamicVariables=1

[DSTEnd]
Group=TimeGroup
Measure=Time
TimeStamp=DSTEnd[Year]
Format=%Y-%m-%d %H:%M:%S
DynamicVariables=1

[DSTBias]
Group=TimeGroup
Measure=Calc
Formula=([DSTStatus:]=-1?0:(([Time:Timestamp]>=[DSTStart:Timestamp]+([TimeZoneBias:]+[DSTStandardBias:])*60)&&([Time:Timestamp]<[DSTEnd:Timestamp]+([TimeZoneBias:]+[DSTDaylightBias:])*60)?[DSTDaylightBias:]:[DSTStandardBias]))
DynamicVariables=1

[TimeLocal]
Group=TimeGroup
Measure=Time
TimeStamp=([Time:Timestamp]-([TimeZoneBias:]+[DSTBias:])*60)
Format=%Y-%m-%d %H:%M:%S
DynamicVariables=1

[TimeZoneOffset]
Group=TimeGroup
Measure=Time
Format=%z
DynamicVariables=1

---Meters---

[Text]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
MeasureName=Time
MeasureName2=TimeLocal
MeasureName3=TimeZoneBias
MeasureName4=DSTBias
Text="Time         = %1#CRLF#Time (local) = %2#CRLF#TZ Bias      = %3#CRLF#DST Bias     = %4#CRLF#Realtime     = #Realtime##CRLF#Speed Factor = #Rate#"
LeftMouseUpAction=[!TogglePauseMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MiddleMouseUpAction=[!SetVariable Realtime (1-#Realtime#)][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MouseScrollUpAction=[!SetVariable Rate (Clamp((#Rate#+1),-360,360))][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetVariable Rate (Clamp((#Rate#-1),-360,360))][!UpdateMeasureGroup TimeGroup][!UpdateMeter *][!Redraw]
DynamicVariables=1
TimeTimezonesDST.jpg
In the end, the directions suggested by jsmorley were spot on, though I didn't get away with less than one short of a dozen measures. I'm satisfied with the result - it worked prety well for a TLDR post. :lol:
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Timezones in Time measures

Post by eclectic-tech »

Nice work Yincognito! :thumbup:

I can't wait for people to finally decide to completely eliminate DST... but in the meantime your work will come in handy!
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Timezones in Time measures

Post by Yincognito »

eclectic-tech wrote: November 21st, 2021, 3:41 am Nice work Yincognito! :thumbup:

I can't wait for people to finally decide to completely eliminate DST... but in the meantime your work will come in handy!
Thanks, but it wasn't that much of a "work", other than the formula in [DSTBias], and that became logical once I realized I could use those DST...YYYY timestamps and understood how UTC relates to local time, timezone bias and DST bias. I'm not much of a Time measure expert, but I did need this and it came handy for me as well, for my animated Earth.

I don't have a strong opinion regarding eliminating DST - doing so would indeed make things simpler and unified yet would probably create other side effects. There are steps to elimnate it here in the EU, but such things take time to make it right and can cause controversies, not to mention that there are subject to the slow speed of the political apparatus. :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Timezones in Time measures

Post by death.crafter »

eclectic-tech wrote: November 21st, 2021, 3:41 am
Is that like a "pengcrow" or a "crownguin"?
from the Realm of Death
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Timezones in Time measures

Post by eclectic-tech »

death.crafter wrote: November 22nd, 2021, 6:23 am Is that like a "pengcrow" or a "crownguin"?
:lol:
It's a skinny cousin of a Turkey ... Happy Thanksgiving! :D
User avatar
Yincognito
Rainmeter Sage
Posts: 7118
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Timezones in Time measures

Post by Yincognito »

death.crafter wrote: November 22nd, 2021, 6:23 amIs that like a "pengcrow" or a "crownguin"?
How about yours? Never figured out whether that was a pig, a dog, or a piggy dog. Oh well, nevermind, I'll just picture it as (notice another cousin of a turkey in the corner as well)... :p
Image
eclectic-tech wrote: November 22nd, 2021, 12:46 pm :lol:
It's a skinny cousin of a Turkey ... Happy Thanksgiving! :D
So basically, a skinny living dinosaur cousin of another living dinosaur from Turkey, celebrating Thanksgiving... :???:
Image
... or just the intricacies of choosing a profile pic. :sly:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth