emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-clock: Fix clock report sometimes ignoring hours before :wstart
@ 2017-10-04 11:26 Georgiy Tugai
  2017-10-05 14:40 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Georgiy Tugai @ 2017-10-04 11:26 UTC (permalink / raw)
  To: emacs-org

[-- Attachment #1: Type: text/x-diff, Size: 2050 bytes --]

* 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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 9dc501500..0c899dfa2 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,12 @@ 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 ts)))))
+                        (if (= 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")
--
2.12.1.windows.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-clock: Fix clock report sometimes ignoring hours before :wstart
  2017-10-04 11:26 [PATCH] org-clock: Fix clock report sometimes ignoring hours before :wstart Georgiy Tugai
@ 2017-10-05 14:40 ` Nicolas Goaziou
  2017-10-07  2:44   ` Georgiy Tugai
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-10-05 14:40 UTC (permalink / raw)
  To: emacs-org

Hello,

Georgiy Tugai <georgiy.tugai@gmail.com> writes:

> * 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.

Thank you.

Would you mind adding a test in test-org-clock.el?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-clock: Fix clock report sometimes ignoring hours before :wstart
  2017-10-05 14:40 ` Nicolas Goaziou
@ 2017-10-07  2:44   ` Georgiy Tugai
  2017-10-07  6:44     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Georgiy Tugai @ 2017-10-07  2:44 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 954 bytes --]

While implementing the test, I found a bug in my patch. Thanks for
pointing out the test suite! :)

Should I flatten the commits i.e. send original + new changes as one
patch?

Also, I have not yet signed FSF papers -- will this pose a problem for
incorporating the test suite changes?

Regards,
Georgiy

On 05 Oct, Nicolas Goaziou wrote:
> Hello,
> 
> Georgiy Tugai <georgiy.tugai@gmail.com> writes:
> 
> > * 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.
> 
> Thank you.
> 
> Would you mind adding a test in test-org-clock.el?
> 
> Regards,
> 
> -- 
> Nicolas Goaziou
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] org-clock: Fix clock report sometimes ignoring hours before :wstart
  2017-10-07  2:44   ` Georgiy Tugai
@ 2017-10-07  6:44     ` Nicolas Goaziou
  2017-10-07 11:31       ` [PATCH v2] " Georgiy Tugai
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2017-10-07  6:44 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Georgiy Tugai <georgiy.tugai@gmail.com> writes:

> Should I flatten the commits i.e. send original + new changes as one
> patch?

Yes, please.

> Also, I have not yet signed FSF papers -- will this pose a problem for
> incorporating the test suite changes?

I don't think so.

Thank you for the work.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] org-clock: Fix clock report sometimes ignoring hours before :wstart
  2017-10-07  6:44     ` Nicolas Goaziou
@ 2017-10-07 11:31       ` Georgiy Tugai
  2017-10-08  8:55         ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Georgiy Tugai @ 2017-10-07 11:31 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/x-diff, Size: 5694 bytes --]

* 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)
+				 (= 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] =>  0:00
 CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 13:09] =>  0:00"
             (test-org-clock-clocktable-contents ":tcolumns 2")))))
 
+(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] =>  1:00
+CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] =>  2:00
+CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] =>  3:00"
+      (test-org-clock-clocktable-contents ":step week :block 2017-09 :stepskip0 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] =>  1:00
+CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] =>  2:00
+CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] =>  3:00
+CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] =>  4:00
+CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] =>  5:00"
+	    (test-org-clock-clocktable-contents ":step week :block 2017-10 :stepskip0 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] =>  1:00
+CLOCK: [2017-10-01 Sun 11:00]--[2017-10-01 Sun 13:00] =>  2:00
+CLOCK: [2017-10-02 Mon 11:00]--[2017-10-02 Mon 14:00] =>  3:00
+CLOCK: [2017-10-08 Sun 09:00]--[2017-10-08 Sun 13:00] =>  4:00
+CLOCK: [2017-10-09 Mon 09:00]--[2017-10-09 Mon 14:00] =>  5:00"
+	    (test-org-clock-clocktable-contents ":step day :block 2017-W40")))))
+
 (provide 'test-org-clock)
 ;;; test-org-clock.el end here
-- 
2.12.1.windows.1


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] org-clock: Fix clock report sometimes ignoring hours before :wstart
  2017-10-07 11:31       ` [PATCH v2] " Georgiy Tugai
@ 2017-10-08  8:55         ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2017-10-08  8:55 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Georgiy Tugai <georgiy.tugai@gmail.com> writes:

> * 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

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-10-08  8:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-04 11:26 [PATCH] org-clock: Fix clock report sometimes ignoring hours before :wstart Georgiy Tugai
2017-10-05 14:40 ` Nicolas Goaziou
2017-10-07  2:44   ` Georgiy Tugai
2017-10-07  6:44     ` Nicolas Goaziou
2017-10-07 11:31       ` [PATCH v2] " Georgiy Tugai
2017-10-08  8:55         ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).