fix(spark/task-durations-month): pad with nils if not ending on Saturday

This commit is contained in:
contrapunctus 2021-06-24 19:16:55 +05:30
parent 8f664fd4e2
commit 2480d26f91
2 changed files with 18 additions and 8 deletions

View File

@ -112,18 +112,23 @@ SCHEMA should be a vector as specified by `tabulated-list-format'."
while (not (ts> current stop-ts))
collect
(cl-loop
with row
with row with complete-p
;; pad with nils if not starting from Sunday
initially ;; could be moved to the outer loop? 🤔
(when (and (ts= current start-ts)
(not (zerop start-dow)))
(setq row (make-list start-dow nil)))
for day from (ts-dow current) to 6
while (and (not complete-p) (ts<= current stop-ts))
;; do (message (ts-format "%a, %d %h %Y" current))
collect (chronometrist-task-time-one-day task current) into row
do (setq current (ts-adjust 'day 1 current))
do (setq current (ts-adjust 'day 1 current)
complete-p (zerop (ts-dow current)))
;; finally (message "row - %S" row)
finally return row))))
;; pad with nils if not ending on Saturday
finally return
(if (and (< stop-dow 6) (< (length row) 7))
(append row (make-list (- 6 stop-dow) nil))
row)))))
(provide 'chronometrist-spark)
;;; chronometrist-spark.el ends here

View File

@ -176,18 +176,23 @@ SCHEMA should be a vector as specified by `tabulated-list-format'."
while (not (ts> current stop-ts))
collect
(cl-loop
with row
with row with complete-p
;; pad with nils if not starting from Sunday
initially ;; could be moved to the outer loop? 🤔
(when (and (ts= current start-ts)
(not (zerop start-dow)))
(setq row (make-list start-dow nil)))
for day from (ts-dow current) to 6
while (and (not complete-p) (ts<= current stop-ts))
;; do (message (ts-format "%a, %d %h %Y" current))
collect (chronometrist-task-time-one-day task current) into row
do (setq current (ts-adjust 'day 1 current))
do (setq current (ts-adjust 'day 1 current)
complete-p (zerop (ts-dow current)))
;; finally (message "row - %S" row)
finally return row))))
;; pad with nils if not ending on Saturday
finally return
(if (and (< stop-dow 6) (< (length row) 7))
(append row (make-list (- 6 stop-dow) nil))
row)))))
#+END_SRC
**** tests
#+BEGIN_SRC emacs-lisp :tangle chronometrist-spark-tests.el :load test