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.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.
It is currently October 13th, 2024, 6:47 am
Simple countdown timer
-
- Rainmeter Sage
- Posts: 16651
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Simple countdown timer
-
- Developer
- Posts: 22851
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
If I was going to do this in Lua entirely, and I likely would, it would be something like:
Skin:
Countdown.lua:
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
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
You do not have the required permissions to view the files attached to this post.
-
- Developer
- Posts: 22851
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
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:
Countdown.lua:
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
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
You do not have the required permissions to view the files attached to this post.
-
- Posts: 93
- Joined: February 5th, 2017, 4:50 am
Re: Simple countdown timer
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.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.
deXxterlab97
-
- Developer
- Posts: 22851
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
https://forum.rainmeter.net/viewtopic.php?p=138245#p138245deXxterlab97 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.
-
- Posts: 3
- Joined: August 1st, 2020, 4:46 pm
Re: Simple countdown timer
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
-
- Rainmeter Sage
- Posts: 2746
- Joined: March 23rd, 2015, 5:26 pm
Re: Simple countdown timer
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?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
You do not have the required permissions to view the files attached to this post.
-
- Developer
- Posts: 22851
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Simple countdown timer
-
- Posts: 3
- Joined: August 1st, 2020, 4:46 pm
Re: Simple countdown timer
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.
Not a big deal.
-
- Posts: 1831
- Joined: February 17th, 2011, 7:45 pm
- Location: a Galaxy S7 far far away
Re: Simple countdown timer
Last edited by sl23 on September 4th, 2024, 6:45 am, edited 1 time in total.
57686174 77696C6C 6265 77696C6C 6265