I’m looking for any suggestions on the easiest/best way to get the current DST offset of a Vera device?
The os.date() function, documented here Lua 5.1 Reference Manual can return a table which contains a Boolean variable isdst.
local t = os.date "*t"
print (pretty(t))
{
day = 29,
hour = 16,
isdst = true,
min = 31,
month = 8,
sec = 47,
wday = 3,
yday = 241,
year = 2017
}
Right, that’ll do it.
Take os.time vs UTC an knowing if isDST, voil?.
Thanks.
Not sure exactly what you are looking for, just DST on/off, or something else. But if it is something else, you might find this page useful:
http://lua-users.org/wiki/TimeZone
In particular, this function is sometimes helpful:
-- return the timezone offset in seconds, as it was on the time given by ts
-- Eric Feliksik
local function get_timezone_offset(ts)
local utcdate = os.date("!*t", ts)
local localdate = os.date("*t", ts)
localdate.isdst = false -- this is the trick
return os.difftime(os.time(localdate), os.time(utcdate))
end
Thanks, my thinking was that there may be a Vera setting that was easily accessible… but calculating the offset (as you showed) is rather trivial.
I appreciate your response.
…what could POSSIBLY have led you to think that?! :o
Just be careful you don’t rely too much on this value, because there are a number of circumstances under which it is wrong. The most annoying is that it is correct only at the instant that the Luup engine started, so if you have experienced a daylight saving transition since then, the cached value will be out by an hour. I also recall a limitation in Lua that it will assume this offset applies to all times in the future and past, so you can’t use it to forecast a time of day (say) six months in advance (even less if a daylight saving transition is in your near future).
It’s my experience that if you find yourself wanting to know your UTC offset then there’s a good chance that you’re thinking about a problem the wrong way to begin with. I don’t think I’ve ever used it in my plugins, and that includes very timey things like Heliotrope and Countdown Timer.
(I have a lot of experience with time zones. So much that this xkcd comic is one of the funniest I’ve seen.)
yeah, I’m not interested too much in the local time, but I wanted to add an OLED to my 3G bridge and add some time data to the visual display.
My goal was to sync the time from my Vera, and then display some information regarding the last communication. I was nerd sniped on this for a while, have to come back to it soon…
At least you’re in something other than UTC. No developer should live in the zone.
Love the xkcd, they’re usually spot on the mark.