From 3a6a227158507d2f6500488f1f87eac8a6d47463 Mon Sep 17 00:00:00 2001 From: "Toby S. Cubitt" Date: Mon, 12 Nov 2012 11:45:47 +0000 Subject: [PATCH 2/2] Optionally allow months and years to be used in clocksum format --- lisp/org.el | 98 ++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 57 insertions(+), 41 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 3ae1892..fd05104 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2722,29 +2722,25 @@ The value can be a single format string containing two %-sequences, which will be filled with the number of hours and minutes in that order. -Alternatively, the value can be a list of up to three format +Alternatively, the value can be a list of up to five format strings. In this case, the first format string in the list is used for the number of minutes, the second for the number of -hours, and the third for the number of days if the duration is -longer than 1 day. The complete formatted duration is obtained by -concatenating these in the order: days, minutes, hours. - -If the list contains fewer than three format strings, it -restricts the largest time unit in the formatted duration to be -the largest one in the list. A two-element list means the -duration will always be expressed in hours and minutes, a -one-element list means the duration will always be expressed in -minutes." +hours, the third for the number of days if the duration is longer +than 1 day, the fourth for the number of months if the duration +is longer than 1 month (a month is taken to be 30 days here), the +fifth for the number of years if the duration is longer than 1 +year (a year is taken to be 365 days here). The complete +formatted duration is obtained by concatenating these in the +order: years, months, days, hours, minutes. + +If the list contains fewer than five elements, the largest time +unit in the formatted duration is restricted to the largest time +unit in the list. E.g. a two-element list means the duration will +always be expressed in hours and minutes, a one-element list +means the duration will always be expressed in minutes." :group 'org-time - :type '(choice (string :tag "single format") - (group :tag "mins" (string :tag "minutes format")) - (group :tag "mins,hrs" - (string :tag "minutes format") - (string :tag "hours format")) - (group :tag "mins,hrs,days" - (string :tag "minutes format") - (string :tag "hours format") - (string :tag "days format")))) + :type '(choice (string :tag "format string") + (repeat :tag "list" (string :tag "format string")))) (defcustom org-time-clocksum-use-fractional nil "If non-nil, \\[org-clock-display] uses fractional times. @@ -16695,31 +16691,51 @@ If there is already a time stamp at the cursor position, update it." (defun org-minutes-to-clocksum-string (m) "Compute H:MM from a number of minutes." - (let* ((d (/ m 1400)) (h (/ (- m (* 1400 d)) 60))) - (setq m (- m (* 1400 d) (* 60 h))) + (let ((h (/ m 60)) d M Y) + (setq m (- m (* 60 h))) (if org-time-clocksum-use-fractional (format org-time-clocksum-fractional-format - (/ (+ (* 60.0 (+ (* 1400 d) h)) m) 60.0)) + (/ (+ (* 60.0 h) m) 60.0)) (cond + ;; single hh:mm format ((stringp org-time-clocksum-format) - (format org-time-clocksum-format (+ (* 1400 d) h) m)) - ((> d 0) - (if (>= (length org-time-clocksum-format) 3) - (concat (format (nth 2 org-time-clocksum-format) d) - (format (nth 1 org-time-clocksum-format) h) - (format (nth 0 org-time-clocksum-format) m)) - (if (>= (length org-time-clocksum-format) 2) - (concat (format (nth 1 org-time-clocksum-format) - (+ (* 1400 d) h) m) - (format (nth 0 org-time-clocksum-format) m)) - (format (nth 0 org-time-clocksum-format) - (+ (* 60 (+ (* 1400 d) h)) m))))) - (t (if (>= (length org-time-clocksum-format) 2) - (concat (format (nth 1 org-time-clocksum-format) - (+ (* 1400 d) h) m) - (format (nth 0 org-time-clocksum-format) m)) - (format (nth 0 org-time-clocksum-format) - (+ (* 60 (+ (* 1400 d) h)) m)))))))) + (format org-time-clocksum-format h m)) + ;; years + ((and (>= (length org-time-clocksum-format) 5) + (> (/ h 8760) 0)) + (setq Y (/ h 8760) h (- h (* 8760 Y)) + M (/ h 720) h (- h (* 720 M)) + d (/ h 24) h (- h (* 24 d))) + (concat (format (nth 4 org-time-clocksum-format) Y) + (format (nth 3 org-time-clocksum-format) M) + (format (nth 2 org-time-clocksum-format) d) + (format (nth 1 org-time-clocksum-format) h) + (format (nth 0 org-time-clocksum-format) m))) + ;; months + ((and (>= (length org-time-clocksum-format) 4) + (> (/ h 720) 0)) + (setq M (/ h 720) h (- h (* 720 M)) + d (/ h 24) h (- h (* 24 d))) + (concat (format (nth 3 org-time-clocksum-format) M) + (format (nth 2 org-time-clocksum-format) d) + (format (nth 1 org-time-clocksum-format) h) + (format (nth 0 org-time-clocksum-format) m))) + ;; days + ((and (>= (length org-time-clocksum-format) 3) + (> (/ h 24) 0)) + (setq d (/ h 24) h (- h (* 24 d))) + (concat (format (nth 2 org-time-clocksum-format) d) + (format (nth 1 org-time-clocksum-format) h) + (format (nth 0 org-time-clocksum-format) m))) + ;; hours + ((>= (length org-time-clocksum-format) 2) + (concat (format (nth 1 org-time-clocksum-format) h) + (format (nth 0 org-time-clocksum-format) m))) + ;; minutes + ((>= (length org-time-clocksum-format) 1) + (setq m (+ m (* 60 h))) + (format (nth 0 org-time-clocksum-format) m)) + (t ""))))) (defalias 'org-minutes-to-hh:mm-string 'org-minutes-to-clocksum-string) (make-obsolete 'org-minutes-to-hh:mm-string 'org-minutes-to-clocksum-string -- 1.7.8.6