From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kevin Brubeck Unhammer Subject: [PATCH] clocktable thinks Oct 29 is Oct 28 [9.1.14 (release_9.1.14-1012-g643481 @ /home/unhammer/src/org-mode/lisp/)] Date: Thu, 01 Nov 2018 16:18:27 +0100 Message-ID: <87efc4zv0c.fsf_-_@fsfe.org> References: <874ld25v0n.fsf@fsfe.org> <878t2e48ll.fsf@fsfe.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gIEk8-0002hk-6h for emacs-orgmode@gnu.org; Thu, 01 Nov 2018 11:18:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gIEk5-0000zh-0c for emacs-orgmode@gnu.org; Thu, 01 Nov 2018 11:18:44 -0400 Received: from [195.159.176.226] (port=56457 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gIEk4-0000xe-Kt for emacs-orgmode@gnu.org; Thu, 01 Nov 2018 11:18:40 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1gIEhr-0006fP-S9 for emacs-orgmode@gnu.org; Thu, 01 Nov 2018 16:16:23 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain The attached patch solves this, as far as I can tell. I have signed the FSF copyright papers. best regards, Kevin Brubeck Unhammer --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-clock-Handle-DST-in-clocktable.patch Content-Transfer-Encoding: quoted-printable From=20e818cd5d1c651a516a0e791a10d91fe1e310cde9 Mon Sep 17 00:00:00 2001 From: Kevin Brubeck Unhammer Date: Thu, 1 Nov 2018 13:59:09 +0100 Subject: [PATCH] org-clock: Handle DST in clocktable * lisp/org-clock.el (org-clocktable-steps): new fn org-clocktable-increment-day to add/subtract days that are not exactly 24 hours * testing/lisp/test-org-clock.el (test-org-clock/clocktable/step): Add test for DST. =2D-- lisp/org-clock.el | 27 +++++++++++++++++++-------- testing/lisp/test-org-clock.el | 21 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 420fdadfe..6292a259f 100644 =2D-- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2681,6 +2681,15 @@ LEVEL is an integer. Indent by two spaces per level= above 1." (if (=3D level 1) "" (concat "\\_" (make-string (* 2 (1- level)) ?\s)))) =20 +(defun org-clocktable-increment-day (ts &optional n) + "Increment day in TS by N (defaulting to 1). +The TS argument has the same type as the return values of +`float-time' or `current-time'." + (let ((tsd (decode-time ts))) + (cl-incf (nth 3 tsd) (or n 1)) + (setf (nth 8 tsd) nil) ; no time zone: increasing day skips one whole = day + (apply 'encode-time tsd))) + (defun org-clocktable-steps (params) "Step through the range to make a number of clock tables." (let* ((ts (plist-get params :tstart)) @@ -2688,7 +2697,6 @@ LEVEL is an integer. Indent by two spaces per level = above 1." (ws (plist-get params :wstart)) (ms (plist-get params :mstart)) (step0 (plist-get params :step)) =2D (step (cdr (assq step0 '((day . 86400) (week . 604800))))) (stepskip0 (plist-get params :stepskip0)) (block (plist-get params :block)) cc tsb) @@ -2715,16 +2723,19 @@ LEVEL is an integer. Indent by two spaces per leve= l above 1." (if (eq step0 'week) (let ((dow (nth 6 (decode-time (seconds-to-time ts))))) (if (<=3D dow ws) ts =2D (- ts (* 86400 (- dow ws))))) + (org-clocktable-increment-day ts ; decrement + (- ws dow)))) ts)) (while (< tsb te) (unless (bolp) (insert "\n")) =2D (let ((start-time (seconds-to-time (max tsb ts)))) =2D (cl-incf tsb (let ((dow (nth 6 (decode-time (seconds-to-time tsb))))) =2D (if (or (eq step0 'day) =2D (=3D dow ws)) =2D step =2D (* 86400 (- ws dow))))) + (let* ((start-time (seconds-to-time (max tsb ts))) + (dow (nth 6 (decode-time (seconds-to-time tsb)))) + (days-to-skip (cond ((eq step0 'day) 1) + ;; else 'week: + ((=3D dow ws) 7) + (t (- ws dow))))) + (setq tsb (time-to-seconds (org-clocktable-increment-day tsb + days-to-skip))) (insert "\n" (if (eq step0 'day) "Daily report: " "Weekly report starting on: ") diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index abb3637bd..ddc135669 100644 =2D-- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -977,7 +977,26 @@ CLOCK: [2017-12-27 Wed 08:00]--[2017-12-27 Wed 16:00] = =3D> 8:00" (let ((system-time-locale "en_US")) (test-org-clock-clocktable-contents (concat ":step day :tstart \"<2017-12-25 Mon>\" " =2D ":tend \"<2017-12-27 Wed 23:59>\" :stepskip0 t"))))))) + ":tend \"<2017-12-27 Wed 23:59>\" :stepskip0 t")))))) + ;; Regression test: Respect DST + (should + (equal " +Daily report: [2018-10-29 Mon] +| Headline | Time | +|--------------+--------| +| *Total time* | *8:00* | +|--------------+--------| +| Foo | 8:00 | +" + (org-test-with-temp-text + "* Foo +CLOCK: [2018-10-29 Mon 08:00]--[2018-10-29 Mon 16:00] =3D> 8:00" + (let ((system-time-locale "en_US")) + (test-org-clock-clocktable-contents + (concat ":step day " + ":stepskip0 t " + ":tstart \"2018-10-01\" " + ":tend \"2018-11-01\""))))))) =20 (ert-deftest test-org-clock/clocktable/extend-today-until () "Test assignment of clock time to days in presence of \"org-extend-today= -until\"." =2D-=20 2.17.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEq9A0PxCu5rIo7lbX/DwefQCTFmcFAlvbGUMACgkQ/DwefQCT FmeINA/6A2zfJeaqTrfe/XfJricilZPXe356+Y0C1rWyCHwBDu4jBLdcdizlefz5 GDC3eJNlX63b2FwUKUMu2+tzOhWvsZMK5IuHVxfJsLATsmf06SSRKnNGH4LdDPlx TxjSDf/SeNa2SEALNPEjbOHgS16RBtH89ezuSFkFfhftFSXEdaoTcLt1HHT9zJKt hhn4A8WHO5TIB7go5t3XVaRls2sgTxoHx1BrlVU8cZd4r1IHW+beTWCY2v9NtV1n mkLaAc2tCK25TvBbt6bC+Wmq729aV7xFs+i+Nr0Nf20C1DR3Bllxj5v3KmDAD5L8 Kb5orV/Pp27CMX+DyNz80Db4JbkfN4viFckqB5KqKVwm8e9PDXWDh5nFt05m2YjZ agxU5EqiMIy6CInpOkMnPH8sEEKJcTRbOeOGa5LN0oRT/fQ8xrWq/zXdkNIsSPSk b8gh7y3vaMGuj8SIqvUEFjCNxtnzrw4Cxir22tP/myNQlCs6MzdaWH7dlLnLRz3q ohhaKZecEv4FoCGid51ojNRd09RT4GnSmOVj30bS4G/B179ttw80Nn7m6er0hrzV T3yt3rHrrMeCFGXP19IQ6glcL3gFTT6F6/ChwOukIJsn3B1sAjTD5x0aWvqcn/tY gpqDDUfPjxwxZYSrWzE4piBoLRMkBg0RU1QkCSVLwhOZHHqqnN0= =xcKF -----END PGP SIGNATURE----- --==-=-=--