add parse_iso8691_date function
This commit is contained in:
17
lib/misc.lua
17
lib/misc.lua
@@ -1,4 +1,4 @@
|
||||
function parseHexColor(text)
|
||||
function parse_hex_color(text)
|
||||
local r = tonumber('0x' .. string.sub(text, -8, -7))
|
||||
local g = tonumber('0x' .. string.sub(text, -6, -5))
|
||||
local b = tonumber('0x' .. string.sub(text, -4, -3))
|
||||
@@ -7,3 +7,18 @@ function parseHexColor(text)
|
||||
return r, g, b, a
|
||||
end
|
||||
|
||||
function parse_iso8601_date(json_date)
|
||||
local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%+%-])(%d?%d?)%:?(%d?%d?)"
|
||||
local year, month, day, hour, minute,
|
||||
seconds, offsetsign, offsethour, offsetmin = json_date:match(pattern)
|
||||
local timestamp = os.time{year = year, month = month,
|
||||
day = day, hour = hour, min = minute, sec = seconds}
|
||||
local offset = 0
|
||||
if offsetsign ~= 'Z' then
|
||||
offset = tonumber(offsethour) * 60 + tonumber(offsetmin)
|
||||
if xoffset == "-" then offset = offset * -1 end
|
||||
end
|
||||
|
||||
return timestamp + offset
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user