It is currently April 20th, 2024, 4:52 am

Applying UTC Offset to a Time Stamp

Get help with installing and using Rainmeter.
gator
Posts: 14
Joined: May 29th, 2020, 3:35 pm

Applying UTC Offset to a Time Stamp

Post by gator »

I am using a website (Foreca) that provides time stamps (e.g. Observation, Sunrise, Sunset) in GMT/UTC times such as 2020-06-28T17:53Z, 10:29:08Z, and 00:18:18Z respectively. It also provides a time zone ID such as America/New_York. Using the time zone ID and another website (worldtimeapi.org), I am able to obtain the time zone abbreviation (EDT), whether or not that location is currently on DST (true), and the current UTC offset (including adjustment for DST where necessary) for the time zone (-04:00) along with other information.

I have been unable to apply the UTC Offset to any of these time stamps to convert the time stamp to the local time (America/New_York in this example) using Rainmeter's Time measure. For example, I can put the observation time stamp together so that it reads like 2020-06-28T17:53-04:00, but when I apply TimeStampFormat=%Y-%m-%dT%H:%M%z to it I get an error (Invalid TimeStampFormat: %Y-%m-%dT%H:%M%z). I'm not so sure though that seeing the GMT/UTC offset on a time stamp like this doesn't mean that the time has already been adjusted by the offset listed in the time stamp.

I would really like to do this using a Time measure (instead of mathmatically) as that should also account for any date differences as well as time differences if the location I'm looking at is on a different day than the observation was made in GMT/UTC.

I did see this thread - https://forum.rainmeter.net/viewtopic.php?t=32019, but it appears that the Lua code is only addressing time and not the fact that the date may also be different after the adjustment.

My goal is to be able to produce accurate sunrise/sunset times (6:29 am / 8:18 pm) and a meter that reads "Last Update: 6/28/2020 @ 1:53 pm EDT" from the time stamps shown here.

Any assistance would be greatly appreciated.

My setup:
Rainmeter 4.4.0.3360 beta (64-bit)
Language: English (1033)
Build time: 2020-06-11 14:34:23
Commit Hash: 33a476b9
Windows 10 Home 1903 64-bit (build 18362) - English (1033)
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Applying UTC Offset to a Time Stamp

Post by SilverAzide »

The Time measure does not appear to accept "%z" for TimeStampFormat. However, the way to do this is to set the timezone offset using the TimeZone option. Something like this...

Code: Select all

[MeasureTime]
Measure=Time
TimeStamp=[Your_Timestamp_From_Forca_Measure]
TimeStampFormat=%Y-%m-%dT%H:%M:%S
TimeZone=[Your_UTC_Offset_Measure]
DaylightSavingTime=[Your_DST_Measure]
DynamicVariables=1
The output will be the timestamp in that location's local time.
Gadgets Wiki GitHub More Gadgets...
gator
Posts: 14
Joined: May 29th, 2020, 3:35 pm

Re: Applying UTC Offset to a Time Stamp

Post by gator »

SilverAzide,

Thank you for responding! That still produces an error.

Code: Select all

[@CurrentObservationTimeStamp]
Measure=WebParser
URL=[@CurrentConditionsParent]
StringIndex=3

[@CurrentObservationTimeStamp2]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp]
DynamicVariables=1
TimeStampFormat=%Y-%m-%dT%H:%MZ
Format=%Y-%m-%dT%H:%M[@LocationUTCOffset]

[@CurrentObservationTimeStamp3]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp]
TimeStampFormat=%Y-%m-%dT%H:%MZ
TimeZone=[@LocationUTCOffset]
;DaylightSavingTime=[Your_DST_Measure]
DynamicVariables=1

[@CurrentObservationDate]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp3]
DynamicVariables=1
TimeStampFormat=%Y-%m-%dT%H:%MZ
Format=%#m/%#d/%Y

[@CurrentObservationTime]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp3]
DynamicVariables=1
TimeStampFormat=%Y-%m-%dT%H:%MZ
Format=%#I:%M %p
Substitute="AM":"am","PM":"pm"

[@ForecastDay1SunriseTimeStamp]
Measure=WebParser
URL=[@LocationForecastParent]
StringIndex=28

[@ForecastDay1SunsetTimeStamp]
Measure=WebParser
URL=[@LocationForecastParent]
StringIndex=29
Above is the pertinent code I am using. [@CurrentObservationTimeStamp] is the raw date returned from Foreca. [@CurrentObservationTimeStamp2] is my attempt at removing the capital Z from the returned data and adding the UTCOffset. Finally, [@CurrentObservationTimeStamp3] is my attempt at applying your suggestion. The DST adjustment is included in the UTCOffset I obtain so it is commented out here. I did attempt both TimeZone and DaylightSavingTime by hard-coding the information there and I still receive an error.

Here is the resulting information in About, Rainmeter:
TZOffset.jpg
As you can see, [@CurrentObservationTimeStamp3] just returns 00:53:00 from the original time stamp with no UTCOffset adjustment and no date.

My skin that produced the above measures:
Test.zip
You do not have the required permissions to view the files attached to this post.
gator
Posts: 14
Joined: May 29th, 2020, 3:35 pm

Re: Applying UTC Offset to a Time Stamp

Post by gator »

RM manual.jpg
You can see what the manual says regarding TimeZone and DaylightSavingTime. I have manually set TimeZone=-4 and DaylightSavingTime=0. Alternatively, I have manually set TimeZone=-5 and DaylightSavingTime=1.

"If specified, GMT time is used", the only way I can see to specify a TimeZone is with the %Z parameter which reads "Time zone name. These are for the system locale, and cannot be modified using FormatLocale. (e.g. "Eastern Standard Time")". I have left the capital "Z" at the end of the timestamp returned by Foreca and applied the %Z parameter to my TimeStampFormat - fail. I have replaced the "Z" with "GMT" - fail. I have even spelled out "Greenwich Mean Time" as the %Z description shows "Eastern Standard Time" spelled out, again - fail. I know I'm new to Rainmeter, but I'm at a complete loss.

I have even tried formatting the output as Format=%EY-%Om-%OdT%OH:%OM with and without the %Z parameter on the input measure. With the %Z parameter on the input measure - fail. Without the %Z parameter on the input measure, results in a perfectly formatted timestamp without any adjustment, meaning it looks just like @CurrentObservationTimeStamp without the 'Z'.

As you mentioned, the %z parameter is likewise not accepted.
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Applying UTC Offset to a Time Stamp

Post by SilverAzide »

gator wrote: June 29th, 2020, 2:14 am As you can see, [@CurrentObservationTimeStamp3] just returns 00:53:00 from the original time stamp with no UTCOffset adjustment and no date.
Well, the reason it is returning 00:53:00 is because you didn't supply the Format option to the measure, so you got the default %H:%M:%S format as a result. Your TimeZone option isn't correct either, your measure is returning "-04:00" but the option takes a numeric value in hours, i.e., "-4", so you need to convert the "+HH:MM" format to a valid number using a calc measure or two. Your DST measure is returning the string "true", but it must be "0" or "1". Remove the "Z" off the end of the TimeStampFormat option (the way it is in my post), add the format, DST, and time zone options to this measure and see what you get.
Last edited by SilverAzide on June 29th, 2020, 11:48 am, edited 1 time in total.
Gadgets Wiki GitHub More Gadgets...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5398
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Applying UTC Offset to a Time Stamp

Post by eclectic-tech »

~ Duplicate of SilverAzide's comment removed ~

This tip may help: https://forum.rainmeter.net/viewtopic.php?f=118&t=19354
gator
Posts: 14
Joined: May 29th, 2020, 3:35 pm

Re: Applying UTC Offset to a Time Stamp

Post by gator »

SilverAzide,

For now I will dispense with using the UTCOffset I am obtaining from worldtimeapi.org and just hard-code the TimeZone and DaylightSavingTime until I get the logic correct.

Code: Select all

[@CurrentObservationTimeStamp]
Measure=WebParser
URL=[@CurrentConditionsParent]
StringIndex=3

[@CurrentObservationTimeStamp2]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp]
DynamicVariables=1
TimeStampFormat=%Y-%m-%dT%H:%MZ
Format=%Y-%m-%dT%H:%M:00

[@CurrentObservationTimeStamp3]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp2]
TimeStampFormat=%Y-%m-%dT%H:%M:%S
TimeZone=-4
DaylightSavingTime=0
Format=%Y-%m-%dT%H:%M:%S
DynamicVariables=1
In @CurrentObservationTimeStamp2, I bring in @CurrentObservationTimeStamp which is the raw data obtained from WebParser. I remove the "Z" and add ":00" so that it will be formatted as in your suggestion. @CurrentObservationTimeStamp3 brings in @CurrentObservationTimeStamp2 with your suggested TimeStampFormat, then applies the TimeZone and DaylightSavingTime adjustments and similarly formats the output.

RM1.jpg
As you can see, there is no difference between @CurrentObservationTimeStamp2 and @CurrentObservationTimeStamp3. The application of TimeZone and DaylightSavingTime does not appear to have any effect unless I am still applying it incorrectly.

--------------------------

eclectic-tech,

Thank you for that link! Applying the logic from that thread to my @CurrentObservationTimeStamp3 and subtracting 14400 (4 hours at 3600 seconds/hour) produced the desired/expected results. Now that I have the logic down, I can work with the UTCOffset I am obtaining and convert it from +/-HH:MM to +/-seconds and use that as a variable.

Code: Select all

[@CurrentObservationTimeStamp]
Measure=WebParser
URL=[@CurrentConditionsParent]
StringIndex=3

[@CurrentObservationTimeStamp2]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=[@CurrentObservationTimeStamp]
DynamicVariables=1
TimeStampFormat=%Y-%m-%dT%H:%MZ
Format=%Y-%m-%dT%H:%M:00

[@CurrentObservationTimeStamp3]
Measure=Time
Group=UTCOffset
Disabled=1
TimeStamp=([@CurrentObservationTimeStamp2:Timestamp] - 14400)
Format=%Y-%m-%dT%H:%M:%S
DynamicVariables=1
RM2.jpg
And my meter was able to produce the results I was looking for:
RM3.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5398
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Applying UTC Offset to a Time Stamp

Post by eclectic-tech »

Great! :great: