From 76a4936f065ef0f84ff61c74c8f5c800ca019011 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 6 Jul 2018 15:03:42 +0200 Subject: rem: distinguish between dates with day and minute granularity --- rem.lua | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/rem.lua b/rem.lua index 3dd1aeb..a696f83 100644 --- a/rem.lua +++ b/rem.lua @@ -169,7 +169,7 @@ local rem_of_vcalendars do return nil end - local rem_date = function (d, loctime) + local rem_date_time = function (d, loctime) if loctime == true then return osdate ("%b %d %Y AT %H:%M", d) end @@ -177,6 +177,14 @@ local rem_of_vcalendars do return osdate ("!%b %d %Y AT %H:%M", d) end + local rem_date = function (d, loctime) + if loctime == true then + return osdate ("%b %d %Y", d) + end + + return osdate ("!%b %d %Y", d) + end + local rem_duration = function (dt) --[[-- remind(1): Note that duration is specified in hours and minutes. --]]-- @@ -196,27 +204,28 @@ local rem_of_vcalendars do return stringformat ("%0.2d:%s", dt, ret) end - local repeat_of_duration = function (te) + local repeat_of_duration = function (t0, te) + local from = rem_date (t0) local till = rem_date (te) - return stringformat ("*1 UNTIL %s", till) + return stringformat ("%s *1 UNTIL %s", from, till) end local rem_date_duration = function (t0, te, loctime) local dt = te - t0 - local s_t0 = rem_date (t0, loctime) if dt == 0 or dt == time_f_day then - return s_t0 + --- no duration or exactly 1d β†’ no β€œat” clause + return rem_date (t0, loctime) end - if dt > time_f_day then --- needs repeat claus - local rep = repeat_of_duration (te) - - return stringformat ("%s %s", s_t0, rep) + if dt > time_f_day then + --- duration of multiple days β†’ needs repeat clause + return repeat_of_duration (t0, te) end + local s_t0 = rem_date_time (t0, loctime) local s_dt = rem_duration (dt) return stringformat ("%s DURATION %s", s_t0, s_dt) @@ -228,7 +237,7 @@ local rem_of_vcalendars do if t0 ~= nil then if te ~= nil then return rem_date_duration (t0, te, loctime) end - return rem_date (t0, loctime) + return rem_date_time (t0, loctime) end return nil -- cgit v1.2.3