Comparison

mod_storage_muc_log/mod_storage_muc_log.lua @ 1568:c357039c1ab1

mod_storage_muc_log: Change to sane timestamp format and warn if it differs from legacy mod_muc_log timestamps
author Kim Alvefur <zash@zash.se>
date Mon, 10 Nov 2014 14:51:36 +0100
parent 1566:9158882dd9a1
child 1569:711fabfe6604
comparison
equal deleted inserted replaced
1567:585bb8ac11bb 1568:c357039c1ab1
6 local datetime = require"util.datetime" 6 local datetime = require"util.datetime"
7 local lfs = require"lfs"; 7 local lfs = require"lfs";
8 local noop = function () end; 8 local noop = function () end;
9 local os_date = os.date; 9 local os_date = os.date;
10 10
11 local timef, datef = "!%X", "!%y%m%d"; 11 local timef, datef = "!%H:%M:%S", "!%y%m%d";
12 local host = module.host; 12 local host = module.host;
13 13
14 local driver = {}; 14 local driver = {};
15 local driver_mt = { __index = driver }; 15 local driver_mt = { __index = driver };
16 16
17 do 17 do
18 -- Sanity check 18 -- Sanity check
19 -- Fun fact: 09:00 and 21:00 en_HK are both "09:00:00 UTC" 19 -- Fun fact: 09:00 and 21:00 en_HK are both "09:00:00 UTC"
20 local t = os_date("!*t"); 20 local t = os_date("!*t");
21 t.hour = 9; 21 t.hour = 9;
22 local am = os_date(timef, os.time(t)); 22 local am = os_date("!%X", os.time(t));
23 t.hour = 21; 23 t.hour = 21;
24 local pm = os_date(timef, os.time(t)); 24 local pm = os_date("!%X", os.time(t));
25 if am == pm then 25 if am == pm then
26 module:log("warn", "Timestamps in AM and PM are identical in your locale, expect timestamps to be wrong"); 26 module:log("warn", "Timestamps in AM and PM are identical in your locale, expect timestamps to be wrong");
27 end
28 if os_date("!%X", os.time(t)) ~= os_date(timef, os_date(t)) then
29 module:log("warn", "Timestamp format differ from what mod_muc_log used, this module may not work correctly");
27 end 30 end
28 end 31 end
29 32
30 local function parse_silly(date, time) 33 local function parse_silly(date, time)
31 local year, month, day = date:match("^(%d%d)(%d%d)(%d%d)"); 34 local year, month, day = date:match("^(%d%d)(%d%d)(%d%d)");