From 969c080b5e613fa5eb32c2ac100b6c8d231b170e Mon Sep 17 00:00:00 2001 From: Coranna Howard Date: Sat, 3 Sep 2016 02:12:33 -0700 Subject: [PATCH] app/core/Pickle.lua: use a table to store parsed time, take table on formatting. --- app/core/src/pickle/app_core/Pickle.lua | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/core/src/pickle/app_core/Pickle.lua b/app/core/src/pickle/app_core/Pickle.lua index 907a89d..bd01b93 100644 --- a/app/core/src/pickle/app_core/Pickle.lua +++ b/app/core/src/pickle/app_core/Pickle.lua @@ -260,9 +260,39 @@ local function casual_file_same(a, b) end function M.parse_time(time_str, format) - return Internal.strptime(time_str, format) + local time = {} + time.secs, time.offset = Internal.strptime(time_str, format) + return time end +function M.format_time(time, format) + if type(time) == "table" then + return Internal.strftime(time.secs, format, time.offset) + else + return Internal.strftime(time, format, 0) + end +end + +--[[do + local iso_format = "%Y-%m-%dT%H:%M:%S%z" + local function check(str, secs, offset) + local time = M.parse_time(str, iso_format) + local str_rewritten = M.format_time(time, iso_format) + print("## check: ") + print(" i " .. str) + print(" r " .. str_rewritten) + print(" s " .. tostring(time.secs) .. " " .. tostring(time.secs - secs)) + print(" " .. tostring(secs)) + print(" z " .. tostring(time.offset) .. " " .. tostring(time.offset - offset)) + print(" " .. tostring(offset)) + U.assert(time.offset == offset, "offset") + U.assert(time.secs == secs, "secs") + U.assert(str == str_rewritten, "str") + end + check("2016-09-03T00:00:00+0000", 1472860800, 0) + check("2015-10-07T01:34:00-0400", 1444196040, -14400) +end--]] + function M.replace_fields(to, from) for k, v in pairs(from) do local c = to[k]