Software /
code /
prosody
Changeset
9698:e616c37756b3 0.11
util.datetime: Make sure timezone difference is calculated correctly (fixes #1262)
If the two os.date() calls happen at either side of a second ticking
over there would be a one second error in the calculation.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 09 Dec 2018 23:01:47 +0100 |
parents | 9674:6f97acc4583b |
children | 9699:588ec80f1677 9703:0cfb7b3593eb |
files | util/datetime.lua |
diffstat | 1 files changed, 2 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/datetime.lua Sat Dec 01 18:30:19 2018 +0100 +++ b/util/datetime.lua Sun Dec 09 23:01:47 2018 +0100 @@ -38,7 +38,8 @@ local year, month, day, hour, min, sec, tzd; year, month, day, hour, min, sec, tzd = s:match("^(%d%d%d%d)%-?(%d%d)%-?(%d%d)T(%d%d):(%d%d):(%d%d)%.?%d*([Z+%-]?.*)$"); if year then - local time_offset = os_difftime(os_time(os_date("*t")), os_time(os_date("!*t"))); -- to deal with local timezone + local now = os_time(); + local time_offset = os_difftime(os_time(os_date("*t", now)), os_time(os_date("!*t", now))); -- to deal with local timezone local tzd_offset = 0; if tzd ~= "" and tzd ~= "Z" then local sign, h, m = tzd:match("([+%-])(%d%d):?(%d*)");