It is currently March 29th, 2024, 12:28 am

Use leading zeros on lua countdown

Get help with creating, editing & fixing problems with skins
JohnSmithESP
Posts: 7
Joined: June 15th, 2018, 2:10 pm

Use leading zeros on lua countdown

Post by JohnSmithESP »

Hi, I´m trying to edit a countdown skin made in lua https://goo.gl/gKXnBC, but i dont know hot to change from 18:1:3 to 18:01:03
.ini
[Rainmeter]
Update=100
OnRefreshAction=!execute [!RainMetershowMetergroup Hover]
MouseOverAction=!execute [!rainmetershowMetergroup Hover]
MouseLeaveAction=!execute [!rainmetershowmetergroup Hover]

[Metadata]
Name=Countdown
Config=
Description=An accurate countdown timer that will only show up when you hover over the icon.
Instructions=You can change the date in the countdown.ini file. | You can change the logo.png to match what you're counting down to.
Version=1.0
Tags=countdown | time
License=
Variant=1
Preview=#CURRENTPATH#preview.png

[Variables]
Color=255, 255, 255, 255
FontName=Trebuchet MS
FontHeight=40

;Set these variables so change the day the count down is counting to, and to change what the text says when it hits that time!;

toYear=2018
toMonth=6
toDay=20
toHour=19
toMinute=00
toSecond=00
ReleaseText="Han llegado las"

;Measures;

[MeasureScript]
Measure=script
ScriptFile=#CURRENTPATH#countdown.lua
TableName=Countdown
year=#toYear#
month=#toMonth#
day=#toDay#
hour=#toHour#
min=#toMinute#
sec=#toSecond#
fintext=#ReleaseText#

;Meters;

[MeterString]
Meter=string
MeasureName=MeasureScript
X=R
Y=0
H=100
FontFace=#FontName#
FontSize=#FontHeight#
FontColor=#Color#
StringStyle=BOLD
AntiAlias=1
Text=%1
Group=Hover

[MeterString2]
Meter=String
Text="Ofertas de Verano de Steam"
FontFace=#FontName#
FontSize=15
FontColor=#Color#
AntiAlias=1
X=-2r
Y=54r
Color=255, 255, 255, 255
.lua
PROPERTIES = {year=0, month=0, day=0, hour=0, min=0, sec=0, fintext=""}

function Initialize()

RELEASEDATE = {}
setmetatable(RELEASEDATE, getmetatable(PROPERTIES))
for k,v in pairs(PROPERTIES) do
if k ~= fintext then
RELEASEDATE[k] = v
end
end
RELEASEDATE.isdst = true

RELEASETEXT = PROPERTIES.fintext or ""

end

function GetTimeLeft()
local dif = os.time(RELEASEDATE) - os.time()
local timeleft = {
[1] = math.floor(dif/60/60/24), --day
[2] = math.floor(dif/60/60)%24, --hour
[3] = math.floor(dif/60)%60, --minute
[4] = math.floor(dif)%60 --second
}

local text = {}
for i=1, #timeleft do
if i == 1 then
if timeleft > 0 then

table.insert(text,timeleft)
end
else
table.insert(text,timeleft)
end
end

if dif <= 0 then
text = RELEASETEXT
else
text = table.concat(text,":")
end
return tostring(text)
end

function Update()
end

function GetStringValue()

return GetTimeLeft()

end


Sorry for my english and thanks in advance
Last edited by JohnSmithESP on June 15th, 2018, 3:52 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Use leading zeros on lua countdown

Post by balala »

Replace the GetTimeLeft() function of the .lua script with the following statement:

Code: Select all

function GetTimeLeft()
	local dif = os.time(RELEASEDATE) - os.time()
	local timeleft = {
		[1] = math.floor(dif/60/60/24), --day
		[2] = math.floor(dif/60/60)%24, --hour
		[3] = math.floor(dif/60)%60, --minute
		[4] = math.floor(dif)%60 --second
	}

	local text = {}
	for i=1, #timeleft do
		if i == 1 then
			if timeleft[i] > 0 then
				table.insert(text,timeleft[i])
			end
		else
			if timeleft[i] < 10 then
				table.insert(text,'0'..timeleft[i])
			else
				table.insert(text,timeleft[i])
			end
		end
	end
	if dif <= 0 then
		text = RELEASETEXT
	else
		text = table.concat(text,":")
	end
	return tostring(text)
end
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Use leading zeros on lua countdown

Post by balala »

As I can see, you've marked the question as solved. Is it solved indeed?
JohnSmithESP
Posts: 7
Joined: June 15th, 2018, 2:10 pm

Re: Use leading zeros on lua countdown

Post by JohnSmithESP »

Solved
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Use leading zeros on lua countdown

Post by balala »

JohnSmithESP wrote:Solved
Ok, great. :thumbup: