Make task-time-one-day work with interval objects
This commit is contained in:
parent
3f8253daa4
commit
e57f88a935
|
@ -400,7 +400,7 @@ Use =org-babel= (=org-babel-tangle= / =org-babel-tangle-file=), /not/ =literate-
|
|||
:xdg-config-home :xdg-data-home
|
||||
:strcat :split-string)
|
||||
(:import-from :local-time
|
||||
:parse-timestring :now :adjust-timestamp
|
||||
:parse-timestring :now :timestamp-to-unix :adjust-timestamp
|
||||
:timestamp< :format-timestring)
|
||||
(:export
|
||||
;; customizable variables
|
||||
|
@ -432,6 +432,7 @@ Use =org-babel= (=org-babel-tangle= / =org-babel-tangle-file=), /not/ =literate-
|
|||
:latest-record :task-records-for-date :latest-date-records
|
||||
;; helpers
|
||||
:make-hash-table-1 :split-plist :iso-to-date :plist-key-values
|
||||
:task-time-one-day
|
||||
;; debugging
|
||||
:*debug-enable*
|
||||
:*debug-buffer*))
|
||||
|
@ -645,7 +646,7 @@ If REPLACE is non-nil, replace the last interval with PLIST."
|
|||
|
||||
*** ht-last :reader:
|
||||
#+BEGIN_SRC lisp
|
||||
(defun ht-last (&optional (backend (chronometrist-active-backend)))
|
||||
(defun ht-last (&optional (backend (chronometrist:active-backend)))
|
||||
"Return the last plist from `chronometrist-events'."
|
||||
(let* ((hash-table (chronometrist-backend-hash-table backend))
|
||||
(last-date (ht-last-date hash-table)))
|
||||
|
@ -679,16 +680,12 @@ treated as though their time is 00:00:00."
|
|||
|
||||
*** task-time-one-day :reader:
|
||||
#+BEGIN_SRC lisp
|
||||
(defun task-time-one-day (task &optional
|
||||
(date (today))
|
||||
(backend (chronometrist-active-backend)))
|
||||
(defun task-time-one-day (task &optional (date (today)) (backend (active-backend)))
|
||||
"Return total time spent on TASK today or on DATE.
|
||||
The return value is seconds, as an integer."
|
||||
(let ((task-intervals (task-records-for-date backend task date)))
|
||||
(if task-intervals
|
||||
(->> (plists-to-durations task-intervals)
|
||||
(-reduce #'+)
|
||||
(truncate))
|
||||
(reduce #'+ (mapcar #'interval-to-duration task-intervals))
|
||||
;; no events for this task on DATE, i.e. no time spent
|
||||
0)))
|
||||
#+END_SRC
|
||||
|
@ -733,15 +730,6 @@ active backend.")
|
|||
#+END_SRC
|
||||
|
||||
** Time functions
|
||||
*** plists-to-durations :function:
|
||||
#+BEGIN_SRC lisp
|
||||
(defun plists-to-durations (plists)
|
||||
"Convert PLISTS into a list of durations in seconds.
|
||||
PLISTS must be a list of valid Chronometrist property lists (see
|
||||
`*user-data-file*'). Return 0 if PLISTS is nil."
|
||||
(if plists (mapcar #'interval plists) 0))
|
||||
#+END_SRC
|
||||
|
||||
*** date-iso :function:
|
||||
#+BEGIN_SRC lisp
|
||||
(defun date-iso (&optional (ts (ts-now)))
|
||||
|
@ -1004,6 +992,14 @@ return a list of tasks from the active backend."
|
|||
(read-from-string properties-string))))
|
||||
#+END_SRC
|
||||
|
||||
***** interval-to-duration :function:
|
||||
#+BEGIN_SRC lisp
|
||||
(defun interval-to-duration (interval)
|
||||
(with-slots (start stop) interval
|
||||
(let ((stop (or stop (timestamp-to-unix (now)))))
|
||||
(- stop start))))
|
||||
#+END_SRC
|
||||
|
||||
**** event :class:
|
||||
#+BEGIN_SRC lisp
|
||||
(defclass event ()
|
||||
|
|
Reference in New Issue