* [PATCH] Allow relative times in clocktable tstart and tend options
@ 2012-11-21 23:07 Ivan Vilata i Balaguer
2012-11-28 12:47 ` Nicolas Goaziou
0 siblings, 1 reply; 6+ messages in thread
From: Ivan Vilata i Balaguer @ 2012-11-21 23:07 UTC (permalink / raw)
To: emacs-orgmode
* lisp/org-clock.el (org-clock-get-table-data): Pass tstart and tend
time strings through `org-matcher-time` to allow relative times besides
absolute ones, convert result to encoded time.
* doc/org.texi (The clock table): Document acceptance of relative times
in tstart and tend, link to syntax description.
Inspired in the original relative times proposal by Ilya Shlyakhter,
this is less invasive and it doesn't modify core functions, thus it
avoids the original's infinite recursion when hitting normal dates in
other locations.
TINYCHANGE
---
doc/org.texi | 4 ++++
lisp/org-clock.el | 4 ++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index bf67876..c88b745 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6263,7 +6263,11 @@ be selected:
thisyear, lastyear, thisyear-@var{N} @r{a relative year}
@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}
+ @r{@ref{Matching tags and properties} for relative time syntax.}
:tend @r{A time string specifying when to stop considering times.}
+ @r{Relative times like @code{"<now>"} can also be used. See}
+ @r{@ref{Matching tags and properties} for relative time syntax.}
:step @r{@code{week} or @code{day}, to split the table into chunks.}
@r{To use this, @code{:block} or @code{:tstart}, @code{:tend} are needed.}
:stepskip0 @r{Do not show steps that have zero time.}
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 54e4018..6595330 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2604,9 +2604,9 @@ TIME: The sum of all time spend in this tree, in minutes. This time
(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
;; Now the times are strings we can parse.
(if ts (setq ts (org-float-time
- (apply 'encode-time (org-parse-time-string ts)))))
+ (seconds-to-time (org-matcher-time ts)))))
(if te (setq te (org-float-time
- (apply 'encode-time (org-parse-time-string te)))))
+ (seconds-to-time (org-matcher-time te)))))
(save-excursion
(org-clock-sum ts te
(unless (null matcher)
--
1.7.10.4
--
Ivan Vilata i Balaguer -- https://elvil.net/
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relative times in clocktable tstart and tend options
2012-11-21 23:07 [PATCH] Allow relative times in clocktable tstart and tend options Ivan Vilata i Balaguer
@ 2012-11-28 12:47 ` Nicolas Goaziou
2012-11-28 16:11 ` Ivan Vilata i Balaguer
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2012-11-28 12:47 UTC (permalink / raw)
To: Ivan Vilata i Balaguer; +Cc: emacs-orgmode
Hello,
Ivan Vilata i Balaguer <ivan@selidor.net> writes:
> * lisp/org-clock.el (org-clock-get-table-data): Pass tstart and tend
> time strings through `org-matcher-time` to allow relative times besides
> absolute ones, convert result to encoded time.
> * doc/org.texi (The clock table): Document acceptance of relative times
> in tstart and tend, link to syntax description.
>
> Inspired in the original relative times proposal by Ilya Shlyakhter,
> this is less invasive and it doesn't modify core functions, thus it
> avoids the original's infinite recursion when hitting normal dates in
> other locations.
>
> TINYCHANGE
Thank you for your patch.
Would you mind providing a (couple) of simple test case(s) (or better,
a complete ert test) for that situation?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relative times in clocktable tstart and tend options
2012-11-28 12:47 ` Nicolas Goaziou
@ 2012-11-28 16:11 ` Ivan Vilata i Balaguer
2012-11-28 22:32 ` Ivan Vilata i Balaguer
0 siblings, 1 reply; 6+ messages in thread
From: Ivan Vilata i Balaguer @ 2012-11-28 16:11 UTC (permalink / raw)
To: emacs-orgmode
Nicolas Goaziou (2012-11-28 13:47:32 +0100) wrote:
> Ivan Vilata i Balaguer <ivan@selidor.net> writes:
>
>> * lisp/org-clock.el (org-clock-get-table-data): Pass tstart and tend
>> time strings through `org-matcher-time` to allow relative times besides
>> absolute ones, convert result to encoded time.
>> * doc/org.texi (The clock table): Document acceptance of relative times
>> in tstart and tend, link to syntax description.
>>
>> Inspired in the original relative times proposal by Ilya Shlyakhter,
>> this is less invasive and it doesn't modify core functions, thus it
>> avoids the original's infinite recursion when hitting normal dates in
>> other locations.
>>
>> TINYCHANGE
>
> Thank you for your patch.
>
> Would you mind providing a (couple) of simple test case(s) (or better,
> a complete ert test) for that situation?
Of course, I will do it ASAP. Thanks for considering the patch!
--
Ivan Vilata i Balaguer -- https://elvil.net/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relative times in clocktable tstart and tend options
2012-11-28 16:11 ` Ivan Vilata i Balaguer
@ 2012-11-28 22:32 ` Ivan Vilata i Balaguer
2012-11-30 15:31 ` Nicolas Goaziou
0 siblings, 1 reply; 6+ messages in thread
From: Ivan Vilata i Balaguer @ 2012-11-28 22:32 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1729 bytes --]
Ivan Vilata i Balaguer (2012-11-28 17:11:46 +0100) wrote:
> Nicolas Goaziou (2012-11-28 13:47:32 +0100) wrote:
>
>> Ivan Vilata i Balaguer <ivan@selidor.net> writes:
>>
>>> * lisp/org-clock.el (org-clock-get-table-data): Pass tstart and tend
>>> time strings through `org-matcher-time` to allow relative times besides
>>> absolute ones, convert result to encoded time.
>>> * doc/org.texi (The clock table): Document acceptance of relative times
>>> in tstart and tend, link to syntax description.
>>>
>>> Inspired in the original relative times proposal by Ilya Shlyakhter,
>>> this is less invasive and it doesn't modify core functions, thus it
>>> avoids the original's infinite recursion when hitting normal dates in
>>> other locations.
>>>
>>> TINYCHANGE
>>
>> Thank you for your patch.
>>
>> Would you mind providing a (couple) of simple test case(s) (or
>> better, a complete ert test) for that situation?
>
> Of course, I will do it ASAP. Thanks for considering the patch!
I expected to find some existing clocktable test I could base mine upon,
but it seems that there's none yet, and my elisp skills are insufficient
to write a completely new test mysef. So I wrote a simple example file
(attached) in case it can be useful for a test.
Then I realised that using it for a test can be difficult since relative
times depend on the moment that functions are invoked, so no luck. :(
I'm really sorry that I can provide nothing more than this. However it
seems to work from my live tests, and I confined the changes as much as
possible to avoid other failures.
I'm also attaching a small update to patch that adds a trivial example
to the info file.
Thanks anyway!
--
Ivan Vilata i Balaguer -- https://elvil.net/
[-- Attachment #2: clocktable-reltime.org --]
[-- Type: text/plain, Size: 1573 bytes --]
#+TITLE: Testing relative times in a clocktable
* Relative times in clocktable :ATTACH:
:PROPERTIES:
:ID: af259fdb-b7b7-4307-81b0-0a4439fd944d
:END:
Previous two days:
#+BEGIN: clocktable :tstart "<today-2>" :tend "<today>" :link nil :indent nil
Clock summary at [2012-11-28 dc 22:28]
| Headline | Time | |
|------------------------------+-------+-------|
| *Total time* | *16:00* | |
|------------------------------+-------+-------|
| Relative times in clocktable | 16:00 | |
| Foo | | 5:00 |
| Bar | | 11:00 |
#+END: clocktable
From yesterday until now:
#+BEGIN: clocktable :tstart "<yesterday>" :tend "<now>" :link nil :indent nil
Clock summary at [2012-11-28 dc 22:28]
| Headline | Time | |
|------------------------------+-------+------|
| *Total time* | *13:00* | |
|------------------------------+-------+------|
| Relative times in clocktable | 13:00 | |
| Foo | | 5:00 |
| Bar | | 8:00 |
#+END: clocktable
** Foo
CLOCK: [2012-11-26 dl 08:00]--[2012-11-26 dl 13:00] => 5:00
CLOCK: [2012-11-28 dc 08:00]--[2012-11-28 dc 13:00] => 5:00
** Bar
CLOCK: [2012-11-26 dl 15:00]--[2012-11-26 dl 18:00] => 3:00
CLOCK: [2012-11-27 dt 08:00]--[2012-11-27 dt 13:00] => 5:00
CLOCK: [2012-11-27 dt 15:00]--[2012-11-27 dt 18:00] => 3:00
CLOCK: [2012-11-28 dc 15:00]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Allow-relative-times-in-clocktable-tstart-and-tend-o.patch --]
[-- Type: text/x-diff, Size: 3073 bytes --]
From e85bd48ee3ba39c2bd365cabddd695a32a0184fa Mon Sep 17 00:00:00 2001
From: Ivan Vilata i Balaguer <ivan@selidor.net>
Date: Wed, 28 Nov 2012 20:57:55 +0100
Subject: [PATCH] Allow relative times in clocktable tstart and tend options
* lisp/org-clock.el (org-clock-get-table-data): Pass tstart and tend
time strings through `org-matcher-time' to allow relative times besides
absolute ones, convert result to encoded time.
* doc/org.texi (The clock table): Document acceptance of relative times
in tstart and tend, link to syntax description and provide example.
Inspired in the original relative times proposal by Ilya Shlyakhter,
this is less invasive and it doesn't modify core functions, thus it
avoids the original's infinite recursion when hitting normal dates in
other locations.
TINYCHANGE
---
doc/org.texi | 9 +++++++++
lisp/org-clock.el | 4 ++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index bf67876..e3a40ec 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6263,7 +6263,11 @@ be selected:
thisyear, lastyear, thisyear-@var{N} @r{a relative year}
@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}
+ @r{@ref{Matching tags and properties} for relative time syntax.}
:tend @r{A time string specifying when to stop considering times.}
+ @r{Relative times like @code{"<now>"} can also be used. See}
+ @r{@ref{Matching tags and properties} for relative time syntax.}
:step @r{@code{week} or @code{day}, to split the table into chunks.}
@r{To use this, @code{:block} or @code{:tstart}, @code{:tend} are needed.}
:stepskip0 @r{Do not show steps that have zero time.}
@@ -6314,6 +6318,11 @@ only to fit it into the manual.}
:tend "<2006-08-10 Thu 12:00>"
#+END: clocktable
@end example
+A range starting a week ago and ending right now could be written as
+@example
+#+BEGIN: clocktable :tstart "<-1w>" :tend "<now>"
+#+END: clocktable
+@end example
A summary of the current subtree with % times would be
@example
#+BEGIN: clocktable :scope subtree :link t :formula %
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 54e4018..6595330 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2604,9 +2604,9 @@ TIME: The sum of all time spend in this tree, in minutes. This time
(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
;; Now the times are strings we can parse.
(if ts (setq ts (org-float-time
- (apply 'encode-time (org-parse-time-string ts)))))
+ (seconds-to-time (org-matcher-time ts)))))
(if te (setq te (org-float-time
- (apply 'encode-time (org-parse-time-string te)))))
+ (seconds-to-time (org-matcher-time te)))))
(save-excursion
(org-clock-sum ts te
(unless (null matcher)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relative times in clocktable tstart and tend options
2012-11-28 22:32 ` Ivan Vilata i Balaguer
@ 2012-11-30 15:31 ` Nicolas Goaziou
2012-11-30 23:09 ` Ivan Vilata i Balaguer
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2012-11-30 15:31 UTC (permalink / raw)
To: Ivan Vilata i Balaguer; +Cc: emacs-orgmode
Hello,
Ivan Vilata i Balaguer <ivan@elvil.net> writes:
> I expected to find some existing clocktable test I could base mine upon,
> but it seems that there's none yet.
Yes, Org is lacking in the regression tests area. I hope that will
change in the future.
> So I wrote a simple example file (attached) in case it can be useful
> for a test.
Great. I wrote tests out of it.
> I'm also attaching a small update to patch that adds a trivial example
> to the info file.
>
> Thanks anyway!
This is now applied. Thank you for you work.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relative times in clocktable tstart and tend options
2012-11-30 15:31 ` Nicolas Goaziou
@ 2012-11-30 23:09 ` Ivan Vilata i Balaguer
0 siblings, 0 replies; 6+ messages in thread
From: Ivan Vilata i Balaguer @ 2012-11-30 23:09 UTC (permalink / raw)
To: emacs-orgmode
Nicolas Goaziou (2012-11-30 16:31:47 +0100) wrote:
> Hello,
>
> Ivan Vilata i Balaguer <ivan@elvil.net> writes:
>
>> I expected to find some existing clocktable test I could base mine
>> upon, but it seems that there's none yet.
>
> Yes, Org is lacking in the regression tests area. I hope that will
> change in the future.
>
>> So I wrote a simple example file (attached) in case it can be useful
>> for a test.
>
> Great. I wrote tests out of it.
>
>> I'm also attaching a small update to patch that adds a trivial
>> example to the info file.
>>
>> Thanks anyway!
>
> This is now applied. Thank you for you work.
>
> Regards,
It was very instructive to look at the new tests. :)
Thanks!
--
Ivan Vilata i Balaguer -- https://elvil.net/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-11-30 23:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-21 23:07 [PATCH] Allow relative times in clocktable tstart and tend options Ivan Vilata i Balaguer
2012-11-28 12:47 ` Nicolas Goaziou
2012-11-28 16:11 ` Ivan Vilata i Balaguer
2012-11-28 22:32 ` Ivan Vilata i Balaguer
2012-11-30 15:31 ` Nicolas Goaziou
2012-11-30 23:09 ` Ivan Vilata i Balaguer
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).