Comparison

util/datetime.lua @ 5107:6ac790efecd3

util.datetime: Fix timestamp parsing pattern.
author Waqas Hussain <waqas20@gmail.com>
date Tue, 28 Aug 2012 05:08:18 +0500
parent 4250:7b456af75c77
child 5776:bd0ff8ae98a8
comparison
equal deleted inserted replaced
5105:50688a2856f7 5107:6ac790efecd3
34 end 34 end
35 35
36 function parse(s) 36 function parse(s)
37 if s then 37 if s then
38 local year, month, day, hour, min, sec, tzd; 38 local year, month, day, hour, min, sec, tzd;
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*)"); 44 local sign, h, m = tzd:match("([+%-])(%d%d):?(%d*)");