It is currently March 28th, 2024, 11:51 am

Issue when changing clock time based on day time

Get help with creating, editing & fixing problems with skins
Post Reply
Keichi
Posts: 5
Joined: April 30th, 2020, 9:45 am

Issue when changing clock time based on day time

Post by Keichi »

Hello everyone !
I've some trouble to change the clock time based on the day time.
I've tested several solutions without any results... It's been 3 hours I'm on it and I'm not able to fix it!
As you can see, each condition is something that has been tested without any results...

Here is my code :

Code: Select all

[Rainmeter]
Update=1000


[Variables]

fontName=Digital-7
;fontName=DESG7ClassicMini
textSize=12

[Measure24Hr]
Measure=Calc
IfCondition=(MeasureTime >= 0600) && (Measure24Hr < 1300)
IfTrueAction=[!SetOption StyleTime TextColor "188,90,69,255,255"][!UpdateMeter StyleTime]
IfCondition2=(Measure24Hr >= 1300) && (Measure24Hr < 1900)
IfTrueAction2=[!SetOption StyleTimee TextColor "188,90,69,255,255"][!UpdateMeter StyleTime]
IfCondition3=(Measure24Hr >= 19) && (Measure24Hr < 23)
IfTrueAction3=[!SetVariable TextColor "188,90,69,255,255"][!UpdateMeter *]
IfCondition4=(Measure24Hr >= 23) || (Measure24Hr < 06)
IfTrueAction4=[!SetVariable TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]


[MeasureTime]
Measure=Time
Format=%H:%M

[MeasureDate]
Measure=Time
Format=%d.%m.%Y
FormatLocale=fr-FR

[MeasureDay]
Measure=Time
Format=%A
FormatLocale=fr-FR

[StyleTime]
StringAlign=Center
StringStyle=Regular
StringEffect=Shadow
FontColor=#TextColor#
FontFace=#fontName#
FontSize=38
AntiAlias=1
ClipString=1

[styleLeftText]
;StringAlign=Left
StringStyle=Bold
StringEffect=Shadow
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=Right
StringStyle=Bold
StringEffect=Shadow
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[meterTime]
Meter=String
MeterStyle=styleTime
FontColor=#TextColor#
MeasureName=measureTime
X=245
Y=355
W=200
H=40

[meterDay]
Meter=String
MeterStyle=styleLeftText
MeasureName=measureDay
X=260
Y=400
W=190
H=14

[meterDate]
Meter=String
MeterStyle=styleRightText
MeasureName=measureDate
X=200
Y=0r
W=190
H=14

;Tosave
;FontEffectColor=0,0,0,20
;[styleSeperator]

;SolidColor=255,255,255,15

Thank's in advance for the help :)
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: Issue when changing clock time based on day time

Post by SilverAzide »

Keichi wrote: May 9th, 2021, 2:33 pm Hello everyone !
I've some trouble to change the clock time based on the day time.
I've tested several solutions without any results... It's been 3 hours I'm on it and I'm not able to fix it!
As you can see, each condition is something that has been tested without any results...

Thank's in advance for the help :)
I see several problems here.

The first problem is that you need to be aware that a time measure returns a formatted string ("HH:MM" in your case of using the %H:%M format), or it can also return a Windows timestamp (number). IfCondition expressions can only handle numeric values, so your attempts to compare with strings will not work. Read about IfConditions here, and especially read the note in the second paragraph.

The second issue is that your Measure24Hr Calc measure has no Formula option, so it is just going to return zero all the time. So your condition expressions will never work properly.
  • A side issue to keep in mind, Rainmeter processes the file in order (top down). Your Measure24Hr measure makes reference to MeasureTime, which occurs later in the file. When the skin first loads, because it is out of order, the MeasureTime measure will not have a value when Measure24Hr runs the first time. I'd suggest re-ordering the measures at some point to make sure no measure references another measure that is later in the file.
There are a number of ways you can achieve what you want. I would suggest you can either create a Time measure that returns the hour only (remember, this is the string representation of the hour) or just ignore the formatted string and use the timestamp along with some math to calculate the hour.

Code: Select all

; return the hour with no leading zeros, "0" to "23"
[MeasureHour]
Measure=Time
Format=%#H

; convert the hour string into a number, 0 to 23
[Measure24Hr]
Measure=Calc
Formula=([MeasureHour])
IfCondition=(Measure24Hr >= 6) && (Measure24Hr < 13)
...
Now you can use the [Measure24Hr] result in your IfConditions since it will be a number. (You can do this in a single time measure, but I am suggesting this way first so you can see what is going on more easily.)

Another way to do this is use timestamps and math. The trick is to know that [MeasureTime:Timestamp] returns a numeric Windows timestamp. Using math, you can calculate the current hour.

Code: Select all

[MeasureTime]
Measure=Time
Format=%H:%M

; calculate the current hour from the current timestamp
[Measure24Hr]
Measure=Calc
Formula=Floor(([MeasureTime:Timestamp] % 86400) / 3600)
IfCondition=(Measure24Hr >= 6) && (Measure24Hr < 13)
...
Again, your IfConditions will now work since the [Measure24Hr] is returning a number.
Keichi
Posts: 5
Joined: April 30th, 2020, 9:45 am

Re: Issue when changing clock time based on day time

Post by Keichi »

Wow thank's for the very clear answer !

So I went into the first solution that you gave me !

I've created a MeasureHour with Measure=Time and Time=%#H as you say ! I put it under my MeasureTime. I've modified my Measure24Hr with the Formula=([MeasureHour]).

Then for the problem of referencing something that is not existing yet, I move my Measure24Hr measure between MeasureDay and StyleTime so this way I can get the new MeasureHour.

Now the Measure24Hr properly get a numeric number !! Thank's !

For the conditions, I'm not sure if it's a good way but I've set something like this (because the !SetVariable is not working) :

Code: Select all

IfTrueAction=[!WriteKeyValue Variables TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]
Maybe it's not the good way, but it works like a charm :p

Big thumbs Up !
User avatar
CodeCode
Posts: 1363
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Issue when changing clock time based on day time

Post by CodeCode »

Keichi wrote: May 9th, 2021, 4:41 pm
For the conditions, I'm not sure if it's a good way but I've set something like this (because the !SetVariable is not working) :

Code: Select all

IfTrueAction=[!WriteKeyValue Variables TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]
Maybe it's not the good way, but it works like a charm :p

Big thumbs Up !
The Text Color Option only uses 4 channels:Red,Green,Blue,Alpha or, R,G,B,A. So the Alpha in your parameter is fully opaque, where 0 (zero) is completely invisible. Tip: making a SolidColor=0,0,0,1 field in a image or text Meter will make the click area easily accessible and verily transparent - an overlay of sorts to make clicking easier. :rosegift: The meter will need W and H Options to determine the size of the clicky, where the X and Y determine the upper left corner of the clicky. :D
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm
Contact:

Re: Issue when changing clock time based on day time

Post by SilverAzide »

Keichi wrote: May 9th, 2021, 4:41 pm For the conditions, I'm not sure if it's a good way but I've set something like this (because the !SetVariable is not working) :

Code: Select all

IfTrueAction=[!WriteKeyValue Variables TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]
Maybe it's not the good way, but it works like a charm :p
Yes, as CodeCode mentioned, your !SetVariable bangs are not working because your colors are not in the correct "R,G,B,A" format. Using !WriteVariable isn't the way to go, not only because the colors are wrong, but because variables are only read when the skin is loaded/refreshed, so your colors will not change until you refresh the entire skin. It is better to use !SetVariable, as the change will be immediate. Also, you need to add DynamicVariables=1 to your meters that change color so the variables will be re-evaluated, and DON'T use !SetOption to change options on a style meter, change the actual meter itself (the meter using the style).
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Issue when changing clock time based on day time

Post by balala »

SilverAzide wrote: May 9th, 2021, 3:53 pm The first problem is that you need to be aware that a time measure returns a formatted string ("HH:MM" in your case of using the %H:%M format), or it can also return a Windows timestamp (number).
Not to nitpick, but in fact not "or". I mean that a time measure always returns both, a string value (as you described) AND the time stamp (not or). The time stamp can be accessed through the (for instance) [MeasureTime:TimeStamp] section variable (requires the DynamicVariables=1 option).
Sorry, as said, don't want to nitpick you.
Keichi wrote: May 9th, 2021, 2:33 pm As you can see, each condition is something that has been tested without any results...
SilverAzide is right when he says:
SilverAzide wrote: May 9th, 2021, 3:53 pm IfCondition expressions can only handle numeric values, so your attempts to compare with strings will not work.
however there is a somehow simpler approach.
You can slightly modify the Format option of the [MeasureTime] measure to Format=%H.%M. This way the measure returns a decimal number and you can use the IfConditions, for instance this way:

Code: Select all

[MeasureTime]
Measure=Time
Format=%H.%M
IfCondition=((MeasureTime >= 06)&&(MeasureTime < 13))
IfTrueAction=[!SetOption StyleTime TextColor "188,90,69,255,255"][!UpdateMeter StyleTime][!Redraw]
IfCondition2=((MeasureTime >= 13)&&(MeasureTime < 19))
IfTrueAction2=[!SetOption StyleTimee TextColor "188,90,69,255,255"][!UpdateMeter StyleTime][!Redraw]
IfCondition3=((MeasureTime >= 19)&&(MeasureTime < 23))
IfTrueAction3=[!SetVariable TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]
IfCondition4=((MeasureTime >= 23)||(MeasureTime < 6))
IfTrueAction4=[!SetVariable TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]
Here I also aded a few pairs of parentheses. Even if they are not absolutely needed, I'm always using them, because at least for me they are making the conditions better and more clearly visible.
With the above solution, you can get rid of the [Measure24Hr] measure (at least supposing the posted code is the entire code used by your skin), because it is not used anywhere else in your code.
The disadvantage of the above approach is that the [MeterTime] will show the time as (for example) 8.00, not 8:00. If this is not a too big disadvantage, you can use this approach.
SilverAzide wrote: May 9th, 2021, 3:53 pm
  • A side issue to keep in mind, Rainmeter processes the file in order (top down). Your Measure24Hr measure makes reference to MeasureTime, which occurs later in the file. When the skin first loads, because it is out of order, the MeasureTime measure will not have a value when Measure24Hr runs the first time. I'd suggest re-ordering the measures at some point to make sure no measure references another measure that is later in the file.
This is not a problem. No disadvantages, no error messages, nothing if the measures are placed into the posted order. This might be a problem in procedural programming languages, but not in Rainmeter, which is not a programming language.
SilverAzide wrote: May 9th, 2021, 3:53 pm There are a number of ways you can achieve what you want. I would suggest you can either create a Time measure that returns the hour only (remember, this is the string representation of the hour) or just ignore the formatted string and use the timestamp along with some math to calculate the hour.

Code: Select all

; return the hour with no leading zeros, "0" to "23"
[MeasureHour]
Measure=Time
Format=%#H

; convert the hour string into a number, 0 to 23
[Measure24Hr]
Measure=Calc
Formula=([MeasureHour])
IfCondition=(Measure24Hr >= 6) && (Measure24Hr < 13)
...
Now you can use the [Measure24Hr] result in your IfConditions since it will be a number. (You can do this in a single time measure, but I am suggesting this way first so you can see what is going on more easily.)
No need to add a new measure just for the conditions. As you can see in my above example, you can add the conditions directly to the [MeasureHour] measure.
Usually the less measures (sections), the better, so it's always a good idea not to add measures if they are not needed.
Keichi wrote: May 9th, 2021, 2:33 pm

Code: Select all

[Rainmeter]
Update=1000


[Variables]

fontName=Digital-7
;fontName=DESG7ClassicMini
textSize=12

[Measure24Hr]
Measure=Calc
IfCondition=(MeasureTime >= 0600) && (Measure24Hr < 1300)
IfTrueAction=[!SetOption StyleTime TextColor "188,90,69,255,255"][!UpdateMeter StyleTime]
IfCondition2=(Measure24Hr >= 1300) && (Measure24Hr < 1900)
IfTrueAction2=[!SetOption StyleTimee TextColor "188,90,69,255,255"][!UpdateMeter StyleTime]
IfCondition3=(Measure24Hr >= 19) && (Measure24Hr < 23)
IfTrueAction3=[!SetVariable TextColor "188,90,69,255,255"][!UpdateMeter *]
IfCondition4=(Measure24Hr >= 23) || (Measure24Hr < 06)
IfTrueAction4=[!SetVariable TextColor "188,90,69,255,255"][!UpdateMeter *][!Redraw]


[MeasureTime]
Measure=Time
Format=%H:%M

[MeasureDate]
Measure=Time
Format=%d.%m.%Y
FormatLocale=fr-FR

[MeasureDay]
Measure=Time
Format=%A
FormatLocale=fr-FR

[StyleTime]
StringAlign=Center
StringStyle=Regular
StringEffect=Shadow
FontColor=#TextColor#
FontFace=#fontName#
FontSize=38
AntiAlias=1
ClipString=1

[styleLeftText]
;StringAlign=Left
StringStyle=Bold
StringEffect=Shadow
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=Right
StringStyle=Bold
StringEffect=Shadow
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[meterTime]
Meter=String
MeterStyle=styleTime
FontColor=#TextColor#
MeasureName=measureTime
X=245
Y=355
W=200
H=40

[meterDay]
Meter=String
MeterStyle=styleLeftText
MeasureName=measureDay
X=260
Y=400
W=190
H=14

[meterDate]
Meter=String
MeterStyle=styleRightText
MeasureName=measureDate
X=200
Y=0r
W=190
H=14

;Tosave
;FontEffectColor=0,0,0,20
;[styleSeperator]

;SolidColor=255,255,255,15

Sorry, a StringStyle=Regular option (used on the [StyleTime] section) is not valid. It probably should be StringStyle=Normal.
Keichi
Posts: 5
Joined: April 30th, 2020, 9:45 am

Re: Issue when changing clock time based on day time

Post by Keichi »

Thank's everyone for your replies !

You helped me a lot...

And yeah about the X.X.X.X.X (R,G,B,A) for the condition, it was a remnants from my pasts tests... Wrong copy/paste !

I'm able to change it with this code (for futur guys who want to know, with only interesting parts) :

Code: Select all

[Variables]
TextColor=245,99,40,255


[MeasureHour]
Measure=Time
Format=%#H

[Measure24Hr]
Measure=Calc
Formula=([MeasureHour])
IfCondition=(Measure24Hr >= 6) && (Measure24Hr < 13)
IfTrueAction=[!SetVariable TextColor "188,90,69,255"][!UpdateMeter meterTime][!Redraw]
IfCondition2=(Measure24Hr >= 13) && (Measure24Hr < 19)
IfTrueAction2=[!SetVariable TextColor "245,99,40,255"][!UpdateMeter meterTime][!Redraw]
IfCondition3=(Measure24Hr >= 19) && (Measure24Hr < 23)
IfTrueAction3=[!SetVariable TextColor "211,113,47,255"][!UpdateMeter meterTime][!Redraw]
IfCondition4=(Measure24Hr >= 23) || (Measure24Hr < 6)
IfTrueAction4=[!SetVariable TextColor "10,214,255,255"][!UpdateMeter meterTime][!Redraw]
DynamicVariables=1

;188,90,69,255
;245,99,40,255
;211,113,47,255
;10,214,255,255

[StyleTime]
StringAlign=Center
StringStyle=Regular
StringEffect=Shadow
FontColor=#TextColor#
FontFace=#fontName#
FontSize=42
AntiAlias=1
;ClipString=1
DynamicVariables=1

[meterTime]
Meter=String
MeterStyle=styleTime
;FontColor=#TextColor#
MeasureName=MeasureTime
X=250
Y=345
W=200
H=50
Text=%1
Angle=(Rad(-1))
DynamicVariables=1
Not the best but do the job !

Anyway sometime the color does not refresh so I've to discharge/reload the skin but it work after !

Thank you for everyone tips !
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Issue when changing clock time based on day time

Post by balala »

Keichi wrote: May 10th, 2021, 9:20 pm I'm able to change it with this code (for futur guys who want to know, with only interesting parts) :
The [Measure24Hr] measure is still not needed. You can add the conditions directly to the [MeasureHour] measure, which besides reducing the number of measures (if you do this, you can completely get rid of the [Measure24Hr] measure), avoids the need to set on the dynamic variables:

Code: Select all

[MeasureHour]
Measure=Time
Format=%#H
IfCondition=(MeasureHour >= 6) && (MeasureHour < 13)
IfTrueAction=[!SetVariable TextColor "188,90,69,255"][!UpdateMeter meterTime][!Redraw]
IfCondition2=(MeasureHour >= 13) && (MeasureHour < 19)
IfTrueAction2=[!SetVariable TextColor "245,99,40,255"][!UpdateMeter meterTime][!Redraw]
IfCondition3=(MeasureHour >= 19) && (MeasureHour < 23)
IfTrueAction3=[!SetVariable TextColor "211,113,47,255"][!UpdateMeter meterTime][!Redraw]
IfCondition4=(MeasureHour >= 23) || (MeasureHour < 6)
IfTrueAction4=[!SetVariable TextColor "10,214,255,255"][!UpdateMeter meterTime][!Redraw]

;[Measure24Hr]
;Measure=Calc
;Formula=([MeasureHour])
;IfCondition=(Measure24Hr >= 6) && (Measure24Hr < 13)
;IfTrueAction=[!SetVariable TextColor "188,90,69,255"][!UpdateMeter meterTime][!Redraw]
;IfCondition2=(Measure24Hr >= 13) && (Measure24Hr < 19)
;IfTrueAction2=[!SetVariable TextColor "245,99,40,255"][!UpdateMeter meterTime][!Redraw]
;IfCondition3=(Measure24Hr >= 19) && (Measure24Hr < 23)
;IfTrueAction3=[!SetVariable TextColor "211,113,47,255"][!UpdateMeter meterTime][!Redraw]
;IfCondition4=(Measure24Hr >= 23) || (Measure24Hr < 6)
;IfTrueAction4=[!SetVariable TextColor "10,214,255,255"][!UpdateMeter meterTime][!Redraw]
;DynamicVariables=1
See that [Measure24Hr] is commented out.
Post Reply