[feat] add separate duration format for total time
This commit is contained in:
parent
69a7dfd1fc
commit
d692453472
|
@ -80,23 +80,34 @@ file.")
|
|||
"Return the name of the currently clocked-in task, or nil if not clocked in."
|
||||
(chronometrist-sexp-current-task))
|
||||
|
||||
(cl-defun chronometrist-format-duration (seconds &optional (blank (make-string 3 ?\s)))
|
||||
"Format SECONDS as a string suitable for display in Chronometrist buffers.
|
||||
(defcustom chronometrist-duration-formats
|
||||
`((chronometrist "%h:%.2m:%z%.2s" ,(concat (make-string 7 ?\s) "-"))
|
||||
(chronometrist-total "%h:%.2m:%z%.2s" ,(concat (make-string 6 ?\s) "-"))
|
||||
(report "%m:%s" ,(make-string 3 ?\s)))
|
||||
"List specifying duration formats.
|
||||
Each element must be in the form
|
||||
|
||||
\(FIELD FORMAT-STRING [BLANK-STRING])
|
||||
|
||||
FIELD should be a symbol unique to this list.
|
||||
|
||||
FORMAT-STRING should be a string acceptable to `format-seconds'.
|
||||
|
||||
If the given duration is zero, BLANK-STRING is used instead.")
|
||||
|
||||
(defun chronometrist-format-duration (seconds &optional field)
|
||||
"Format SECONDS as a duration string.
|
||||
SECONDS must be a positive integer.
|
||||
|
||||
BLANK is a string to display in place of blank values. If not
|
||||
supplied, 3 spaces are used."
|
||||
(-let [(h m s) (chronometrist-seconds-to-hms seconds)]
|
||||
(if (and (zerop h) (zerop m) (zerop s))
|
||||
(concat (make-string 7 ?\s) "-")
|
||||
(let ((h (if (zerop h) blank (format "%2d:" h)))
|
||||
(m (cond ((and (zerop h) (zerop m)) blank)
|
||||
((zerop h) (format "%2d:" m))
|
||||
(t (format "%02d:" m))))
|
||||
(s (if (and (zerop h) (zerop m))
|
||||
(format "%2d" s)
|
||||
(format "%02d" s))))
|
||||
(concat h m s)))))
|
||||
The format is specified by `chronometrist-duration-formats'.
|
||||
FIELD, if supplied, must be a symbol used to identify entries in
|
||||
the same."
|
||||
(-let [(format-string blank-string)
|
||||
(alist-get (or field 'chronometrist)
|
||||
chronometrist-duration-formats)]
|
||||
(if (zerop seconds)
|
||||
blank-string
|
||||
(format-seconds format-string seconds))))
|
||||
|
||||
(defun chronometrist-common-file-empty-p (file)
|
||||
"Return t if FILE is empty."
|
||||
|
@ -1171,11 +1182,12 @@ is the name of the task to be clocked out of."
|
|||
(defun chronometrist-print-non-tabular ()
|
||||
"Print the non-tabular part of the buffer in `chronometrist'."
|
||||
(with-current-buffer chronometrist-buffer-name
|
||||
(let ((inhibit-read-only t) (w "\n "))
|
||||
(let ((inhibit-read-only t)
|
||||
(w "\n "))
|
||||
(goto-char (point-max))
|
||||
(--> (chronometrist-active-time-one-day)
|
||||
(chronometrist-format-duration it)
|
||||
(format "%s%- 26s%s" w "Total" it)
|
||||
(chronometrist-format-duration it 'chronometrist-total)
|
||||
(format "%s%- 29s%s" w "Total" it)
|
||||
(insert it)))))
|
||||
|
||||
(defun chronometrist-goto-nth-task (n)
|
||||
|
|
|
@ -429,6 +429,7 @@ file.")
|
|||
#+BEGIN_SRC emacs-lisp
|
||||
(defcustom chronometrist-duration-formats
|
||||
`((chronometrist "%h:%.2m:%z%.2s" ,(concat (make-string 7 ?\s) "-"))
|
||||
(chronometrist-total "%h:%.2m:%z%.2s" ,(concat (make-string 6 ?\s) "-"))
|
||||
(report "%m:%s" ,(make-string 3 ?\s)))
|
||||
"List specifying duration formats.
|
||||
Each element must be in the form
|
||||
|
@ -444,14 +445,16 @@ If the given duration is zero, BLANK-STRING is used instead.")
|
|||
#+END_SRC
|
||||
*** format-duration :function:
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defun chronometrist-format-duration (seconds)
|
||||
"Format SECONDS as a string suitable for display in Chronometrist buffers.
|
||||
(defun chronometrist-format-duration (seconds &optional field)
|
||||
"Format SECONDS as a duration string.
|
||||
SECONDS must be a positive integer.
|
||||
|
||||
BLANK is a string to display in place of blank values. If not
|
||||
supplied, 3 spaces are used."
|
||||
The format is specified by `chronometrist-duration-formats'.
|
||||
FIELD, if supplied, must be a symbol used to identify entries in
|
||||
the same."
|
||||
(-let [(format-string blank-string)
|
||||
(alist-get 'chronometrist chronometrist-duration-formats)]
|
||||
(alist-get (or field 'chronometrist)
|
||||
chronometrist-duration-formats)]
|
||||
(if (zerop seconds)
|
||||
blank-string
|
||||
(format-seconds format-string seconds))))
|
||||
|
@ -2231,11 +2234,12 @@ is the name of the task to be clocked out of."
|
|||
(defun chronometrist-print-non-tabular ()
|
||||
"Print the non-tabular part of the buffer in `chronometrist'."
|
||||
(with-current-buffer chronometrist-buffer-name
|
||||
(let ((inhibit-read-only t) (w "\n "))
|
||||
(let ((inhibit-read-only t)
|
||||
(w "\n "))
|
||||
(goto-char (point-max))
|
||||
(--> (chronometrist-active-time-one-day)
|
||||
(chronometrist-format-duration it)
|
||||
(format "%s%- 26s%s" w "Total" it)
|
||||
(chronometrist-format-duration it 'chronometrist-total)
|
||||
(format "%s%- 29s%s" w "Total" it)
|
||||
(insert it)))))
|
||||
#+END_SRC
|
||||
**** goto-nth-task :procedure:
|
||||
|
|
Reference in New Issue