summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2018-07-06 15:14:33 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2018-09-08 16:12:35 +0200
commitba120b9edec8a34b12bbc8b2530d890afc545364 (patch)
tree2ec39043c297d38e1afdc8e0bde89f41504eb16f
parent76a4936f065ef0f84ff61c74c8f5c800ca019011 (diff)
downloadcaldr-ba120b9edec8a34b12bbc8b2530d890afc545364.tar.gz
rem: format date as iso 8601 timestamps
-rw-r--r--rem.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/rem.lua b/rem.lua
index a696f83..ddee9a6 100644
--- a/rem.lua
+++ b/rem.lua
@@ -6,6 +6,8 @@
local inspect = require "ext.inspect"
+local iso8601dates = true --false --- write ISO 8601 dates
+
local pcall = pcall
local io = require "io"
@@ -155,8 +157,8 @@ local rem_of_vcalendars do
local parse_date_value = function (val)
local params = val.params
- local ptzid = get_param_value_1 (params, "TZID")
- local pdate = get_param_value_1 (params, "VALUE")
+ local ptzid = get_param_value_1 (params, "TZID")
+ local pdate = get_param_value_1 (params, "VALUE")
if pdate == nil or pdate == "DATE-TIME" then
return parse_date_value_DATE_TIME (val.value, ptzid)
@@ -169,20 +171,35 @@ local rem_of_vcalendars do
return nil
end
+ local fmt_date_jumble_loc = "%b %d %Y"
+ local fmt_date_iso8601_loc = "%F"
+ local fmt_date_time_jumble_loc = "%b %d %Y AT %H:%M"
+ local fmt_date_time_iso8601_loc = "%F AT %H:%M"
+
+ local fmt_date_jumble_utc = "!%b %d %Y"
+ local fmt_date_iso8601_utc = "!%F"
+ local fmt_date_time_jumble_utc = "!%b %d %Y AT %H:%M"
+ local fmt_date_time_iso8601_utc = "!%F AT %H:%M"
+
+ local fmt_date_loc = iso8601dates and fmt_date_iso8601_loc or fmt_date_jumble_loc
+ local fmt_date_utc = iso8601dates and fmt_date_iso8601_utc or fmt_date_jumble_utc
+ local fmt_date_time_loc = iso8601dates and fmt_date_time_iso8601_loc or fmt_date_time_jumble_loc
+ local fmt_date_time_utc = iso8601dates and fmt_date_time_iso8601_utc or fmt_date_time_jumble_utc
+
local rem_date_time = function (d, loctime)
if loctime == true then
- return osdate ("%b %d %Y AT %H:%M", d)
+ return osdate (fmt_date_time_loc, d)
end
- return osdate ("!%b %d %Y AT %H:%M", d)
+ return osdate (fmt_date_time_utc, d)
end
local rem_date = function (d, loctime)
if loctime == true then
- return osdate ("%b %d %Y", d)
+ return osdate (fmt_date_loc, d)
end
- return osdate ("!%b %d %Y", d)
+ return osdate (fmt_date_utc, d)
end
local rem_duration = function (dt)