changeset 735:c1b0f0c33c6a

mod_archive: Fix hour offset in stored message date os.date expect a timestamp in local time, that is subject to daylight saving. But since we pass an UTC timestamp to os.date one hour is (wrongly) added in the summer. The only sensible thing is to call the os.date only once with the ! parametter. And then parsing this sting to get the utc_timestamp. Calling os.date with an UTC timestamp is not possible, and calling os.date twice without timestamp could give different results.
author Olivier Goffart <ogoffart@woboq.com>
date Wed, 04 Jul 2012 13:49:57 +0200
parents 81de1e446bfe
children b031831b2ac0
files mod_archive/mod_archive.lua
diffstat 1 files changed, 2 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mod_archive/mod_archive.lua	Sun Jul 01 13:51:26 2012 +0200
+++ b/mod_archive/mod_archive.lua	Wed Jul 04 13:49:57 2012 +0200
@@ -37,16 +37,8 @@
     dm.store(node, host, PREFS_DIR, st.preserialize(data));
 end
 
-local function os_date()
-    return os.date("!*t");
-end
-
 local date_time = datetime.datetime;
 
-local function date_format(s)
-	return os.date("%Y-%m-%dT%H:%M:%SZ", s);
-end
-
 local function date_parse(s)
 	local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z");
 	return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec});
@@ -96,9 +88,8 @@
 	local data = dm.list_load(node, host, ARCHIVE_DIR);
     local tag = isfrom and "from" or "to";
     local with = isfrom and msg.attr.to or msg.attr.from;
-    local utc = os_date();
-    local utc_secs = os.time(utc);
-    local utc_datetime = date_format(utc_secs);
+    local utc_datetime = date_time();
+    local utc_secs = date_parse(utc_datetime);
     if data then
         -- The collection list are in REVERSE chronological order 
         for k, v in ipairs(data) do