It is currently March 28th, 2024, 1:34 pm

Simple countdown timer

Get help with creating, editing & fixing problems with skins
Post Reply
User avatar
deXxterlab97
Posts: 93
Joined: February 5th, 2017, 4:50 am
Contact:

Simple countdown timer

Post by deXxterlab97 »

I want to create a simple countdown timer but currently lost on where to start

It just count the time difference between current time and end time (that I defined)


I am currently looking at this topic but it only shows how to do it when the start time is 0 and end time is something defined in seconds (or vice versa) only https://forum.rainmeter.net/viewtopic.php?p=51733#p51733
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

I'll promote again one of my previous works: https://forum.rainmeter.net/viewtopic.php?p=74805#p74805
Probably you need the Countdown skin of this package. Please check it and let me know if it's useful for you.
User avatar
deXxterlab97
Posts: 93
Joined: February 5th, 2017, 4:50 am
Contact:

Re: Simple countdown timer

Post by deXxterlab97 »

balala wrote:I'll promote again one of my previous works: https://forum.rainmeter.net/viewtopic.php?p=74805#p74805
Probably you need the Countdown skin of this package. Please check it and let me know if it's useful for you.
Yes it's really useful but your skin only goes up to hour

I want to create a more detailed countdown that goes up to month and maybe year

I can see a way to make a countdown between 2 dates of a same month but since these 2 are in seperate months it could be a harder task

My approach so far is as follow: make all date to seconds so then I can substract them, then divide the result to get the corresponding result in hours, minutes, seconds...

As for months I am thinking of a conditional statement where it checks what months it is and then return the how many days has past from the start of the year till the beginning of that month, then I have no of days to work with I can then convert them back to seconds. But it looks very long.

This is my code so far

Code: Select all

[Rainmeter]
Update=1000

[Variables]
Month=08
Date=31
Hour=19
Minute=0
Second=0

[CurrentTimeMh]
Measure=Time
Format=%#m

[CurrentTimeD]
Measure=Time
Format=%#d

[CurrentTimeH]
Measure=Time
Format=%#H

[CurrentTimeM]
Measure=Time
Format=%#M

[CurrentTimeS]
Measure=Time
Format=%#S

[HourMinSecDiff] ;in seconds
Measure=Calc
Formula=((#Hour#*3600+#Minute#*60+#Second#)-(CurrentTimeH*3600+CurrentTimeM*60+CurrentTimeS))

[HourDiff]
Measure=Calc
Formula=(FLOOR (HourMinSecDiff / 3600))

[HourTest]
Meter=String
MeasureName=HourDiff
FontColor=255,255,255
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

Brute force math on the month, day, hour, minute, second is never going to work. How many seconds are in a month? How many seconds are in a year? How many seconds are in February? None of those has any reasonable answer that isn't a massive amount of work. You are going to need some function, either in Rainmeter proper or Lua, to convert a date / time string into a timestamp. Then get the current date and time as a timestamp and subtract the two.

Rainmeter has some nice features in the Time measure for turning date / time strings into a Windows timestamp value, and the Uptime measure can actually be used to turn a "difference" in seconds into "days, hours, minutes, seconds".
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

Code: Select all

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

[Variables]
Target=7/26/2017 8:32:10

[MeasureNow]
Measure=Time
Format=%A, %B %#d, %Y %#I:%M %p

[MeasureThen]
Measure=Time
TimeStamp=#Target#
TimeStampFormat=%m/%d/%Y %H:%M:%S
Format=%A, %B %#d, %Y %#I:%M %p

[MeasureDiff]
Measure=Calc
Formula=[MeasureThen:Timestamp]-[MeasureNow:Timestamp]
DynamicVariables=1
IfCondition=MeasureDiff < 1
IfTrueAction=[!SetOption MeterCountdown Text "Target:		%1#CRLF#Current:		%2#CRLF#Countdown:	Completed!"]
IfFalseAction=[!SetOption MeterCountdown Text "Target:		%1#CRLF#Current:		%2#CRLF#Countdown:	%3"]

[MeasureFormatSeconds]
Measure=UpTime
SecondsValue=[MeasureDiff]
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

[MeterCountdown]
Meter=String
MeasureName=MeasureThen
MeasureName2=MeasureNow
MeasureName3=MeasureFormatSeconds
FontSize=13
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
1.png
https://docs.rainmeter.net/manual-beta/measures/time/
https://docs.rainmeter.net/manual-beta/measures/uptime/
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

EDIT: Sorry jsmorley, you again was much quicker then me...
deXxterlab97 wrote:Yes it's really useful but your skin only goes up to hour
The Countdown.ini of that package counts down from the set time to zero. Have you tried it?
deXxterlab97 wrote:I want to create a more detailed countdown that goes up to month and maybe year
I think my skin can be easily modified to show not just the hours, minutes and seconds, but the days, months, too.
deXxterlab97 wrote:I can see a way to make a countdown between 2 dates of a same month but since these 2 are in seperate months it could be a harder task

My approach so far is as follow: make all date to seconds so then I can substract them, then divide the result to get the corresponding result in hours, minutes, seconds...
Or for such cases maybe a lua script also could be useful. Lua being a programming language, has functions to get the difference between two moments.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

balala wrote: Or for such cases maybe a lua script also could be useful. Lua being a programming language, has functions to get the difference between two moments.
I actually prefer Lua for this, and almost always use it. Although the timestamp stuff in the Time measure in Rainmeter is perfectly good, I find using the Uptime measure to format the output to be pretty limiting. So I just use Lua for that, and since I'm already out in Lua anyway, I just use the very powerful date / time features in Lua to do the whole thing.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

jsmorley wrote:I actually prefer Lua for this, and almost always use it. Although the timestamp stuff in the Time measure in Rainmeter is perfectly good, I find using the Uptime measure to format the output to be pretty limiting. So I just use Lua for that.
Yeah, probably it is much more reliable for such calculations. And probably easier to use, at least if the user has some experience.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

balala wrote:Yeah, probably it is much more reliable for such calculations. And probably easier to use, at least if the user has some experience.
While both ways are "reliable" enough, I find it a challenge in Rainmeter to deal with time zones, and Daylight Saving time and "local" vs "UTC" and all that, and Lua is pretty good at it. Not a big deal in this particular case, just counting seconds between two date / time settings that are already "apples and apples", but in other cases, the power of Lua really helps.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

deXxterlab97 wrote: I want to create a more detailed countdown that goes up to month and maybe year
You will find it difficult to create a countdown that uses years and / or months. The largest time increment that is consistent enough to be accurate is going to be weeks. There are always a fixed number of seconds in a week, day, hour, and minute, but not in a month, year, decade, century etc.

To use months or years you are back to just hideous amounts of calculation about "what" month it is, is it a leap year, and all that. That is less a "countdown" type of calculation, and more of a "calendar" calculation.
Post Reply