It is currently April 25th, 2024, 10:17 am

Recurring Countdown Timer & Substitution Problem

Get help with creating, editing & fixing problems with skins
User avatar
cwfrizzell
Posts: 77
Joined: August 10th, 2009, 9:03 pm

Recurring Countdown Timer & Substitution Problem

Post by cwfrizzell »

I have a countdown timer set to calculate to a particular date based on jsmorley's simple countdown timer.

As an example, it calculates to New Year's Day. I would like it to automatically calculate to the next New Year's Day once the new year arrives without me having to update the year. I figured I would try to use Substitute to replace current year of event date with following year, but am stuck as I just don't understand RegExp. Or maybe there's another way I haven't discovered yet...

Code: Select all

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

[Variables]
EventDateTime="2017-01-01 00:00:00"

[mTime]
Measure=Time

[mYear]
Measure=Time
Format="%Y"

[mNextYear]
Measure=Calc
Formula=mYear+1

[mEventTimeRecur]
Measure=STRING
String=#EventDateTime#
RegExpSubstitute=1
Substitute="^(.{0,4}).+$":"\1[mNextYear]"
;I know the above line is wrong.  I just don't understand RegExp
DynamicVariables=1

[mEventTime]
Measure=Time
TimeStamp=[mEventTimeRecur]
;TimeStamp=#EventDateTime#
TimeStampFormat="%Y-%m-%d %H:%M:%S"
Format="%Y-%m-%d %H:%M:%S"
DynamicVariables=1

[mEventDiff]
Measure=Uptime
SecondsValue=(Max(0, [mEventTime:timestamp] - [mTime:timestamp]))
Format="%4!01i!:%3!02i!:%2!02i!:%1!02i!"
DynamicVariables=1

[MeterCountdown]
Meter=String
MeasureName=mEventTimeRecur
MeasureName2=mTime
MeasureName3=mEventDiff
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Target:      %1#CRLF#Current:      %2#CRLF#Countdown:   %3
Appreciate any help!
Cheers!

Chuck
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Recurring Countdown Timer & Substitution Problem

Post by ikarus1969 »

I haven't think about some other solution, but if you replace the Substitute in your code of [mEventTimeRecur] with the following:

Code: Select all

Substitute="^(\d{4,4})(.+)$":"[mNextYear]\2"
it works.

The regular expression:
the "^" means: "at the beginning of a string
then i have 2 so-called "groups", defined by "(" and ")" which i can refer to in the substitute by "\1", "\2" and so on
"\d" means "a digit"; "{4,4}" means: "exactly 4 digits ({from, to})
the second group ".+" means any character
"$" means: "the end of the string"

so i replace the 4 digits at the very beginning of a string by [mNextYear] and append the rest of the string (beginning with the 5.th character).
User avatar
cwfrizzell
Posts: 77
Joined: August 10th, 2009, 9:03 pm

Re: Recurring Countdown Timer & Substitution Problem

Post by cwfrizzell »

It does indeed work...

Thank you very much!
Cheers!

Chuck
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Recurring Countdown Timer & Substitution Problem

Post by ikarus1969 »

cwfrizzell wrote:It does indeed work...

Thank you very much!
You're welcome!
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Recurring Countdown Timer & Substitution Problem

Post by balala »

ikarus1969 wrote:"{4,4}" means: "exactly 4 digits ({from, to})
Not exactly ikarus1969, {4,4} means from 4 to 4 digits (you also have said this), but in this case, this is not needed, exactly 4 digits being coded as {4}. So, I think I'd replace the Substitute="^(\d{4[color=#FF0000],4[/color]})(.+)$":"[mNextYear]\2" option with the simpler Substitute="^(\d{4})(.+)$":"[mNextYear]\2" option. However, your option works the same well, being correct as well.
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Recurring Countdown Timer & Substitution Problem

Post by ikarus1969 »

It's just another form of notation of the same thing...
User avatar
balala
Rainmeter Sage
Posts: 16168
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Recurring Countdown Timer & Substitution Problem

Post by balala »

ikarus1969 wrote:It's just another form of notation of the same thing...
Right, I also said this...
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Recurring Countdown Timer & Substitution Problem

Post by jsmorley »

While the difference is negligible, I can the the purist argument for "Is it exactly 4? Yes." over "Is it at least 4? Yes. Is it at most 4? Yes."

;-)