It is currently March 28th, 2024, 12:39 pm

[Bug] Time measure's UTC offset is incorrect

Report bugs with the Rainmeter application and suggest features.
Post Reply
User avatar
JelleDekkers
Posts: 127
Joined: September 27th, 2017, 6:32 pm
Location: Netherlands
Contact:

[Bug] Time measure's UTC offset is incorrect

Post by JelleDekkers »

Just a simple time measure, right?

Code: Select all

[MeasureTimeZone]
Measure=Time
Format=%z
I live in the Netherlands and the current UTC offset is +0200 because of DST. During the winter, it's +0100. However, this measure outputs +0100 instead of +0200. I believe it's because Window's time zone is set to +1, which isn't the same as the UTC offset since UTC doesn't care about DST.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Bug] Time measure's UTC offset is incorrect

Post by jsmorley »

Correct. The %z time format code does not take into account Daylight Saving Time, as that is purely a local affectation, and has nothing to do with the standard offset from UTC.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Bug] Time measure's UTC offset is incorrect

Post by jsmorley »

You can use the TimeZone features of the SysInfo plugin to resolve this:

Code: Select all

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

[Variables]

[MeasureIsDST]
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_ISDST
IfCondition=MeasureIsDST < 1
IfTrueAction=[!SetOption MeasureTotalOffset Formula "Neg(MeasureStandardOffset / 60)"]
IfFalseAction=[!SetOption MeasureTotalOffset Formula "Neg((MeasureStandardOffset + MeasureDaylightOffset)/60)"]

[MeasureStandardOffset]
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_BIAS

[MeasureDaylightOffset]
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_DAYLIGHT_BIAS

[MeasureTotalOffset]
Measure=Calc

[MeterOffset]
Meter=String
MeasureName=MeasureTotalOffset
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Local time is %1:00 hours from UTC

1.jpg


2.jpg


I use the Neg() function to turn the result from the default, where it is the amount of minutes "from" the local time "to" UTC, into the amount of minutes "from" UTC "to" the local time.

I'm in the Eastern Time Zone in the US, which is currently in Daylight Saving Time and so the standard offset of -5:00 hours from UTC is currently -4:00 hours.

This gets a little trickier in the few places where the standard offset is not some even number of hours, but that can be solved as well, though I'm not going down that rabbit hole unless you really need me to. Just means you have to turn it all into "seconds" and do some additional stuff to turn seconds into hours and minutes. You don't want 4.5 hours, but 4:30 hours.

https://www.timeanddate.com/time/dst/
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Bug] Time measure's UTC offset is incorrect

Post by jsmorley »

To do this while accounting for a time zone offset from UTC that is or is not an even number of hours, you might:

Code: Select all

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

[Variables]

[MeasureStandardOffset]
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_BIAS
IfCondition=MeasureStandardOffset >= 0
IfTrueAction=[!SetOption MeasureFormattedOffset Format "-%3!02i!:%2!02i!"]
IfFalseAction=[!SetOption MeasureFormattedOffset Format "+%3!02i!:%2!02i!"]

[MeasureDaylightOffset]
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_DAYLIGHT_BIAS

[MeasureIsDST]
Measure=Plugin
Plugin=SysInfo
SysInfoType=TIMEZONE_ISDST
IfCondition=MeasureIsDST < 1
IfTrueAction=[!SetOption MeasureFormattedOffset SecondsValue "(([MeasureStandardOffset]*60))"]
IfFalseAction=[!SetOption MeasureFormattedOffset SecondsValue "(([MeasureStandardOffset]*60 + [MeasureDaylightOffset]*60))"]

[MeasureFormattedOffset]
Measure=UpTime

[MeterOffset]
Meter=String
MeasureName=MeasureFormattedOffset
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Local time is %1 hours from UTC

1.jpg


https://docs.rainmeter.net/manual/measures/uptime/

Note that the UpTime measure does not know or care about negative numbers, it is only about "elapsed seconds", so you have to determine if you are ahead or behind UTC and force a static - or + symbol on the Format option as needed.

Search keys: Timezone Offset Daylight
Post Reply