It is currently March 28th, 2024, 10:19 pm

Leading Zero

Get help with creating, editing & fixing problems with skins
Craft
Posts: 25
Joined: August 3rd, 2017, 6:00 pm

Leading Zero

Post by Craft »

Hi!

Today i have question about leading zero in formula.
How to do that?

I do simple work time timer, and want to format output: 00:00:00
Capture.PNG

Code: Select all


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

[Variables]
FontSize=12
HoursStart=11
HoursEnd=19
MinutesStart=30
MinutesEnd=30
TextSwitch=""
LabelColor=0,0,0,0

[GetCurrentHour]
Measure=Time
Format=%H

[GetCurrentMinute]
Measure=Time
Format=%M

[GetCurrentSecond]
Measure=Time
Format=%S

[TimeToDigits]
Measure=Calc
DynamicVariables=1
Formula=(GetCurrentHour+(((GetCurrentMinute*60)+GetCurrentSecond)/3600))

[TimeToDigitsStart]
Measure=Calc
DynamicVariables=1
Formula=(#HoursStart#+(((#MinutesStart#*60)+0)/3600))

[TimeToDigitsEnd]
Measure=Calc
DynamicVariables=1
Formula=(#HoursEnd#+(((#MinutesEnd#*60)+0)/3600))

[TimeRemaining]
Measure=Calc
DynamicVariables=1
Formula=(TimeToDigits-TimeToDigitsEnd)*-1
IfConditionMode=1
IfCondition=TimeToDigits > TimeToDigitsStart && TimeToDigits < TimeToDigitsEnd
IfCondition2=TimeToDigits > TimeToDigitsStart && TimeToDigits < TimeToDigitsEnd
IfTrueAction=!RainmeterSetVariable TextSwitch "Work Time"
IfTrueAction2=!RainmeterSetVariable LabelColor 230,40,100,255
IfFalseAction=!RainmeterSetVariable TextSwitch "Rest Time"
IfFalseAction2=!RainmeterSetVariable LabelColor 50,225,150,255

[NumbersToTimeHours]
Measure=Calc
DynamicVariables=1
Formula=Floor(TimeRemaining)

[NumbersToTimeMinutes]
Measure=Calc
DynamicVariables=1
Formula=Floor((Frac(TimeRemaining)*3600)/60)

[NumbersToTimeSeconds]
Measure=Calc
DynamicVariables=1
Formula=(((Floor((Frac(TimeRemaining)*3600)/60))*60)-(Frac(TimeRemaining)*3600))*-1

[TitleBackground]
Meter=Shape
X=5
Y=5
DynamicVariables=1
Shape=Rectangle 0,0,100,25,1 | Fill Color #LabelColor# | StrokeWidth 1 | Stroke Color 255,255,255,100

[AllBackground]
Meter=Shape
X=5
Y=32
DynamicVariables=1
Shape=Rectangle 0,0,100,25,1 | Fill Color 35,35,35,255 | StrokeWidth 1 | Stroke Color 255,255,255,100

[TextTitle]
Meter=String
MeasureName=NumbersToTimeHours
MeasureName2=NumbersToTimeMinutes
MeasureName3=NumbersToTimeSeconds
X=22
Y=7
FontFace=Calibri
FontEffectColor=0,0,0,255
FontColor=255,255,255,255
FontSize=#FontSize#
DynamicVariables=1
AntiAlias=1
LeftMouseUpAction=!RainmeterRefresh
Text=#TextSwitch#

[TextRemainingTime]
Meter=String
MeasureName=NumbersToTimeHours
MeasureName2=NumbersToTimeMinutes
MeasureName3=NumbersToTimeSeconds
X=10r
Y=8R
FontFace=Calibri
FontEffectColor=0,0,0,255
FontColor=255,255,255,255
FontSize=#FontSize#
DynamicVariables=1
AntiAlias=1
LeftMouseUpAction=!RainmeterRefresh
Text=%1:%2:%3

You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

Craft wrote:and want to format output: 00:00:00
Add the following options to the [NumbersToTimeHours], [NumbersToTimeMinutes] and [NumbersToTimeSeconds] measures:

Code: Select all

RegExpSubstitute=1
Substitute="^(\d{1})$":"0\1"
Craft
Posts: 25
Joined: August 3rd, 2017, 6:00 pm

Re: Leading Zero

Post by Craft »

balala wrote:Add the following options to the [NumbersToTimeHours], [NumbersToTimeMinutes] and [NumbersToTimeSeconds] measures:

Code: Select all

RegExpSubstitute=1
Substitute="^(\d{1})$":"0\1"

Big thanks, i try this!

Unfortunately, i google solution, but can't find...
Craft
Posts: 25
Joined: August 3rd, 2017, 6:00 pm

Re: Leading Zero

Post by Craft »

Craft wrote:Big thanks, i try this!

Unfortunately, i google solution, but can't find...
Yes! it works like a charm!!!

Thanks again!
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

Glad to help.
But I have to make two remarks:
  • The !Rainmeter... bang prefix is deprecated, you should not use it.
  • Also, seem a good practice to get used to add brackets around the bangs, even if you're using just one bang. Although this is not absolutely necessary, could avoid a lot of headaches in the future.
Craft
Posts: 25
Joined: August 3rd, 2017, 6:00 pm

Re: Leading Zero

Post by Craft »

balala wrote:Glad to help.
But I have to make two remarks:
  • The !Rainmeter... bang prefix is deprecated, you should not use it.
  • Also, seem a good practice to get used to add brackets around the bangs, even if you're using just one bang. Although this is not absolutely necessary, could avoid a lot of headaches in the future.
Thanks. I still learn syntax!

!Rainmeter - I remember that.

Without brackets conditions not working correctly. i already fix that.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Leading Zero

Post by balala »

Craft wrote:Without brackets conditions not working correctly. i already fix that.
I'm surprised, because it should. Eg the following two IfTrueActions should work the same way:
IfTrueAction=!RainmeterSetVariable TextSwitch "Work Time"
IfTrueAction=[!SetVariable TextSwitch "Work Time"]
(copied from the [TimeRemaining] measure)
Here I also removed the !Rainmeter... prefix of the !RainmeterSetVariable bang.
Using those brackets in such cases is optional. But if you have two or more bangs in the same option, the brackets become obligatory, you can't left them out.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Leading Zero

Post by jsmorley »

I think we are confusing two things here.

IfCondition=(TimeToDigits > TimeToDigitsStart) && (TimeToDigits < TimeToDigitsEnd)
This requires (parentheses) around the left and right comparisons when using AND with && in a formula.

IfTrueAction=[!SetVariable TextSwitch "Work Time"]
This specific example does not "require" [Brackets] around the bang in an action, but it is a good practice to always just do so. If you ever want more than one bang, they are required, and if you want to execute a command, not a bang, like ["http://cnn.com"] or ["C:\Program Files\MyApp.exe"] they are required. It's easier to just always use them on bangs.

(Parentheses)
[Brackets or Square Brackets]
{Braces or Curly Braces}

http://grammar.quickanddirtytips.com/education/grammar/parentheses-brackets-and-braces
Craft
Posts: 25
Joined: August 3rd, 2017, 6:00 pm

Re: Leading Zero

Post by Craft »

jsmorley wrote:I think we are confusing two things here.

IfCondition=(TimeToDigits > TimeToDigitsStart) && (TimeToDigits < TimeToDigitsEnd)
This requires (parentheses) around the left and right comparisons when using AND with && in a formula.

IfTrueAction=[!SetVariable TextSwitch "Work Time"]
This specific example does not "require" [Brackets] around the bang in an action, but it is a good practice to always just do so. If you ever want more than one bang, they are required, and if you want to execute a command, not a bang, like ["http://cnn.com"] or ["C:\Program Files\MyApp.exe"] they are required. It's easier to just always use them on bangs.

(Parentheses)
[Brackets or Square Brackets]
{Braces or Curly Braces}

http://grammar.quickanddirtytips.com/education/grammar/parentheses-brackets-and-braces
I mean that:

IfCondition=(TimeToDigits > TimeToDigitsStart) && (TimeToDigits < TimeToDigitsEnd)
This requires (parentheses) around the left and right comparisons when using AND with && in a formula.

Other code work fine.
No errors or something like that.

Thanks Guys!
User avatar
xenium
Posts: 841
Joined: January 4th, 2018, 9:52 pm

Re: Leading Zero

Post by xenium »

Hi,

I have a webparser measure that displays time in a format like this :
23: 00
00: 00
01: 00

How do I use substitute to remove leading zero,to display time in format:
23:00
0: 00
1: 00

Thanks