From 339d5da1e7b378103606b06d5d23ee0b28cb7127 Mon Sep 17 00:00:00 2001 From: contrapunctus Date: Tue, 3 May 2022 10:43:50 +0530 Subject: [PATCH] Display durations using format-seconds --- cl/chronometrist.org | 54 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/cl/chronometrist.org b/cl/chronometrist.org index 70f7e9c..09552f0 100644 --- a/cl/chronometrist.org +++ b/cl/chronometrist.org @@ -822,8 +822,9 @@ treated as though their time is 00:00:00." :CUSTOM_ID: task-duration-one-day :END: #+BEGIN_SRC lisp -(defun task-duration-one-day (task &optional (date (timestamp-to-unix (today))) - (backend (active-backend))) +(defun task-duration-one-day (task &optional + (date (timestamp-to-unix (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))) @@ -3019,26 +3020,27 @@ s-expressions in a text column.") **** task-records-for-date :PROPERTIES: -:CUSTOM_ID: task-records-for-date-3 +:CUSTOM_ID: sqlite-task-records-for-date :END: #+BEGIN_SRC lisp (defmethod chronometrist:task-records-for-date ((backend sqlite-backend) task date &key &allow-other-keys) - (let ((list (execute-sxql #'execute-to-list - (select (:name :start_time :stop_time :properties) - (from :intervals) - (left-join :interval_names :using (:name_id)) - (left-join :properties :using (:prop_id)) - (where (:and - (:in :interval_id - (select (:interval_id) - (from :date_intervals) - (where (:= :date_id - (select (:date_id) - (from :dates) - (where (:= :date date))))))) - (:= :name task)))) - (backend-connection backend)))) + (let ((list (execute-sxql + #'execute-to-list + (select (:name :start_time :stop_time :properties) + (from :intervals) + (left-join :interval_names :using (:name_id)) + (left-join :properties :using (:prop_id)) + (where (:and + (:in :interval_id + (select (:interval_id) + (from :date_intervals) + (where (:= :date_id + (select (:date_id) + (from :dates) + (where (:= :date date))))))) + (:= :name task)))) + (backend-connection backend)))) (loop for (name start stop prop-string) in list collect (make-interval name start stop prop-string)))) #+END_SRC @@ -3091,11 +3093,21 @@ s-expressions in a text column.") (defpackage :chronometrist.clim (:use :clim :clim-lisp) (:import-from :local-time :now :today :timestamp-to-unix) + (:import-from :format-seconds :format-seconds) (:import-from :chronometrist :task-list :task-duration-one-day) (:export :run-chronometrist)) (in-package :chronometrist.clim) #+END_SRC +**** *duration-format-string* :variable: +:PROPERTIES: +:CUSTOM_ID: duration-format-string +:END: +#+BEGIN_SRC lisp +(defvar *duration-format-string* "~2h:~2,'0m:~2,'0s" + "Format string used for durations, acceptable to `format-seconds'.") +#+END_SRC + **** chronometrist :application:frame: :PROPERTIES: :CUSTOM_ID: chronometrist-1 @@ -3195,12 +3207,14 @@ FRAME and PANE are the CLIM frame and pane as passed to the display function.")) duration frame pane) (with-output-as-presentation (pane duration 'number) - (format t "~A" duration))) + (if (zerop duration) + (format t "~10@A" "-") + (format-seconds t *duration-format-string* duration)))) #+END_SRC ***** *task-duration-table-spec* :custom:variable: :PROPERTIES: -:CUSTOM_ID: *task-duration-table-spec* +:CUSTOM_ID: task-duration-table-spec :END: #+BEGIN_SRC lisp (defvar *task-duration-table-spec*