diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2022-06-14 22:12:32 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2022-06-14 22:12:32 -0400 |
| commit | 5c86bab04fd4074810210c3dc3579eded2fc223c (patch) | |
| tree | c2d4dfbb66cb0c5d0c372d8412a9dfebe6531efa | |
| parent | ba8a2f4823470af4172e343081f689c9892c48df (diff) | |
Added "all day" or "24hrs" option
| -rwxr-xr-x | nowopen | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -89,7 +89,7 @@ local dsl = re.compile([=[ ({:from: {[a-zA-Z]+} :} ws? "-" ws? {:to: {[a-zA-Z]+} :} ws? ":") /({:from: {[a-zA-Z]+} :} ws? ":") /({:from:''->'sun':} {:to:''->'sat':}) - time_range <- {| {:open: time :} ws? "-" ws? {:close: time :} |} + time_range <- {| {:all_day: ("all day" / "24" ("hr"/"hour") "s"?):} / ({:open: time :} ws? "-" ws? {:close: time :}) |} time <- {| {:hour: {[0-9]+} :} (":" {:minute: {[0-9]+} :})? ws? {:ampm: { "am" / "pm"} :} / ("noon" {:hour: {~''->'12'~} :} {:ampm: {~''->'pm'~} :}) @@ -147,10 +147,14 @@ for i,place in ipairs(places) do end if today_times and today_times[1] then for _, window in ipairs(today_times) do - local until_open = t(window.open) - now - local until_close = t(window.close) - now - if until_close < until_open then - table.insert(options, {name=place.name, until_close=until_close}) + if window.all_day then + table.insert(options, {name=place.name, until_close=math.huge}) + else + local until_open = t(window.open) - now + local until_close = t(window.close) - now + if until_close < until_open then + table.insert(options, {name=place.name, until_close=until_close}) + end end end end @@ -187,8 +191,13 @@ else end local max_line = 0 for _,option in ipairs(options) do - local line = ("%s: %2s:%02d left"):format( - option.name, hours(option.until_close), mins(option.until_close)) + local line + if option.until_close >= math.huge then + line = ("%s: all day "):format(option.name) + else + line = ("%s: %2s:%02d left"):format( + option.name, hours(option.until_close), mins(option.until_close)) + end if not raw_print then local color if hours(option.until_close) >= 2 then |
