It is currently March 29th, 2024, 8:43 am

Countdown timer and timestamp

Get help with creating, editing & fixing problems with skins
User avatar
Endemoniada
Posts: 6
Joined: February 28th, 2010, 10:52 pm

Countdown timer and timestamp

Post by Endemoniada »

Hi there. I'm trying to display a perpetual countdown timer to my fixed pay day each month. My pay day is stored in a variable (#payDate#). To determine my next pay day, firstly I calculate whether it's this month or next month (see [measureNextPayMonth]) by simply comparing the day of today's date with pay day. If today's date is >= pay day, my next pay day is next month otherwise it's this month. This measure is currently evaluating to 08 which is correct because my next pay day is indeed in August (the substitution btw is just to pad single digits with a zero).

Unfortunately when I try to feed [measureNextPayMonth] into the timestamp expression in [measureNextPayDay], it evaluates a date way, way in the past (13222915200). If I put in the actual correct number (08) instead of [measureNextPayMonth], however, [measureNextPayDay] and hence [measureCountdown] both evaluate exactly as I want. Any advice either about where I'm going wrong or even an easier way to do it would be most welcome. I should add I'm not new to Rainmeter but I haven't used it for about 10 years so I'm more than a bit rusty. Also I know [measureYear] needs some work to make it work going forward but I want to sort this problem first if possible.

Code: Select all

[measureNow]
Measure=Time

[measureYear]
Measure=Time
Format=%Y

[measureTodaysDate]
Measure=Time
Format=%d

[measureCurrentMonth]
Measure=Time
Format=%m

[measureNextPayMonth]
Measure=Calc
Formula=measureCurrentMonth+(measureTodaysDate>=#payDate#)
RegExpSubstitute=1
Substitute="^(\d)$":"0\0"

[measureNextPayDay]
Measure=Time
TimeStamp=#payDate#-[measureNextPayMonth]-[measureYear]
TimeStampFormat=%d-%m-%Y

[measureCountdown]
Measure=Calc
Formula=measureNextPayDay-measureNow
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Countdown timer and timestamp

Post by balala »

Endemoniada wrote: July 26th, 2020, 7:02 pm Hi there. I'm trying to display a perpetual countdown timer to my fixed pay day each month. My pay day is stored in a variable (#payDate#). To determine my next pay day, firstly I calculate whether it's this month or next month (see [measureNextPayMonth]) by simply comparing the day of today's date with pay day. If today's date is >= pay day, my next pay day is next month otherwise it's this month. This measure is currently evaluating to 08 which is correct because my next pay day is indeed in August (the substitution btw is just to pad single digits with a zero).

Unfortunately when I try to feed [measureNextPayMonth] into the timestamp expression in [measureNextPayDay], it evaluates a date way, way in the past (13222915200). If I put in the actual correct number (08) instead of [measureNextPayMonth], however, [measureNextPayDay] and hence [measureCountdown] both evaluate exactly as I want. Any advice either about where I'm going wrong or even an easier way to do it would be most welcome. I should add I'm not new to Rainmeter but I haven't used it for about 10 years so I'm more than a bit rusty. Also I know [measureYear] needs some work to make it work going forward but I want to sort this problem first if possible.
There are more problems with your code. The most important is that you have to add a DynamicVariables=1 option to the [measureNextPayDay] measure, because it uses section variables ([measureNextPayMonth] and [measureYear]) and these are requiring to set on the dynamic variables.
On the other hand I also would replace the Formula option of the [measureCountdown] measure with the following one: Formula=( [measureNextPayDay:TimeStamp] - [measureNow:TimeStamp] ). See that in this formula I extracted the time stamp of the [measureNow] measure, from the time stamp of the [measureNextPayDay] measure. Both being time measures, extracting them from each other can cause a lot of problems. Additionally [measureNextPayDay:TimeStamp] and [measureNow:TimeStamp] are again section variables, so you have to add the DynamicVariables=1 option to this measure as well.
However you'll get an error on December, when after 08, [measureNextPayMonth] will return 13 and as we all know, such a month doesn't exist.
User avatar
Endemoniada
Posts: 6
Joined: February 28th, 2010, 10:52 pm

Re: Countdown timer and timestamp

Post by Endemoniada »

balala wrote: July 26th, 2020, 7:49 pm There are more problems with your code. The most important is that you have to add a DynamicVariables=1 option to the [measureNextPayDay] measure, because it uses section variables ([measureNextPayMonth] and [measureYear]) and these are requiring to set on the dynamic variables.
On the other hand I also would replace the Formula option of the [measureCountdown] measure with the following one: Formula=( [measureNextPayDay:TimeStamp] - [measureNow:TimeStamp] ). See that in this formula I extracted the time stamp of the [measureNow] measure, from the time stamp of the [measureNextPayDay] measure. Both being time measures, extracting them from each other can cause a lot of problems. Additionally [measureNextPayDay:TimeStamp] and [measureNow:TimeStamp] are again section variables, so you have to add the DynamicVariables=1 option to this measure as well.
However you'll get an error on December, when after 08, [measureNextPayMonth] will return 13 and as we all know, such a month doesn't exist.
That's very helpful indeed, thanks. My initial thoughts on how to cope with December and the year change: add a mod 12 function to the formula for [measureNextPayMonth] so that it evaluates to 1 not 13 after pay day in December; create a new calculated measure [measureNextPayYear] to use in [measureNextPayDay] which returns the current year + 1 if the month is December.

Code: Select all

[measureNow]
Measure=Time

[measureTodaysDate]
Measure=Time
Format=%d

[measureCurrentMonth]
Measure=Time
Format=%m

[measureCurrentYear]
Measure=Time
Format=%Y

[measureNextPayMonth]
Measure=Calc
Formula=(measureCurrentMonth+(measureTodaysDate>=#payDate#))%12
RegExpSubstitute=1
Substitute="^(\d)$":"0\0"

[measureNextPayYear]
Measure=Calc
Formula=(measureCurrentYear+(measureCurrentMonth=12))

[measureNextPayDay]
Measure=Time
TimeStamp=#payDate#-[measureNextPayMonth]-[measureNextPayYear]
TimeStampFormat=%d-%m-%Y
DynamicVariables=1

[measureCountdown]
Measure=Calc
Formula=([measureNextPayDay:TimeStamp]-[measureNow:TimeStamp])
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Countdown timer and timestamp

Post by balala »

Endemoniada wrote: July 26th, 2020, 8:39 pm My initial thoughts on how to cope with December and the year change: add a mod 12 function to the formula for [measureNextPayMonth] so that it evaluates to 1 not 13 after pay day in December; create a new calculated measure [measureNextPayYear] to use in [measureNextPayDay] which returns the current year + 1 if the month is December.
And does it work?
User avatar
Endemoniada
Posts: 6
Joined: February 28th, 2010, 10:52 pm

Re: Countdown timer and timestamp

Post by Endemoniada »

balala wrote: July 26th, 2020, 8:46 pm And does it work?
I think it will if I add:
Substitute="0":"12"
to [measureNextPayMonth].

Otherwise in November after pay day it would evaluate to 0.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Countdown timer and timestamp

Post by balala »

Endemoniada wrote: July 26th, 2020, 8:56 pm I think it will if I add:
Substitute="0":"12"
to [measureNextPayMonth].
Right. I probably would suggest to add the new substitution before the existing one and add the appropriate ^ and $ characters as well: Substitute="^0$":"12","^(\d)$":"0\0".
User avatar
Endemoniada
Posts: 6
Joined: February 28th, 2010, 10:52 pm

Re: Countdown timer and timestamp

Post by Endemoniada »

balala wrote: July 27th, 2020, 6:52 am Right. I probably would suggest to add the new substitution before the existing one and add the appropriate ^ and $ characters as well: Substitute="^0$":"12","^(\d)$":"0\0".
Thanks again. :thumbup:
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Countdown timer and timestamp

Post by balala »

Endemoniada wrote: July 27th, 2020, 9:28 am Thanks again. :thumbup:
Did you get it working as intended?
User avatar
Endemoniada
Posts: 6
Joined: February 28th, 2010, 10:52 pm

Re: Countdown timer and timestamp

Post by Endemoniada »

balala wrote: July 27th, 2020, 9:43 am Did you get it working as intended?
Yes thanks.
Image
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Countdown timer and timestamp

Post by balala »

You're welcome. :thumbup: