From 1931e88c85aa80832e468cd807b5f849ab4c6a3a Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Sat, 3 Jul 2021 00:23:56 +0530 Subject: [PATCH] feat(details): support begin/end in ranges --- TODO.org | 6 ++++-- elisp/chronometrist.el | 29 +++++++++++++++++++++-------- elisp/chronometrist.org | 29 +++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/TODO.org b/TODO.org index b959777..c8d9f8d 100644 --- a/TODO.org +++ b/TODO.org @@ -610,16 +610,18 @@ list of tasks, one day, durations and graphs list of tasks, one week, durations only *** statistics list of tasks, one week/month/year [fn:1] -*** details (intervals for a day) [0%] +*** details (intervals for a day) [25%] list of intervals, one day [fn:1] + [-] commands [50%] 1. [X] set [task/key-value] filter [fn:2] 2. [X] set range + 1. implement timestamp ranges (e.g. =2021-06-01T12:00+05:30= to =2021-07-03T00:10:29+0530=) 3. [ ] previous/next day 4. [ ] set duration format + [ ] with =spark= - vertical sparkline for each interval + [ ] non-tabular text [fn:3] -+ [ ] when range is a pair with the =car= or the =cdr= being blank, set the respective date to the earliest (if =car= is blank) or the latest (if =cdr= is blank) date available. ++ [X] when range is a pair with the =car= or the =cdr= being blank, set the start/stop date to the earliest/latest date available. + * not possible with =completing-read-multiple=, which removes blank strings; the simplest solution was to allow "begin"/"end" as inputs. ** New frontends I want *** task-key-values diff --git a/elisp/chronometrist.el b/elisp/chronometrist.el index 67fd178..b6c8d58 100644 --- a/elisp/chronometrist.el +++ b/elisp/chronometrist.el @@ -2161,20 +2161,33 @@ TABLE must be a hash table similar to `chronometrist-events'." (let ((input (completing-read-multiple (concat "Range (blank, ISO-8601 date, " "or two ISO-8601 dates/timestamps): ") - (reverse (hash-table-keys chronometrist-events)) nil nil - (pcase chronometrist-details-range - ('nil nil) - ((pred stringp) - (format "%s" chronometrist-details-range)) - (`(,begin . ,end) - (format "%s,%s" begin end))) + (append '("begin" "end") + (reverse (hash-table-keys chronometrist-events))) + nil nil (pcase chronometrist-details-range + ('nil nil) + ((pred stringp) + (format "%s" chronometrist-details-range)) + (`(,begin . ,end) + (format "%s,%s" begin end))) 'chronometrist-details-range-history))) (pcase input ('nil (setq-local chronometrist-details-range nil)) (`(,date) (setq-local chronometrist-details-range date)) (`(,begin ,end) - (setq-local chronometrist-details-range (cons begin end))) + (let* ((date-p (seq-find #'chronometrist-iso-date-p input)) + (begin-date (car (hash-table-keys chronometrist-events))) + (begin-iso-ts (ts-format + "%FT%T%z" (chronometrist-iso-date-to-ts begin-date))) + (end-date (car (last (hash-table-keys chronometrist-events)))) + (end-iso-ts (chronometrist-format-time-iso8601)) + (begin (if (equal begin "begin") + (if date-p begin-date begin-iso-ts) + begin)) + (end (if (equal end "end") + (if date-p end-date end-iso-ts) + end))) + (setq-local chronometrist-details-range (cons begin end)))) (_ (error "Unsupported range."))) (tabulated-list-revert))) diff --git a/elisp/chronometrist.org b/elisp/chronometrist.org index 3e8932e..c4c7ca8 100644 --- a/elisp/chronometrist.org +++ b/elisp/chronometrist.org @@ -3416,20 +3416,33 @@ TABLE must be a hash table similar to `chronometrist-events'." (let ((input (completing-read-multiple (concat "Range (blank, ISO-8601 date, " "or two ISO-8601 dates/timestamps): ") - (reverse (hash-table-keys chronometrist-events)) nil nil - (pcase chronometrist-details-range - ('nil nil) - ((pred stringp) - (format "%s" chronometrist-details-range)) - (`(,begin . ,end) - (format "%s,%s" begin end))) + (append '("begin" "end") + (reverse (hash-table-keys chronometrist-events))) + nil nil (pcase chronometrist-details-range + ('nil nil) + ((pred stringp) + (format "%s" chronometrist-details-range)) + (`(,begin . ,end) + (format "%s,%s" begin end))) 'chronometrist-details-range-history))) (pcase input ('nil (setq-local chronometrist-details-range nil)) (`(,date) (setq-local chronometrist-details-range date)) (`(,begin ,end) - (setq-local chronometrist-details-range (cons begin end))) + (let* ((date-p (seq-find #'chronometrist-iso-date-p input)) + (begin-date (car (hash-table-keys chronometrist-events))) + (begin-iso-ts (ts-format + "%FT%T%z" (chronometrist-iso-date-to-ts begin-date))) + (end-date (car (last (hash-table-keys chronometrist-events)))) + (end-iso-ts (chronometrist-format-time-iso8601)) + (begin (if (equal begin "begin") + (if date-p begin-date begin-iso-ts) + begin)) + (end (if (equal end "end") + (if date-p end-date end-iso-ts) + end))) + (setq-local chronometrist-details-range (cons begin end)))) (_ (error "Unsupported range."))) (tabulated-list-revert)))