From mboxrd@z Thu Jan 1 00:00:00 1970 From: Georgiy Tugai Subject: [PATCH v2] org-clock: Fix clock report sometimes ignoring hours before :wstart Date: Sat, 7 Oct 2017 22:01:43 +1030 Message-ID: <20171007113143.GK5513@gmail.com> References: <20171004112628.GE5513@gmail.com> <87k209k68n.fsf@nicolasgoaziou.fr> <20171007024448.GH5513@gmail.com> <87bmljihi8.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="QqzFzR/RUlLahzby" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0nKi-0005GM-NI for emacs-orgmode@gnu.org; Sat, 07 Oct 2017 07:31:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0nKf-0005hQ-It for emacs-orgmode@gnu.org; Sat, 07 Oct 2017 07:31:52 -0400 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]:55250) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e0nKf-0005gN-9v for emacs-orgmode@gnu.org; Sat, 07 Oct 2017 07:31:49 -0400 Received: by mail-pf0-x22e.google.com with SMTP id m28so5772288pfi.11 for ; Sat, 07 Oct 2017 04:31:49 -0700 (PDT) Received: from gmail.com ([101.187.171.220]) by smtp.googlemail.com with ESMTPSA id n12sm190629pfb.149.2017.10.07.04.31.46 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 07 Oct 2017 04:31:47 -0700 (PDT) Content-Disposition: inline In-Reply-To: <87bmljihi8.fsf@nicolasgoaziou.fr> 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 --QqzFzR/RUlLahzby Content-Type: text/x-diff; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * lisp/org-clock (org-clocktable-steps): Fix weekly-step clock report ignoring hours between start of period and start of week, when start of period is on a day of week numerically less than start of week. Clock report now always inserts a "week" starting at the start of the period, if necessary; all following weeks start on the start of the week as expected. TINYCHANGE --- lisp/org-clock.el | 11 ++++- testing/lisp/test-org-clock.el | 99 ++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 9dc501500..d4d88144b 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2725,7 +2725,9 @@ LEVEL is an integer. Indent by two spaces per level = above 1." (setq te (float-time (apply #'encode-time (org-parse-time-string te)= ))))) (setq tsb (if (eq step0 'week) - (- ts (* 86400 (- (nth 6 (decode-time (seconds-to-time ts))) ws))) + (let ((dow (nth 6 (decode-time (seconds-to-time ts))))) + (if (< dow ws) ts + (- ts (* 86400 (- dow ws))))) ts)) (setq p1 (plist-put p1 :header "")) (setq p1 (plist-put p1 :step nil)) @@ -2735,9 +2737,14 @@ LEVEL is an integer. Indent by two spaces per level= above 1." (setq p1 (plist-put p1 :tstart (format-time-string (org-time-stamp-format nil t) (seconds-to-time (max tsb ts))))) + (setq tsb (+ tsb (let ((dow (nth 6 (decode-time (seconds-to-time tsb= ))))) + (if (or (eq step0 'day) + (=3D dow ws)) + step + (* 86400 (- ws dow)))))) (setq p1 (plist-put p1 :tend (format-time-string (org-time-stamp-format nil t) - (seconds-to-time (min te (setq tsb (+ tsb step))))))) + (seconds-to-time (min te tsb))))) (insert "\n" (if (eq step0 'day) "Daily report: " "Weekly report starting on: ") (plist-get p1 :tstart) "\n") diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index 30a69ea45..51ca1d458 100644 --- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -828,5 +828,104 @@ CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 11:09]= =3D> 0:00 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 13:09] =3D> 0:00" (test-org-clock-clocktable-contents ":tcolumns 2"))))) =20 +(ert-deftest test-org-clock/clocktable/step () + "Test \":step\" parameter in Clock table." + ;; Regression test: week crossing month boundary before :wstart + ;; day-of-week. + (should + (equal " +Weekly report starting on: [2017-09-25 Mon] +| Headline | Time | +|--------------+--------| +| *Total time* | *1:00* | +|--------------+--------| +| Foo | 1:00 |" + (org-test-with-temp-text + "* Foo +CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] =3D> 1:00 +CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] =3D> 2:00 +CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] =3D> 3:00" + (test-org-clock-clocktable-contents ":step week :block 2017-09 :step= skip0 t")))) + (should + (equal " +Weekly report starting on: [2017-10-01 Sun] +| Headline | Time | +|--------------+--------| +| *Total time* | *2:00* | +|--------------+--------| +| Foo | 2:00 | + +Weekly report starting on: [2017-10-02 Mon] +| Headline | Time | +|--------------+--------| +| *Total time* | *7:00* | +|--------------+--------| +| Foo | 7:00 | + +Weekly report starting on: [2017-10-09 Mon] +| Headline | Time | +|--------------+--------| +| *Total time* | *5:00* | +|--------------+--------| +| Foo | 5:00 | +" + (org-test-with-temp-text + "* Foo +CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] =3D> 1:00 +CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] =3D> 2:00 +CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] =3D> 3:00 +CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] =3D> 4:00 +CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] =3D> 5:00" + (test-org-clock-clocktable-contents ":step week :block 2017-10 :steps= kip0 t")))) + ;; :step day + (should + (equal " +Daily report: [2017-10-02 Mon] +| Headline | Time | +|--------------+--------| +| *Total time* | *3:00* | +|--------------+--------| +| Foo | 3:00 | + +Daily report: [2017-10-03 Tue] +| Headline | Time | +|--------------+--------| +| *Total time* | *0:00* | + +Daily report: [2017-10-04 Wed] +| Headline | Time | +|--------------+--------| +| *Total time* | *0:00* | + +Daily report: [2017-10-05 Thu] +| Headline | Time | +|--------------+--------| +| *Total time* | *0:00* | + +Daily report: [2017-10-06 Fri] +| Headline | Time | +|--------------+--------| +| *Total time* | *0:00* | + +Daily report: [2017-10-07 Sat] +| Headline | Time | +|--------------+--------| +| *Total time* | *0:00* | + +Daily report: [2017-10-08 Sun] +| Headline | Time | +|--------------+--------| +| *Total time* | *4:00* | +|--------------+--------| +| Foo | 4:00 |" + (org-test-with-temp-text + "* Foo +CLOCK: [2017-09-30 Sat 12:00]--[2017-09-30 Sat 13:00] =3D> 1:00 +CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] =3D> 2:00 +CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] =3D> 3:00 +CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] =3D> 4:00 +CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] =3D> 5:00" + (test-org-clock-clocktable-contents ":step day :block 2017-W40"))))) + (provide 'test-org-clock) ;;; test-org-clock.el end here --=20 2.12.1.windows.1 --QqzFzR/RUlLahzby Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEt94/pILzkhb5UE6EVMIg1W9Zs5kFAlnYux8ACgkQVMIg1W9Z s5nLdggAhzkOxLkZbTKz0qEPAIsfVGxrAOctK7quir0EetHmy6EYvvFkUSkrYEDj fLue7Iuymo/EmAQaVs7iVq6aCftDKRkYBJ2jQtkZvLaeLG9b/IdGXPN4jzrkOhXF lC5MvfDXpmhdj0mCqLRJk7jrsMYUYPpcopGWzNWh9VZGaTYN/1veVkq/ONXqG9Md txQ4lCqvkvSleKoWvqqLi8jW5pFQa9J1h/IHaN/J6bAFKNDXX8Wh9RDQBNR4VuN3 Q1AhSQMrVtzSiakNhvrSDjbXJpFQSdIj8UwEwrOa3F/h70NigWLKZeFEJovQ/sZ7 Sk6LB3ATOq8SitmzmgElHoIRocMaWA== =4iyu -----END PGP SIGNATURE----- --QqzFzR/RUlLahzby--