fix: create events-add-helper, complete events-add

This commit is contained in:
contrapunctus 2021-06-17 05:26:22 +05:30
parent 9cd742d3a0
commit e89a79f096
1 changed files with 19 additions and 14 deletions

View File

@ -1643,25 +1643,30 @@ If REPLACE is non-nil, replace the last event with PLIST."
(puthash date it chronometrist-events))))
#+END_SRC
#+BEGIN_SRC emacs-lisp :tangle no :load no
(defun chronometrist-events-add-helper (key plist table)
"Append PLIST to values for KEY in TABLE."
(--> (append (gethash key table) (list plist))
(puthash key it table)))
#+END_SRC
#+BEGIN_SRC emacs-lisp :tangle no :load no
(cl-defun chronometrist-events-add (plist &optional (table chronometrist-events))
"Add PLIST to the end of TABLE."
(-let* ((start-ts (chronometrist-iso-timestamp-to-ts (plist-get plist :start)))
(start-date (ts-format "%F" start-ts))
(split (chronometrist-events-maybe-split plist))
"Add PLIST to the end of TABLE, splitting it if necessary."
(-let* ((start-ts (chronometrist-iso-timestamp-to-ts
(plist-get plist :start)))
(start-date (ts-format "%F" start-ts))
(start-date-events (gethash start-date table))
(split (chronometrist-events-maybe-split plist))
((split-1 split-2) split)
(((&plist :start old-start :stop old-stop)
(&plist :start new-start :stop new-stop)) split)
(new-start-date (when new-start
(chronometrist-iso-timestamp-to-ts new-start))))
(cond (split
(--> (gethash start-date table)
(append it (list split-1))
(puthash start-date it table))
(--> (gethash new-start-date table)
(append it (list split-2))
(puthash new-start-date it table)))
())))
(new-start-date (when new-start
(chronometrist-iso-timestamp-to-ts new-start))))
(if (null split)
(chronometrist-events-add-helper start-date plist table)
(chronometrist-events-add-helper start-date split-1 table)
(chronometrist-events-add-helper new-start-date split-2 table))))
#+END_SRC
*** last-date :reader: