It is currently May 21st, 2024, 1:13 pm

Simple countdown timer

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16250
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Simple countdown timer

Post by balala »

jsmorley wrote:You will find it difficult to create a countdown that uses years and / or months. The largest time value 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.
Right. I also got stuck once in this problem in the past and wasn't able to find a good solution. Hard to be implemented, I think even with Lua.
User avatar
jsmorley
Developer
Posts: 22634
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

If I was going to do this in Lua entirely, and I likely would, it would be something like:

Skin:

Code: Select all

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

[Variables]
Target=9/27/2017 11:32:10

[MeasureLua]
Measure=Script
ScriptFile=#CURRENTPATH#Countdown.lua

[MeterCountdown]
Meter=String
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Countdown.lua:

Code: Select all

function Update()

	targetString = SKIN:GetVariable('Target')
	
	timeTarget = TimeStamp(targetString)
	timeNow = os.time(os.date('*t'))
	
	countDown = os.difftime(timeTarget, timeNow)
	if countDown < 0 then countDown = 0 end
	weeks, days, hours, minutes, seconds = FormatSeconds(countDown)	
	
	if weeks == 1 then weekText = "week" else weekText="weeks" end
	if days == 1 then dayText = "day" else dayText="days" end
	if hours == 1 then hourText = "hour" else hourText="hours" end
	if minutes == 1 then minuteText = "minute" else minuteText="minutes" end
	if seconds == 1 then secondText = "second" else secondText="seconds" end
	
	if countDown < 60 then
		countdownDisplay = seconds..secondText
	end
	if countDown >= 60 then
		countdownDisplay = minutes..' '..minuteText..' '..seconds..' '..secondText
	end
	if countDown >= 3600 then
		countdownDisplay = hours..' '..hourText..' '..minutes..' '..minuteText..' '..seconds..' '..secondText	
	end
	if countDown >= 86400 then
		countdownDisplay = days..' '..dayText..' '..hours..' '..hourText..' '..minutes..' '..minuteText..' '..seconds..' '..secondText	
	end
	if countDown >= 604800 then
		countdownDisplay = weeks..' '..weekText..' '..days..' '..dayText..' '..hours..' '..hourText..' '..minutes..' '..minuteText..' '..seconds..' '..secondText	
	end

	SKIN:Bang('!SetOption', 'MeterCountdown', 'Text', countdownDisplay)
	
end

function TimeStamp(targetString)
   
   -- date format: 7/26/2017 8:32:10

   month, day, year, hour, min, sec =
   string.match(targetString, "(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)")

   timeStamp = os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec, isdst=false})
   
   return timeStamp

end

function FormatSeconds(secondsArg)

	weeks = math.floor(secondsArg / 604800)
	remainder = secondsArg % 604800
	days = math.floor(remainder / 86400)
	remainder = remainder % 86400
	hours = math.floor(remainder / 3600)
	remainder = remainder % 3600
	minutes = math.floor(remainder / 60)
	seconds = remainder % 60
	
	return weeks, days, hours, minutes, seconds
	
end
1.png
You do not have the required permissions to view the files attached to this post.
User avatar
jsmorley
Developer
Posts: 22634
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

Of course, once you have figured out the difference in weeks, days, hours, minutes, and seconds, you can do all kinds of different things with that in your skin...

Skin:

Code: Select all

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

[Variables]
Target=9/27/2017 11:32:10

[MeasureLua]
Measure=Script
ScriptFile=#CURRENTPATH#Countdown.lua

[MeasureWeeks]
Measure=Calc
[MeasureDays]
Measure=Calc
[MeasureHours]
Measure=Calc
[MeasureMinutes]
Measure=Calc
[MeasureSeconds]
Measure=Calc

[MeterBack]
Meter=Shape
Shape=Rectangle 0.75,0.75,478,98,12 | StrokeWidth 1.5 | Stroke Color 150,150,150,255 | Fill Color 0,0,0,255

[MeterWeeks]
Meter=Bitmap
MeasureName=MeasureWeeks
X=10
Y=10
BitmapImage=#@#Nixie\digits60.png
BitmapFrames=10
BitmapExtend=1
BitmapDigits=2

[MeterDays]
Meter=Bitmap
MeasureName=MeasureDays
X=15R
Y=0r
BitmapImage=#@#Nixie\digits60.png
BitmapFrames=10
BitmapExtend=1
BitmapDigits=2

[MeterHours]
Meter=Bitmap
MeasureName=MeasureHours
X=15R
Y=0r
BitmapImage=#@#Nixie\digits60.png
BitmapFrames=10
BitmapExtend=1
BitmapDigits=2

[MeterMinutes]
Meter=Bitmap
MeasureName=MeasureMinutes
X=15R
Y=0r
BitmapImage=#@#Nixie\digits60.png
BitmapFrames=10
BitmapExtend=1
BitmapDigits=2

[MeterSeconds]
Meter=Bitmap
MeasureName=MeasureSeconds
X=15R
Y=0r
BitmapImage=#@#Nixie\digits60.png
BitmapFrames=10
BitmapExtend=1
BitmapDigits=2

[MeterWeeksText]
Meter=String
X=27
Y=70
FontSize=9
FontColor=255,228,110,255
FontWeight=400
AntiAlias=1
Text=WEEKS

[MeterDaysText]
Meter=String
X=130
Y=70
FontSize=9
FontColor=255,228,110,255
FontWeight=400
AntiAlias=1
Text=DAYS

[MeterHoursText]
Meter=String
X=218
Y=70
FontSize=9
FontColor=255,228,110,255
FontWeight=400
AntiAlias=1
Text=HOURS

[MeterMinutesText]
Meter=String
X=308
Y=70
FontSize=9
FontColor=255,228,110,255
FontWeight=400
AntiAlias=1
Text=MINUTES

[MeterSecondsText]
Meter=String
X=399
Y=70
FontSize=9
FontColor=255,228,110,255
FontWeight=400
AntiAlias=1
Text=SECONDS
Countdown.lua:

Code: Select all

function Update()

	targetString = SKIN:GetVariable('Target')
	
	timeTarget = TimeStamp(targetString)
	timeNow = os.time(os.date('*t'))
	
	countDown = os.difftime(timeTarget, timeNow)
	if countDown < 0 then countDown = 0 end
	weeks, days, hours, minutes, seconds = FormatSeconds(countDown)	
	
	SKIN:Bang('!SetOption', 'MeasureWeeks', 'Formula', weeks)
	SKIN:Bang('!SetOption', 'MeasureDays', 'Formula', days)
	SKIN:Bang('!SetOption', 'MeasureHours', 'Formula', hours)
	SKIN:Bang('!SetOption', 'MeasureMinutes', 'Formula', minutes)
	SKIN:Bang('!SetOption', 'MeasureSeconds', 'Formula', seconds)

end

function TimeStamp(targetString)
   
   -- date format: 7/26/2017 8:32:10

   month, day, year, hour, min, sec =
   string.match(targetString, "(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)")

   timeStamp = os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec, isdst=false})
   
   return timeStamp

end

function FormatSeconds(secondsArg)

	weeks = math.floor(secondsArg / 604800)
	remainder = secondsArg % 604800
	days = math.floor(remainder / 86400)
	remainder = remainder % 86400
	hours = math.floor(remainder / 3600)
	remainder = remainder % 3600
	minutes = math.floor(remainder / 60)
	seconds = remainder % 60
	
	return weeks, days, hours, minutes, seconds
	
end
1.png
Countdown_1.0.rmskin
You do not have the required permissions to view the files attached to this post.
User avatar
deXxterlab97
Posts: 93
Joined: February 5th, 2017, 4:50 am

Re: Simple countdown timer

Post by deXxterlab97 »

jsmorley wrote: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.
Yeah I see, how would your above code (Christmas countdown) works if doing just rainmeter. I don't feel like learning a new programming language just to create a single skin.
deXxterlab97
User avatar
jsmorley
Developer
Posts: 22634
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

deXxterlab97 wrote:Yeah I see, how would your above code (Christmas countdown) works if doing just rainmeter. I don't feel like learning a new programming language just to create a single skin.
https://forum.rainmeter.net/viewtopic.php?p=138245#p138245
richjackman242
Posts: 3
Joined: August 1st, 2020, 4:46 pm

Re: Simple countdown timer

Post by richjackman242 »

MODERN GADGETS: How do you start the countdown timer - I've entered an event name and a time in the future. Doesn't seem to be counting down
User avatar
SilverAzide
Rainmeter Sage
Posts: 2641
Joined: March 23rd, 2015, 5:26 pm

Re: Simple countdown timer

Post by SilverAzide »

richjackman242 wrote: August 19th, 2020, 11:38 am MODERN GADGETS: How do you start the countdown timer - I've entered an event name and a time in the future. Doesn't seem to be counting down
The timer starts counting down immediately after entering a valid date and time. There is nothing you need to do to start it. Is the date/time you entered in the proper format?
Clock.jpg
You do not have the required permissions to view the files attached to this post.
Gadgets Wiki GitHub More Gadgets...
User avatar
jsmorley
Developer
Posts: 22634
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Simple countdown timer

Post by jsmorley »

dvo wrote: August 20th, 2020, 8:15 pm JsMorley question... how can i change if there is one week or one day or hour left change it from weeks to week ..hours tot hour days ect... :D
The approach is in the Lua here:

https://forum.rainmeter.net/viewtopic.php?t=26472&p=181966#p138257
richjackman242
Posts: 3
Joined: August 1st, 2020, 4:46 pm

Re: Simple countdown timer

Post by richjackman242 »

Ok, I've got the countdown working. The thing is, I couldn't edit it with the little wrench settings. I had to go in and edit the in. That's the only way my changes would save.

Not a big deal.
User avatar
sl23
Posts: 1150
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: Simple countdown timer

Post by sl23 »

Back again :Whistle

Can I please get some help creating a simple countdown timer. I've looked at balala's and at JSMorley's code earlier in this thread, but can't seem to get what I want. Balala's skin is great, but I really want it as simple as possible.

Just set say, 90 minutes or 120 minutes in a [Variable] and the skin counts down. I've tried to edit balala's code but it's too much to get my head around! :oops: too bloody tired to think straight! :yawn:

I would like a Meter to show the timer as in balala's skin, or even JSMorley's earlier code, with the end result putting PC into hibernation, which I can do. But all the setting options are unnecessary for me.

Thanks.
- MuLab -