Software /
code /
prosody-modules
Comparison
mod_archive/mod_archive.lua @ 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 |
parent | 632:dcb8e7d2c711 |
child | 736:b031831b2ac0 |
comparison
equal
deleted
inserted
replaced
734:81de1e446bfe | 735:c1b0f0c33c6a |
---|---|
35 | 35 |
36 local function store_prefs(data, node, host) | 36 local function store_prefs(data, node, host) |
37 dm.store(node, host, PREFS_DIR, st.preserialize(data)); | 37 dm.store(node, host, PREFS_DIR, st.preserialize(data)); |
38 end | 38 end |
39 | 39 |
40 local function os_date() | |
41 return os.date("!*t"); | |
42 end | |
43 | |
44 local date_time = datetime.datetime; | 40 local date_time = datetime.datetime; |
45 | |
46 local function date_format(s) | |
47 return os.date("%Y-%m-%dT%H:%M:%SZ", s); | |
48 end | |
49 | 41 |
50 local function date_parse(s) | 42 local function date_parse(s) |
51 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z"); | 43 local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)Z"); |
52 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec}); | 44 return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec}); |
53 end | 45 end |
94 local body = msg:child_with_name("body"); | 86 local body = msg:child_with_name("body"); |
95 local thread = msg:child_with_name("thread"); | 87 local thread = msg:child_with_name("thread"); |
96 local data = dm.list_load(node, host, ARCHIVE_DIR); | 88 local data = dm.list_load(node, host, ARCHIVE_DIR); |
97 local tag = isfrom and "from" or "to"; | 89 local tag = isfrom and "from" or "to"; |
98 local with = isfrom and msg.attr.to or msg.attr.from; | 90 local with = isfrom and msg.attr.to or msg.attr.from; |
99 local utc = os_date(); | 91 local utc_datetime = date_time(); |
100 local utc_secs = os.time(utc); | 92 local utc_secs = date_parse(utc_datetime); |
101 local utc_datetime = date_format(utc_secs); | |
102 if data then | 93 if data then |
103 -- The collection list are in REVERSE chronological order | 94 -- The collection list are in REVERSE chronological order |
104 for k, v in ipairs(data) do | 95 for k, v in ipairs(data) do |
105 local collection = st.deserialize(v); | 96 local collection = st.deserialize(v); |
106 local do_save = function() | 97 local do_save = function() |