# HG changeset patch # User Olivier Goffart # Date 1341402597 -7200 # Node ID c1b0f0c33c6a8016e73cc48cc82b331255c2f239 # Parent 81de1e446bfe0c709144a58e6f2bbfab4781b991 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. diff -r 81de1e446bfe -r c1b0f0c33c6a mod_archive/mod_archive.lua --- 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