It is currently April 16th, 2024, 6:15 pm

Parsing a date for countdown.lua

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Parsing a date for countdown.lua

Post by jsmorley »

Well, both the show time and the time we are using are based on GMT, so your location shouldn't matter in one sense, but will matter as the result is "observed" by you.

I'm not a fan of the brute force +1 on the Calc measure myself.

Since the "time" of the show is undefined, you might change the Lua to use:

Code: Select all

function GetDays(month, day, year, measureName)

	local showTime = os.time({year=year, month=month, day=day, hour=23, min=59, sec=59, isdst=false})
	local nowTime = os.time(os.date('!*t'))
	local daysDiff = math.floor((showTime - nowTime ) / 86400)

	SKIN:Bang('!SetOption', measureName, 'Formula', math.abs(daysDiff))
	
end
That will set the "time" of the show to the last minute of the day it airs on instead of the first.

Another thing you might try is to test against your local time, rather than against GMT.

local nowTime = os.time(os.date('*t'))

That might give a better sense of things as observed by you in your location. Now that I chew on it a bit, I think that makes more sense, since the time of the show is undefined, and this might be better relative to your local time.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Parsing a date for countdown.lua

Post by jsmorley »

You can do a little debugging, seeing what the real values are, by changing the Lua to:

Code: Select all

function GetDays(month, day, year, measureName)

	local showTime = os.time({year=year, month=month, day=day, hour=23, min=59, sec=59, isdst=false})
	local nowTime = os.time(os.date('*t'))
	local daysDiff = math.floor((showTime - nowTime ) / 86400)
	
	weeks, days, hours, minutes, seconds = FormatSeconds(showTime - nowTime)
	print(days..' days ', hours..' hours ', minutes..' minutes ', seconds..' seconds')
	
	SKIN:Bang('!SetOption', measureName, 'Formula', math.abs(daysDiff))
	
end

function FormatSeconds(secondsArg)

	local weeks = math.floor(secondsArg / 604800)
	local remainder = secondsArg % 604800
	local days = math.floor(remainder / 86400)
	local remainder = remainder % 86400
	local hours = math.floor(remainder / 3600)
	local remainder = remainder % 3600
	local minutes = math.floor(remainder / 60)
	local 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
StArL0rd84
Posts: 424
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Parsing a date for countdown.lua

Post by StArL0rd84 »

Thanks, but the only thing that seems to have any effect on the bar (For me at least) is the brute force method.
I realize that day seven would never fill up, but hey, at least the bar shows what time has elapsed.
barss2.png
You do not have the required permissions to view the files attached to this post.
([mWorkTime] = 1 ? #Work# : ([mEnergyLoss:%] >= 70% ? #Chillmode# : </>))
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Parsing a date for countdown.lua

Post by jsmorley »

Strange, unless I'm missing some "Wibbly wobbly, timey wimey" logic here, what I just posted feels like it should work right in all cases in all locations. It's based on the "local time", which I probably should have done from the start, given that the show time is undefined.