Diff

util/datetime.lua @ 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
parent 8555:4f0f5b49bb03
child 12629:4c1d3f817063
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*)");