It is currently April 19th, 2024, 9:39 pm

Manage UTC time

Get help with creating, editing & fixing problems with skins
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Manage UTC time

Post by brax64 »

Hi all,

I've this measure/meter

Code: Select all

[Date]
Measure=Time
Format=%m/%d,%Y %H:%M UTC
TimeZone=-1
OnUpdateAction=[!UpdateMeter LastUpdate][!Redraw]
UpdateDivider=#UpdateRate#

[LastUpdate]
Meter=String
MeasureName=Date
Text=%1
UpdateDivider=-1
That, If I'm not mistaken, return UTC time (i.e. 09/02,2020 16:40 UTC)
How can I manage it to add a flag (aka text..) to the LastUpdate meter like "Open" or "Closed" (i.e. 09/02,2020 16:40 UTC Open), knowing that will be "Closed" every day from 21:00 to 22:00 and from Friday 21:00 to Sunday 22:00 (UTC time), also I don't want the day of the week in the resulting text.
Thanks in advance for any hint!
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Manage UTC time

Post by balala »

brax64 wrote: September 2nd, 2020, 6:49 pm How can I manage it to add a flag (aka text..) to the LastUpdate meter like "Open" or "Closed" (i.e. 09/02,2020 16:40 UTC Open), knowing that will be "Closed" every day from 21:00 to 22:00 and from Friday 21:00 to Sunday 22:00 (UTC time), also I don't want the day of the week in the resulting text.
There is a tricky workaround, which is not easy to be understood, however I believe it is the simplest solution.
You need a new Time measure, with the same settings as [Date] and with a proper format, to can check the condition and act accordingly. So, add the following measure to your code:

Code: Select all

[MeasureCondition]
Measure=Time
Format=%#H.%u
TimeZone=-1
IfCondition=((Trunc([#CURRENTSECTION#])=21)||((Round(Frac([#CURRENTSECTION#]),2)=0.5)&&(Trunc([#CURRENTSECTION#])>=21))||(Round(Frac([#CURRENTSECTION#]),2)=0.6)||((Round(Frac([#CURRENTSECTION#]),2)=0.7)&&(Trunc([#CURRENTSECTION#])<22)))
IfTrueAction=[!SetOption LastUpdate Text "%1 (Closed)"][!UpdateMeter "LastUpdate"][!Redraw]
IfFalseAction=[!SetOption LastUpdate Text "%1 (Open)"][!UpdateMeter "LastUpdate"][!Redraw]
DynamicVariables=1
See that this measure returns a decimal number. The integer part of it is the hour (in 24-hours format), while its fractional part is the day (with 0.1 meaning Monday and 0.7 meaning Sunday). Now we have to check distinctly the integer and the fractional part of the returned value. To do this, I used Trunc and Frac functions into the IfCondition option. Namely:
  • The (Trunc([#CURRENTSECTION#])=21) condition checks if the hour is 21, in which case the day doesn't matter.
  • The ((Round(Frac([#CURRENTSECTION#]),2)=0.5)&&(Trunc([#CURRENTSECTION#])>=21)) condition checks if the hour is larger or equal to 21 AND the day is 5 (Friday).
  • The (Round(Frac([#CURRENTSECTION#]),2)=0.6) checks if the day is Saturday (6). In this case the hour doesn't have to be checked, so there is no condition related to the integer part of the number.
  • Finally the ((Round(Frac([#CURRENTSECTION#]),2)=0.7)&&(Trunc([#CURRENTSECTION#])<22)) condition checks if the day is Sunday (7) AND the hour is up to 22.
In any of the above cases, the condition is true and accordingly the flag is set to Closed, otherwise it is set to Open.
Please check the code of the above measure and let me know if there is any problem with it. Hope it's not, but please check it.


NOTE: I removed the other topic of you about the same question from the Help: Rainmeter Application section.
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Manage UTC time

Post by brax64 »

balala wrote: September 2nd, 2020, 7:11 pm There is a tricky workaround, which is not easy to be understood, however I believe it is the simplest solution.
...
Hi Balala,

That, to me, looks brilliant!
Really thanks, very nice and kind from you to spent time dissecting and explaining all the steps, understood exactly how it works.
Already implemented in my code and, as for now (19:10 UTC), it's rightfully showing "(Open)", I'll wait for the 21:00 hour to see if it behaves as expected (but I'm pretty confident it will..).
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Manage UTC time

Post by balala »

brax64 wrote: September 2nd, 2020, 7:19 pm Really thanks, very nice and kind from you to spent time dissecting and explaining all the steps, understood exactly how it works.
Was my pleasure as well. Your question was a really challenging one, I enjoyed solving it.
brax64 wrote: September 2nd, 2020, 7:19 pm I'll wait for the 21:00 hour to see if it behaves as expected
Please let me know if it does (or doesn't).
brax64 wrote: September 2nd, 2020, 7:19 pm (but I'm pretty confident it will..).
Hope the same, but let's see...
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Manage UTC time

Post by brax64 »

balala wrote: September 2nd, 2020, 7:44 pm Please let me know if it does (or doesn't).
...
Hi Balala,
as expected, you nailed it! It's working perfectly, so I do expect that will be no issue for the week end check...

Now I've another couple of points if I'm allowed to pick your brain again:
  • for what I can see in the Rainmeter log, the date value of Format=%#H.%u has only 1 decimal digit (ie 15.3) so I was wondering about the necessity of the "Round" function in ((Round(Frac([#CURRENTSECTION#]),2)=0.5). Can be written as (Frac([#CURRENTSECTION#])=5) ?
  • I would like, if it's possible, to update my skin at a precise point in time. My skin has an UpdateRate=600 (every 10 min) so I would like that the very first update (or refresh) happening at the closest 10min mark, (like 15:00 15:10 15:20 and so on), I mean if I load the skin (ore refresh it...) at 15:02, it will update at 15:10. Hope to have made myself clear :D
User avatar
SilverAzide
Rainmeter Sage
Posts: 2604
Joined: March 23rd, 2015, 5:26 pm

Re: Manage UTC time

Post by SilverAzide »

brax64 wrote: September 2nd, 2020, 9:21 pm I would like, if it's possible, to update my skin at a precise point in time. My skin has an UpdateRate=600 (every 10 min) so I would like that the very first update (or refresh) happening at the closest 10min mark, (like 15:00 15:10 15:20 and so on), I mean if I load the skin (ore refresh it...) at 15:02, it will update at 15:10. Hope to have made myself clear :D
This can be done. Here's one way:

First, on your main time measure, set the UpdateInterval=-1 so it will update only once (the first time your skin loads).

Second, create a Calc measure that will act as a trigger. The formula is something like Formula=([your time measure:Timestamp] % 600). So this measure will return 0 every 10th minute (by the clock). Add an IfCondition or IfValue to test for zero, and then use an !UpdateMeasure bang to update your main time measure.

Depending on your skin you might not need a separate Calc measure, and instead you can handle the formula in an IfCondition of some other measure that can act as your trigger.

P.S.: For this to work, you should use the skin's default Update=1000 (once per second). You'd use UpdateRate=600 on a WebParser measure, not the skin. If you want a WebParser to fire on the 10's, set UpdateRate=-1 on the WebParser measure, then include the measure in your trigger measure and for the action add [!CommandMeasure <your web measure> Update] to force it to update.
Gadgets Wiki GitHub More Gadgets...
User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Manage UTC time

Post by balala »

brax64 wrote: September 2nd, 2020, 9:21 pm so I do expect that will be no issue for the week end check...
I hope as well, however since the weekend is approaching, let's see...
brax64 wrote: September 2nd, 2020, 9:21 pm
  • for what I can see in the Rainmeter log, the date value of Format=%#H.%u has only 1 decimal digit (ie 15.3) so I was wondering about the necessity of the "Round" function in ((Round(Frac([#CURRENTSECTION#]),2)=0.5). Can be written as (Frac([#CURRENTSECTION#])=5) ?
Yep, first I did it this way, didn't use the Round function. But couldn't get it to properly work (and couldn't identify the cause) so finally ended up by adding the Round function. It indeed complicates a little bit the formula used into the IfCondition option, but at least it does work.
brax64 wrote: September 2nd, 2020, 9:21 pm
  • I would like, if it's possible, to update my skin at a precise point in time. My skin has an UpdateRate=600 (every 10 min) so I would like that the very first update (or refresh) happening at the closest 10min mark, (like 15:00 15:10 15:20 and so on), I mean if I load the skin (ore refresh it...) at 15:02, it will update at 15:10. Hope to have made myself clear :D
Have you checked SilverAzide's solution? If it does work, it's alright, otherwise later I'll take a look (just let me know please if his solution is alright).
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Manage UTC time

Post by brax64 »

balala wrote: September 3rd, 2020, 6:32 am ...
Have you checked SilverAzide's solution? If it does work, it's alright, otherwise later I'll take a look (just let me know please if his solution is alright).
SilverAzide wrote: September 2nd, 2020, 9:41 pm ...
P.S.: For this to work, you should use the skin's default Update=1000 (once per second). You'd use UpdateRate=600 on a WebParser measure, not the skin. If you want a WebParser to fire on the 10's, set UpdateRate=-1 on the WebParser measure, then include the measure in your trigger measure and for the action add [!CommandMeasure <your web measure> Update] to force it to update.
Hi Balala,SilverAzide

Did try this but is not working, the whole skin doesn't update at all, what I'm doing wrong?

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,1
SkinWidth=509
SkinHeight=105
OnCloseAction=[!WriteKeyValue Variables OnOff 1 "#@#Variables.inc"][!WriteKeyValue Variables GoldPricePrevious [GoldPriceNumber] "#@#Variables.inc"][!WriteKeyValue Variables SilverPricePrevious [SilverPriceNumber] #@#Variables.inc][!WriteKeyValue Variables PlatinumPricePrevious [PlatinumPriceNumber] #@#Variables.inc][!WriteKeyValue Variables PalladiumPricePrevious [PalladiumPriceNumber] #@#Variables.inc]

[Variables]
@include=#@#Variables.inc

[TimeInternal]
Measure=Time

[Counter]
Measure=Calc
Formula=([TimeInternal:TimeStamp]%600)
IfCondition=([Counter]=0)
IfTrueAction=[!CommandMeasure "Site" "Update"]

[Site]
Measure=WebParser
URL=#URL#
UpdateRate=#UpdateRate#
Flags=Resync | NoCookies
UserAgent=#UserAgent#
LogSubstringErrors=0
RegExp=(?siU)^(.*)$
StringIndex=1
FinishAction=[!EnableMeasureGroup Child][Play "#@#Sounds\UpdateAlarm.wav"][!Delay 5000][!UpdateMeasureGroup Tick]
UpdateDivider=-1

User avatar
balala
Rainmeter Sage
Posts: 16147
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Manage UTC time

Post by balala »

brax64 wrote: September 3rd, 2020, 1:51 pm Did try this but is not working, the whole skin doesn't update at all, what I'm doing wrong?
Although I didn't try out yet the code, I see there a mistake which for sure prevents the skin to properly work. The [Counter] measure uses a section variable ([TimeInternal:TimeStamp]) and as such it requires a DynamicVariables=1 option. Add it and try out the skin again. Do you get it working this way? A little bit later I'll try it out as well.
And one more, which also can't work, but it isn1t even needed. The IfCondition option of the [Counter] measure also uses a section variable (IfCondition=([Counter]=0)). This also would require to set on the dynamic variables, but this one is practically not needed, this option could by simply IfCondition=(Counter=0) (or me personally prefer the IfCondition=(#CURRENTSECTION#=0) form of this option, however this has not too much importance).
Accordingly the [Counter] measure should look like:

Code: Select all

[Counter]
Measure=Calc
Formula=([TimeInternal:TimeStamp]%600)
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!CommandMeasure "Site" "Update"]
DynamicVariables=1
User avatar
brax64
Posts: 172
Joined: July 8th, 2018, 8:05 pm

Re: Manage UTC time

Post by brax64 »

balala wrote: September 3rd, 2020, 2:36 pm Although I didn't try out yet the code, I see there a mistake which for sure prevents the skin to properly work. The [Counter] measure uses a section variable ([TimeInternal:TimeStamp]) and as such it requires a DynamicVariables=1 option. Add it and try out the skin again. Do you get it working this way? A little bit later I'll try it out as well.
And one more, which also can't work, but it isn1t even needed. The IfCondition option of the [Counter] measure also uses a section variable (IfCondition=([Counter]=0)). This also would require to set on the dynamic variables, but this one is practically not needed, this option could by simply IfCondition=(Counter=0) (or me personally prefer the IfCondition=(#CURRENTSECTION#=0) form of this option, however this has not too much importance).
Accordingly the [Counter] measure should look like:

Code: Select all

[Counter]
Measure=Calc
Formula=([TimeInternal:TimeStamp]%600)
IfCondition=(#CURRENTSECTION#=0)
IfTrueAction=[!CommandMeasure "Site" "Update"]
DynamicVariables=1
Hi Balala,
made the correction you suggested and it looks like is fine, I see in the log the [Counter] measure cycling till 600 and then back to 0; unfortunately another major problem arises so I can't verify if it's working properly, I'm getting this error now:
(Fetch error) The operation timed out (ErrorCode=12002) (SpotPrices\SpotPrices.ini - [Site])
even if I remove the [Counter] measure...