[feat] (WIP) use format-seconds; make duration formats customizable
This commit is contained in:
parent
524ba9592f
commit
69a7dfd1fc
|
@ -1072,7 +1072,10 @@ Return the value returned by Fₙ."
|
|||
arg))
|
||||
|
||||
(defcustom chronometrist-schema
|
||||
'[("#" 3 t) ("Task" 25 t) ("Time" 10 t) ("Active" 10 t)]
|
||||
'[("#" 3 t)
|
||||
("Task" 25 t)
|
||||
("Time" 10 t :right-align t)
|
||||
("Active" 10 t :right-align t)]
|
||||
"Vector specifying schema of `chronometrist' buffer.
|
||||
See `tabulated-list-format'."
|
||||
:type '(vector))
|
||||
|
|
|
@ -425,25 +425,36 @@ file.")
|
|||
"Return the name of the currently clocked-in task, or nil if not clocked in."
|
||||
(chronometrist-sexp-current-task))
|
||||
#+END_SRC
|
||||
*** format-time :function:
|
||||
*** duration-formats :function:
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(cl-defun chronometrist-format-duration (seconds &optional (blank (make-string 3 ?\s)))
|
||||
(defcustom chronometrist-duration-formats
|
||||
`((chronometrist "%h:%.2m:%z%.2s" ,(concat (make-string 7 ?\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.")
|
||||
|
||||
#+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.
|
||||
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)))))
|
||||
(-let [(format-string blank-string)
|
||||
(alist-get 'chronometrist chronometrist-duration-formats)]
|
||||
(if (zerop seconds)
|
||||
blank-string
|
||||
(format-seconds format-string seconds))))
|
||||
#+END_SRC
|
||||
*** file-empty-p :reader:
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
|
@ -2097,7 +2108,10 @@ Return the value returned by Fₙ."
|
|||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(defcustom chronometrist-schema
|
||||
'[("#" 3 t) ("Task" 25 t) ("Time" 10 t) ("Active" 10 t)]
|
||||
'[("#" 3 t)
|
||||
("Task" 25 t)
|
||||
("Time" 10 t :right-align t)
|
||||
("Active" 10 t :right-align t)]
|
||||
"Vector specifying schema of `chronometrist' buffer.
|
||||
See `tabulated-list-format'."
|
||||
:type '(vector))
|
||||
|
|
Reference in New Issue