Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-07-03 Thread Sebastien Vauban


Hello Nicolas,

Nicolas Goaziou writes:
> Sebastien Vauban writes:
>
>> Applied the patch:
>
> [...]
>
>> Tested on one of my real files, with:
>
> [...]
>
>> Got this:
>>
>> Debugger entered--Lisp error: (error "Specified time is not
>> representable")
>
> [...]
>
>> BTW, `untilnow' is not proposed when TAB'ing on `C-u C-u C-c C-x C-d'.
>
> Time for another take on this. What about the following patch?

Perfect for me...  I now have the expected total durations displayed.

Best regards,
  Seb

-- 
Sebastien Vauban




Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-06-25 Thread Nicolas Goaziou
Hello,

Sebastien Vauban 
writes:

> Applied the patch:

[...]

> Tested on one of my real files, with:

[...]

> Got this:
>
> Debugger entered--Lisp error: (error "Specified time is not
> representable")

[...]

> BTW, `untilnow' is not proposed when TAB'ing on `C-u C-u C-c C-x C-d'.

Time for another take on this. What about the following patch?

Thank you for the feedback.

Regards,

-- 
Nicolas Goaziou
>From d22786a9542ff285339d61bcc1d0c364233f7a73 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou 
Date: Fri, 20 Feb 2015 11:35:16 +0100
Subject: [PATCH] org-clock: Add `untilnow' time block
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/org-clock.el (org-clock-special-range): Handle `untilnow'
  range.
(org-clock-display-default-range): Add `untilnow' as valid range.
(org-clock-display): Offer `untilnow' as a possible range.

* doc/org.texi (The clock table): Document `untilnow'

Suggested-by: Sébastien Vauban
---
 doc/org.texi  |   1 +
 lisp/org-clock.el | 260 ++
 2 files changed, 144 insertions(+), 117 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index 8ec8a51..9dc4db9 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6648,6 +6648,7 @@ be selected:
  thisweek, lastweek, thisweek-@var{N} @r{a relative week}
  thismonth, lastmonth, thismonth-@var{N}  @r{a relative month}
  thisyear, lastyear, thisyear-@var{N} @r{a relative year}
+ untilnow
  @r{Use @kbd{S-@key{left}/@key{right}} keys to shift the time interval.}
 :tstart  @r{A time string specifying when to start considering times.}
  @r{Relative times like @code{"<-2w>"} can also be used.  See}
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 31d6115..d594054 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -441,6 +441,7 @@ This applies when using `org-clock-goto'."
 		 (const lastmonth)
 		 (const thisyear)
 		 (const lastyear)
+		 (const untilnow)
 		 (const :tag "Select range interactively" interactive)))
 
 (defvar org-clock-in-prepare-hook nil
@@ -1879,9 +1880,9 @@ Use \\[org-clock-remove-overlays] to remove the subtree times."
   (org-clock-remove-overlays)
   (let* ((todayp (equal arg '(4)))
 	 (customp (member arg '((16) today yesterday
-			   thisweek lastweek thismonth
-			   lastmonth thisyear lastyear
-			   interactive)))
+thisweek lastweek thismonth
+lastmonth thisyear lastyear
+untilnow interactive)))
 	 (prop (cond ((not arg) :org-clock-minutes-default)
 		 (todayp :org-clock-minutes-today)
 		 (customp :org-clock-minutes-custom)
@@ -2090,134 +2091,159 @@ buffer and update it."
 
 (defun org-clock-special-range (key &optional time as-strings wstart mstart)
   "Return two times bordering a special time range.
-Key is a symbol specifying the range and can be one of `today', `yesterday',
-`thisweek', `lastweek', `thismonth', `lastmonth', `thisyear', `lastyear'.
-By default, a week starts Monday 0:00 and ends Sunday 24:00.
-The range is determined relative to TIME, which defaults to current time.
-The return value is a cons cell with two internal times like the ones
-returned by `current time' or `encode-time'.
-If AS-STRINGS is non-nil, the returned times will be formatted strings.
-If WSTART is non-nil, use this number to specify the starting day of a
-week (monday is 1).
-If MSTART is non-nil, use this number to specify the starting day of a
-month (1 is the first day of the month).
-If you can combine both, the month starting day will have priority."
-  (if (integerp key) (setq key (intern (number-to-string key
+
+KEY is a symbol specifying the range and can be one of `today',
+`yesterday', `thisweek', `lastweek', `thismonth', `lastmonth',
+`thisyear', `lastyear' or `untilnow'.  If set to `interactive',
+user is prompted for range boundaries.  It can be a string or an
+integer.
+
+By default, a week starts Monday 0:00 and ends Sunday 24:00.  The
+range is determined relative to TIME, which defaults to current
+time.
+
+The return value is a list containing two internal times, one for
+the beginning of the range and one for its end, like the ones
+returned by `current time' or `encode-time' and a string used to
+display information.  If AS-STRINGS is non-nil, the returned
+times will be formatted strings.
+
+If WSTART is non-nil, use this number to specify the starting day
+of a week (monday is 1).  If MSTART is non-nil, use this number
+to specify the starting day of a month (1 is the first day of the
+month).  If you can combine both, the month starting day will
+have priority."
   (let* ((tm (decode-time (or time (current-time
-	 (s 0) (m (nth 1 tm)) (h (nth 2 tm))
-	 (d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 tm))
+	 (m (nth 1 tm))
+	 (h (nth 2 tm))
+	 (d (nth 3 tm))
+	 (month (nth 4 tm))
+	 (y (nth 5 tm))
 	 (dow (nth 6 tm))
-	 (ws (or wstart 1))
-	 (ms (or mstart 1))
-	 (skey (symb

Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-06-25 Thread Sebastien Vauban
Hello Nicolas,

Nicolas Goaziou writes:
> Sebastien Vauban writes:
>
>> I still consider the default behavior as dangerous -- because the novice
>> is not aware (except if obvious) that some clock times may be dropped in
>> the computation, and I find that scary --, but thanks anyway for the
>> workaround.
>
> Would you mind testing the following patch, then? `untilnow' is just
> a suggestion.

Applied the patch:

--8<---cut here---start->8---
patching file lisp/org-clock.el
Hunk #1 succeeded at 441 (offset 1 line).
Hunk #2 succeeded at 2091 (offset 3 lines).
Hunk #3 succeeded at 2200 (offset 3 lines).
Hunk #4 succeeded at 2216 (offset 3 lines).
--8<---cut here---end--->8---

Tested on one of my real files, with:

  ┌
  │ org-clock-display-default-range is a variable defined in `org-clock.el'.
  │ Its value is untilnow
  │ Original value was thisyear
  │ 
  │ Documentation:
  │ Default range when displaying clocks with `org-clock-display'.
  │ 
  │ You can customize this variable.
  └

Got this:

--8<---cut here---start->8---
Debugger entered--Lisp error: (error "Specified time is not representable")
  encode-time(0 0 0 1 1 1)
  (setq ts (encode-time s m h d month y) te (encode-time (or s1 s) (or m1 m) 
(or h1 h) (or d1 d) (or month1 month) (or y1 y)))
  (let* ((tm (decode-time (or time (current-time (s 0) (m (nth 1 tm)) (h 
(nth 2 tm)) (d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 tm)) (dow (nth 6 tm)) 
(ws (or wstart 1)) (ms (or mstart 1)) (skey (symbol-name key)) (shift 0) (q 
(cond ((>= (nth 4 tm) 10) 4) ((>= (nth 4 tm) 7) 3) ((>= (nth 4 tm) 4) 2) ((>= 
(nth 4 tm) 1) 1))) s1 m1 h1 d1 month1 y1 diff ts te fm txt w date interval tmp 
shiftedy shiftedm shiftedq) (cond ((string-match "^[0-9]+$" skey) (setq y 
(string-to-number skey) m 1 d 1 key (quote year))) ((string-match 
"^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)$" skey) (setq y (string-to-number 
(match-string 1 skey)) month (string-to-number (match-string 2 skey)) d 1 key 
(quote month))) ((string-match "^\\([0-9]+\\)-[wW]\\([0-9]\\{1,2\\}\\)$" skey) 
(require (quote cal-iso)) (setq y (string-to-number (match-string 1 skey)) w 
(string-to-number (match-string 2 skey))) (setq date 
(calendar-gregorian-from-absolute (calendar-iso-to-absolute (list w 1 y 
(setq d (nth 1 date) month (car date) y (nth 2 date) dow 1 key (quote week))) 
((string-match "^\\([0-9]+\\)-[qQ]\\([1-4]\\)$" skey) (require (quote cal-iso)) 
(setq y (string-to-number (match-string 1 skey))) (setq q (string-to-number 
(match-string 2 skey))) (setq date (calendar-gregorian-from-absolute 
(calendar-iso-to-absolute (org-quarter-to-date q y (setq d (nth 1 date) 
month (car date) y (nth 2 date) dow 1 key (quote quarter))) ((string-match 
"^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)$" skey) (setq y 
(string-to-number (match-string 1 skey)) month (string-to-number (match-string 
2 skey)) d (string-to-number (match-string 3 skey)) key (quote day))) 
((string-match "\\([-+][0-9]+\\)$" skey) (setq shift (string-to-number 
(match-string 1 skey)) key (intern (substring skey 0 (match-beginning 1 (if 
(and (memq key (quote (quarter thisq))) (> shift 0)) (error "Looking forward 
with quarters isn't implemented" (if (= shift 0) (progn (cond ((eq key 
(quote yesterday)) (setq key (quote today) shift -1)) ((eq key (quote 
lastweek)) (setq key (quote week) shift -1)) ((eq key (quote lastmonth)) (setq 
key (quote month) shift -1)) ((eq key (quote lastyear)) (setq key (quote year) 
shift -1)) ((eq key (quote lastq)) (setq key (quote quarter) shift -1) 
(cond ((memq key (quote (day today))) (setq d (+ d shift) h 0 m 0 h1 24 m1 0)) 
((memq key (quote (week thisweek))) (setq diff (+ (* -7 shift) (if (= dow 0) (- 
7 ws) (- dow ws))) m 0 h 0 d (- d diff) d1 (+ 7 d))) ((memq key (quote (month 
thismonth))) (setq d (or ms 1) h 0 m 0 d1 (or ms 1) month (+ month shift) 
month1 (1+ month) h1 0 m1 0)) ((memq key (quote (quarter thisq))) (cond ((< (+ 
(- q 1) shift) 0) (setq interval (* -1 (+ ... shift))) (setq tmp (org-floor* 
interval 4)) (if (= 0 (nth 1 tmp)) (setq shiftedy (- y ...) shiftedm 1 shiftedq 
1) (setq shiftedy (- y ...) shiftedm (- 13 ...) shiftedq (- 5 ...))) (setq d 1 
h 0 m 0 d1 1 month shiftedm month1 (+ 3 shiftedm) h1 0 m1 0 y shiftedy)) ((> (+ 
q shift) 0) (setq shiftedq (+ q shift)) (setq shiftedy y) (setq d 1 h 0 m 0 d1 
1 month (+ 1 (* 3 ...)) month1 (+ 4 (* 3 ...)) h1 0 m1 0 ((memq key (quote 
(year thisyear))) (setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y))) ((eq key 
(quote untilnow)) (setq y1 y month1 m d1 d m 0 h 0 d 1 month 1 y 1)) ((eq key 
(quote interactive)) nil) (t (user-error "No such time block %s" key))) (setq 
ts (encode-time s m h d month y) te (encode-time (or s1 s) (or m1 m) (or h1 h) 
(or d1 d) (or month1 month) (or y1 y))) (setq fm (cdr org-time-stamp-formats)) 
(cond ((memq key (quote (day today))) (setq txt (format-time-str

Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-02-20 Thread Nicolas Goaziou
Sebastien Vauban 
writes:

> I still consider the default behavior as dangerous -- because the novice
> is not aware (except if obvious) that some clock times may be dropped in
> the computation, and I find that scary --, but thanks anyway for the
> workaround.

Would you mind testing the following patch, then? `untilnow' is just
a suggestion.

Regards,

>From eec96edbc27a56159642f939a9ccd0e56e348a58 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou 
Date: Fri, 20 Feb 2015 11:35:16 +0100
Subject: [PATCH] org-clock: Add `untilnow' time block
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/org-clock.el (org-clock-special-range): Handle `untilnow'
  range.
(org-clock-display-default-range): Add `untilnow' as valid range.

* doc/org.texi (The clock table): Document `untilnow'

Suggested-by: Sébastien Vauban
---
 doc/org.texi  |  1 +
 lisp/org-clock.el | 33 +
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index bec46a9..ba553e2 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6572,6 +6572,7 @@ be selected:
  thisweek, lastweek, thisweek-@var{N} @r{a relative week}
  thismonth, lastmonth, thismonth-@var{N}  @r{a relative month}
  thisyear, lastyear, thisyear-@var{N} @r{a relative year}
+ untilnow
  @r{Use @kbd{S-@key{left}/@key{right}} keys to shift the time interval.}
 :tstart  @r{A time string specifying when to start considering times.}
  @r{Relative times like @code{"<-2w>"} can also be used.  See}
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 07f02b0..f6cc766 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -440,6 +440,7 @@ This applies when using `org-clock-goto'."
 		 (const lastmonth)
 		 (const thisyear)
 		 (const lastyear)
+		 (const untilnow)
 		 (const :tag "Select range interactively" interactive)))
 
 (defvar org-clock-in-prepare-hook nil
@@ -2087,18 +2088,24 @@ buffer and update it."
 
 (defun org-clock-special-range (key &optional time as-strings wstart mstart)
   "Return two times bordering a special time range.
-Key is a symbol specifying the range and can be one of `today', `yesterday',
-`thisweek', `lastweek', `thismonth', `lastmonth', `thisyear', `lastyear'.
-By default, a week starts Monday 0:00 and ends Sunday 24:00.
-The range is determined relative to TIME, which defaults to current time.
-The return value is a cons cell with two internal times like the ones
-returned by `current time' or `encode-time'.
-If AS-STRINGS is non-nil, the returned times will be formatted strings.
-If WSTART is non-nil, use this number to specify the starting day of a
-week (monday is 1).
-If MSTART is non-nil, use this number to specify the starting day of a
-month (1 is the first day of the month).
-If you can combine both, the month starting day will have priority."
+
+KEY is a symbol specifying the range and can be one of `today',
+`yesterday', `thisweek', `lastweek', `thismonth', `lastmonth',
+`thisyear', `lastyear' or `untilnow'.
+
+By default, a week starts Monday 0:00 and ends Sunday 24:00.  The
+range is determined relative to TIME, which defaults to current
+time.
+
+The return value is a cons cell with two internal times like the
+ones returned by `current time' or `encode-time'.  If AS-STRINGS
+is non-nil, the returned times will be formatted strings.
+
+If WSTART is non-nil, use this number to specify the starting day
+of a week (monday is 1).  If MSTART is non-nil, use this number
+to specify the starting day of a month (1 is the first day of the
+month).  If you can combine both, the month starting day will
+have priority."
   (if (integerp key) (setq key (intern (number-to-string key
   (let* ((tm (decode-time (or time (current-time
 	 (s 0) (m (nth 1 tm)) (h (nth 2 tm))
@@ -2190,6 +2197,7 @@ If you can combine both, the month starting day will have priority."
 	  month1 (+ 4 (* 3 (- (+ q shift) 1))) h1 0 m1 0
  ((memq key '(year thisyear))
   (setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y)))
+ ((eq key 'untilnow) (setq y1 y month1 m d1 d m 0 h 0 d 1 month 1 y 1))
  ((eq key 'interactive) nil)
  (t (user-error "No such time block %s" key)))
 (setq ts (encode-time s m h d month y)
@@ -2205,6 +2213,7 @@ If you can combine both, the month starting day will have priority."
   (setq txt (format-time-string "%B %Y" ts)))
  ((memq key '(year thisyear))
   (setq txt (format-time-string "the year %Y" ts)))
+ ((eq key 'untilnow) (setq txt "now"))
  ((memq key '(quarter thisq))
   (setq txt (concat (org-count-quarter shiftedq)
 			" quarter of " (number-to-string shiftedy)
-- 
2.3.0



Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-02-18 Thread Sebastien Vauban
Nicolas Goaziou wrote:
> Sebastien Vauban writes:
>
>>> See `org-clock-display-default-range'.  Basically, clock display only
>>> consider clocks in the current year, by default.
>>
>> For me, what makes more sense is "show all" (as, unlike dynamic blocks,
>> we have no visible indication of what's get considered in the total).
>>
>> Though, it seems not to exit...
>
> With a double prefix argument, you can specify interactively an
> arbitrary wide range (e.g., "-15y" "+15y").

I still consider the default behavior as dangerous -- because the novice
is not aware (except if obvious) that some clock times may be dropped in
the computation, and I find that scary --, but thanks anyway for the
workaround.

Best regards,
  Seb

-- 
Sebastien Vauban




Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-02-18 Thread Nicolas Goaziou
Sebastien Vauban 
writes:

>> See `org-clock-display-default-range'.  Basically, clock display only
>> consider clocks in the current year, by default.
>
> For me, what makes more sense is "show all" (as, unlike dynamic blocks,
> we have no visible indication of what's get considered in the total).
>
> Though, it seems not to exit...

With a double prefix argument, you can specify interactively an
arbitrary wide range (e.g., "-15y" "+15y").


Regards,



Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-02-18 Thread Sebastien Vauban


Hello,

Nicolas Goaziou wrote:
> Sebastien Vauban writes:
>
>> As you can see on http://screencast.com/t/B0knccOCqco, the output of the
>> command org-clock-display (bound to C-c C-x C-d) -- which displays
>> subtree times in the entire buffer -- is partial: for a reason which
>> still escapes me, meetings A and B are not counted...
>
> See `org-clock-display-default-range'.  Basically, clock display only
> consider clocks in the current year, by default.

For me, what makes more sense is "show all" (as, unlike dynamic blocks,
we have no visible indication of what's get considered in the total).

Though, it seems not to exit...

Best regards,
  Seb

-- 
Sebastien Vauban




Re: [O] [BUG] org-clock-display is partial (only some entries are counted)

2015-02-17 Thread Nicolas Goaziou


Hello,

Sebastien Vauban 
writes:

> As you can see on http://screencast.com/t/B0knccOCqco, the output of the
> command org-clock-display (bound to C-c C-x C-d) -- which displays
> subtree times in the entire buffer -- is partial: for a reason which
> still escapes me, meetings A and B are not counted...

See `org-clock-display-default-range'.  Basically, clock display only
consider clocks in the current year, by default.

> PS- Another weird thing is to see that "Org clock display" reports some
> time (0:13 in the screenshot) for the section "Worked Hours
> Report"... which has no LOGBOOK!

I cannot reproduce it.

Regards,

-- 
Nicolas Goaziou




[O] [BUG] org-clock-display is partial (only some entries are counted)

2015-02-17 Thread Sebastien Vauban
Hello,

As you can see on http://screencast.com/t/B0knccOCqco, the output of the
command org-clock-display (bound to C-c C-x C-d) -- which displays
subtree times in the entire buffer -- is partial: for a reason which
still escapes me, meetings A and B are not counted...

On the other hand, the dynamic block (at the bottom of the ECM) is
correct.

PS- Another weird thing is to see that "Org clock display" reports some
time (0:13 in the screenshot) for the section "Worked Hours
Report"... which has no LOGBOOK!

--8<---cut here---start->8---
#+TITLE: ECM

* Events

** Meeting A
   :LOGBOOK:
   CLOCK: [2014-12-01 Mon 11:49]--[2014-12-01 Mon 17:12] =>  5:23
   :END:
   <2014-12-01 Mon 13:00-17:00>

** Meeting B
   :LOGBOOK:
   CLOCK: [2014-12-19 Fri 08:02]--[2014-12-19 Fri 15:02] =>  7:00
   CLOCK: [2014-12-19 Fri 16:47]--[2014-12-19 Fri 17:35] =>  0:48
   CLOCK: [2014-12-23 Tue 10:44]--[2014-12-23 Tue 12:49] =>  2:05
   CLOCK: [2014-12-24 Wed 08:40]--[2014-12-24 Wed 08:54] =>  0:14
   CLOCK: [2014-12-24 Wed 15:17]--[2014-12-24 Wed 15:32] =>  0:15
   :END:
   <2014-12-19 Fri 09:00-13:00>

** Meeting C
   <2015-01-09 Fri 10:00-18:00>
   :LOGBOOK:
   CLOCK: [2015-01-09 Fri 08:50]--[2015-01-09 Fri 18:02] =>  9:12
   :END:

** Meeting D
   :LOGBOOK:
   CLOCK: [2015-01-27 Tue 13:09]--[2015-01-27 Tue 16:50] =>  3:41
   CLOCK: [2015-01-28 Wed 11:40]--[2015-01-28 Wed 12:23] =>  0:43
   CLOCK: [2015-01-28 Wed 13:44]--[2015-01-28 Wed 14:59] =>  1:15
   CLOCK: [2015-01-29 Thu 09:32]--[2015-01-29 Thu 10:10] =>  0:38
   CLOCK: [2015-02-11 Wed 11:07]--[2015-02-11 Wed 11:52] =>  0:45
   :END:
   <2015-01-27 Tue 14:00-16:00>

* Worked Hours Report

#+BEGIN: clocktable :maxlevel 2 :scope file
#+CAPTION: Clock summary at [2015-02-17 Tue 10:05]
| Headline|  Time |   |
|-+---+---|
| Total time  | 31:59 |   |
|-+---+---|
| Events  | 31:59 |   |
| \emsp Meeting A |   |  5:23 |
| \emsp Meeting B |   | 10:22 |
| \emsp Meeting C |   |  9:12 |
| \emsp Meeting D |   |  7:02 |
#+END:
--8<---cut here---end--->8---

Best regards,
  Seb

-- 
Sebastien Vauban