]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable setting timeclock-workday after switching mode on
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 27 Aug 2021 01:10:46 +0000 (03:10 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 27 Aug 2021 01:10:46 +0000 (03:10 +0200)
* lisp/calendar/timeclock.el (timeclock--previous-workday): New
variable.
(timeclock-find-discrep): Use it to flush values when
timeclock-workday changes (bug#50216).
(timeclock-mode-line-display): Mention `timeclock-workday' setting
in doc string.

lisp/calendar/timeclock.el

index 1aea1b5e63c9b68fd2310ef5e5079181ce9a7c4f..0b94bcb77fe7fdaa8350f1b25b01b565ff2d4300 100644 (file)
@@ -88,6 +88,8 @@
   "The length of a work period in seconds."
   :type 'integer)
 
+(defvar timeclock--previous-workday nil)
+
 (defcustom timeclock-relative t
   "Whether to make reported time relative to `timeclock-workday'.
 For example, if the length of a normal workday is eight hours, and you
@@ -269,7 +271,10 @@ will be updated whenever the time display is updated.  Otherwise,
 the timeclock will use its own sixty second timer to do its
 updating.  With prefix ARG, turn mode line display on if and only
 if ARG is positive.  Returns the new status of timeclock mode line
-display (non-nil means on)."
+display (non-nil means on).
+
+If using a customized `timeclock-workday' value, this should be
+set before switching this mode on."
   :global t
   ;; cf display-time-mode.
   (setq timeclock-mode-string "")
@@ -1058,7 +1063,9 @@ discrepancy, today's discrepancy, and the time worked today."
         (first t) (accum 0) (elapsed 0)
         event beg last-date
         last-date-limited last-date-seconds)
-    (unless timeclock-discrepancy
+    (when (or (not timeclock-discrepancy)
+              ;; The length of the workday has changed, so recompute.
+              (not (equal timeclock-workday timeclock--previous-workday)))
       (when (file-readable-p timeclock-file)
        (setq timeclock-project-list nil
              timeclock-last-project nil
@@ -1114,7 +1121,8 @@ discrepancy, today's discrepancy, and the time worked today."
                      last-date-seconds
                    timeclock-workday))
            (forward-line))
-         (setq timeclock-discrepancy accum))))
+         (setq timeclock-discrepancy accum
+                timeclock--previous-workday timeclock-workday))))
     (unless timeclock-last-event-workday
       (setq timeclock-last-event-workday timeclock-workday))
     (setq accum (or timeclock-discrepancy 0)