Change timeclock to use 24-hour clock
Petteri Hintsanen <[email protected]>
| Newsgroups | gmane.emacs.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello list, In my day job I use timeclock for tracking working time, and it works great. However, timeclock uses 12-hour clock which I'm not accustomed to. Also, on my locale %p does not print anything with format-time-string. So I do not see AM/PM qualifiers in time stamps, e.g. after M-x timeclock-status-string. I tried to patch timeclock.el to honor display-time-24hr-format on its conversions. The problem is that display-time-24hr-format is part of time package, and it is not necessarily bound when timeclock outputs something. I guess I could (require 'time), but is there a cleaner solution? I wouldn't like to introduce another "please-use-24hr" flag. Patch attached. My apologies if this belongs to the bug tracker instead. Thanks, Petteri
timeclock-24hr.patch
(text/x-diff, 2.2 KB)
diff --git a/lisp/calendar/timeclock.el b/lisp/calendar/timeclock.el
index acdf99f77ae..6a0403a1e48 100644
--- a/lisp/calendar/timeclock.el
+++ b/lisp/calendar/timeclock.el
@@ -411,11 +411,8 @@ timeclock-status-string
(status
(format "Currently %s since %s (%s), %s %s, leave at %s"
(if last-in "IN" "OUT")
- (if show-seconds
- (format-time-string "%-I:%M:%S %p"
- (nth 1 timeclock-last-event))
- (format-time-string "%-I:%M %p"
- (nth 1 timeclock-last-event)))
+ (format-time-string (timeclock-time-format show-seconds)
+ (nth 1 timeclock-last-event))
(or (nth 2 timeclock-last-event)
(if last-in "**UNKNOWN**" "workday over"))
(timeclock-seconds-to-string remainder show-seconds t)
@@ -539,10 +536,8 @@ timeclock-when-to-leave-string
;; Should today-only be removed in favor of timeclock-relative? - gm
(interactive)
(let* ((then (timeclock-when-to-leave today-only))
- (string
- (if show-seconds
- (format-time-string "%-I:%M:%S %p" then)
- (format-time-string "%-I:%M %p" then))))
+ (string (format-time-string (timeclock-time-format show-seconds)
+ then)))
(if (called-interactively-p 'interactive)
(message "%s" string)
string)))
@@ -1171,7 +1166,9 @@ timeclock-generate-report
(setq done t))
(insert "OUT")))
(unless done
- (insert " since " (format-time-string "%Y/%m/%d %-I:%M %p" begin))
+ (insert " since " (format-time-string
+ (concat "%Y/%m/%d " (timeclock-time-format))
+ begin))
(if html-p
(insert "<br>\n<b>")
(insert "\n*"))
@@ -1322,6 +1319,17 @@ timeclock-visit-timelog
(interactive)
(find-file-other-window timeclock-file))
+(defun timeclock-time-format (&optional seconds)
+ "Return a format string for format-time-string.
+Use 24-hour clock if `display-time-24hr-format' is non-nil, otherwise
+use 12-hour clock.
+
+Include seconds field if SECONDS is non-nil."
+ (if (and (boundp display-time-24hr-format)
+ display-time-24hr-format)
+ (if seconds "%-H:%M:%S" "%-H:%M")
+ (if seconds "%-I:%M:%S %p" "%-I:%M %p")))
+
(provide 'timeclock)
(run-hooks 'timeclock-load-hook)