It is currently April 20th, 2024, 6:17 am

Countdown for Repeating Events

Get help with creating, editing & fixing problems with skins
User avatar
ZipD
Posts: 37
Joined: September 10th, 2017, 4:31 pm

Countdown for Repeating Events

Post by ZipD »

I've been cracking my head on trying to create a countdown timer with a repeating event but couldn't find any posts here that has anything similar. Here's my current code:

Code: Select all

[Variables]
Today=[MeasureNow]
EndDate=9/9/2018 23:43:50
7DaysLater=[MeasureAdd7DaysToTime]
[code][MeasureNow]
Measure=Time
Format=%A, %d %b %Y %H:%M:%S

[MeasureEndDate]
Measure=Time
TimeStamp=#EndDate#
TimeStampFormat=%m/%d/%Y %H:%M:%S
Format=%A, %d %b %Y %H:%M:%S

[MeasureAdd7DaysToTime]
Measure=Time
TimeStamp=([MeasureNow:TimeStamp] + 604800)
Format=%d %b %Y %H:%M:%S
DynamicVariables=1
Disabled=1

[MeasureDiff]
;Gets the difference between the end date and current date in seconds
Measure=Calc
Formula=[MeasureEndDate:Timestamp]-[MeasureNow:Timestamp]
IfCondition=MeasureDiff < 1
IfTrueAction=[!SetVariable EndDate #7DaysLater#]
DynamicVariables=1

[MeasureCountDown]
Measure=Loop
StartValue=0
EndValue=[MeasureDiff]
InvertMeasure=1
DynamicVariables=1

[MeasureFormatSeconds]
;Translates seconds into days/hours/minutes/seconds
Measure=UpTime
SecondsValue=[MeasureCountDown]
Format="%4!i! days %3!i! hours %2!i! minutes %1!i! seconds"
RegExpSubstitute=1
Substitute="^1 days":"1 day"," 1 hours":" 1 hour"," 1 minutes":" 1 minute"," 1 seconds":" 1 second"
DynamicVariables=1

[MeterDiff]
Meter=String
MeasureName=MeasureNow
MeasureName2=MeasureEndDate
MeasureName3=MeasureDiff
MeasureName4=MeasureFormatSeconds
MeasureName5=MeasureAdd7DaysToTime
X=0
Y=0
FontFace=#FontName#
FontSize=#FontSizeNormal#
FontColor=#FontColor#
Text=Now: %1#CRLF#End: %2#CRLF#Diff: %3#CRLF#Result: %4#CRLF#NewDate: %5
https://imgur.com/A5tdM4W

As you can see, I've managed to get it to add 7 days to the current date if EndDate has passed. But somehow I cannot update the EndDate with the new date. Any help is appreciated.
User avatar
ZipD
Posts: 37
Joined: September 10th, 2017, 4:31 pm

Re: Countdown for Repeating Events

Post by ZipD »

I've managed it i think, changing !SetVariable to !WriteKeyValue and refreshing the skin itself. Here's how the code looks like now:

Code: Select all

[Variables]
EndDate=10/09/2018 08:00:00
14DaysLater=[MeasureAdd14DaysToTime]

@Include=#@#\Variables.inc

---------------------------------------------------------------------------------------------------
MEASURES
---------------------------------------------------------------------------------------------------
[Today]
Measure=Time
Format=%d %b %Y %H:%M:%S

[StaticDate]
Measure=Time
TimeStamp=#EndDate#
TimeStampFormat=%d/%m/%Y %H:%M:%S
Format=%d %b %Y %H:%M:%S %p
DynamicVariables=1

[MeasureAdd14DaysToTime]
Measure=Time
TimeStamp=([StaticDate:TimeStamp] + 1209600)
Format=%d/%m/%Y %H:%M:%S
DynamicVariables=1
;Disabled=1

[MeasureDifference]
Measure=Calc
Formula=[Today:TimeStamp] - [StaticDate:TimeStamp]
;InvertMeasure allows the value to be negative if the formula produces a negative value
InvertMeasure=1
DynamicVariables=1

[MeasureEvaluateDateHasPassed]
Measure=Calc
IfCondition=MeasureDifference<1
;!WriteKeyValue Variables MyFontName Arial "#@#Variables.inc"
IfTrueAction=[!WriteKeyValue Variables EndDate #14DaysLater#][!RainmeterRefresh #CURRENTCONFIG#]

[MeasureFormatSeconds]
;Translates seconds into days/hours/minutes/seconds
Measure=UpTime
SecondsValue=[MeasureDifference]
Format="%4!i! days %3!i! hours %2!i! minutes %1!i! seconds"
RegExpSubstitute=1
Substitute="^1 days":"1 day"," 1 hours":" 1 hour"," 1 minutes":" 1 minute"," 1 seconds":" 1 second"
DynamicVariables=1

---------------------------------------------------------------------------------------------------
METERS
---------------------------------------------------------------------------------------------------
[MeterStartDay]
Meter=String
MeasureName=Today
X=0
Y=0
FontName=#FontName#
FontColor=#FontColor#
FontSize=#FontSizeNormal#
AntiAlias=1
Text=Today: %1

[MeterEndDay]
Meter=String
MeasureName=StaticDate
X=0
Y=R
FontName=#FontName#
FontColor=#FontColor#
FontSize=#FontSizeNormal#
AntiAlias=1
Text=End: %1

[MeterDifference]
MeasureName=MeasureDifference
X=0
Y=R
Meter=STRING
FontName=#FontName#
FontColor=#FontColor#
FontSize=#FontSizeNormal#
AntiAlias=1
Text=Seconds: %1

[MeterCountdown]
MeasureName=MeasureFormatSeconds
X=0
Y=R
Meter=STRING
FontName=#FontName#
FontColor=#FontColor#
FontSize=#FontSizeNormal#
AntiAlias=1
Text=Countdown: %1

[MeterNewDate]
MeasureName=MeasureAdd14DaysToTime
X=0
Y=R
Meter=STRING
FontName=#FontName#
FontColor=#FontColor#
FontSize=#FontSizeNormal#
AntiAlias=1
Text=New Date: %1
How it works:
Notice that in the code, the variable EndDate has a fixed date of 10 Sep 2018 at 8am.
  • 1. The measure MeasureDifference returns the difference in seconds between the system time and static date
    2. The measure MeasureEvaluateDateHasPassed will check if the current system time has passed the static date and changes the EndDate variable permanently to the new date (EndDate + 14 days worth of seconds) and !RainMeterRefresh does a refresh of the skin so that it can read the new variable's value. The countdown will reset and start again.
    3. If the current system date has not passed, the countdown will continue
This will be useful to set multiple events that repeat every n days/hours/minute without needing to reset the variable everytime the countdown becomes zero.

I hope the code is correct, if not please feel free to let me know.