Comparison

util/datetime.lua @ 3642:ed80c4c56b9c

util.datetime: Fixes for more liberal timezone parsing - colon and minutes are both (independantly) optional (thanks Zash)
author Matthew Wild <mwild1@gmail.com>
date Sat, 27 Nov 2010 01:22:43 +0000
parent 3430:970690b3cb28
child 3643:2dc342a13f35
comparison
equal deleted inserted replaced
3641:3603aeb325de 3642:ed80c4c56b9c
39 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+%-].*)$"); 39 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+%-].*)$");
40 if year then 40 if year then
41 local time_offset = os_difftime(os_time(os_date("*t")), os_time(os_date("!*t"))); -- to deal with local timezone 41 local time_offset = os_difftime(os_time(os_date("*t")), os_time(os_date("!*t"))); -- to deal with local timezone
42 local tzd_offset = 0; 42 local tzd_offset = 0;
43 if tzd ~= "" and tzd ~= "Z" then 43 if tzd ~= "" and tzd ~= "Z" then
44 local sign, h, m = tzd:match("([+%-])(%d%d):(%d%d)"); 44 local sign, h, m = tzd:match("([+%-])(%d%d):?(%d*)");
45 if not sign then return; end 45 if not sign then return; end
46 if #m ~= 2 then m = "0"; end
46 h, m = tonumber(h), tonumber(m); 47 h, m = tonumber(h), tonumber(m);
47 tzd_offset = h * 60 * 60 + m * 60; 48 tzd_offset = h * 60 * 60 + m * 60;
48 if sign == "-" then tzd_offset = -tzd_offset; end 49 if sign == "-" then tzd_offset = -tzd_offset; end
49 end 50 end
50 sec = sec + time_offset + tzd_offset; 51 sec = sec + time_offset + tzd_offset;