emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How can I calculate the "age" of a headline?
@ 2014-08-19 15:26 M
  2014-08-19 15:34 ` Thorsten Jolitz
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: M @ 2014-08-19 15:26 UTC (permalink / raw)
  To: emacs orgmode-mailinglist

In my task lists, I'm working with scheduled and deadline dates.
However, it would also often be very interesting, how "old" a task is, how
long it is lurking around on my lists..

Therefore it would be interesting to find the oldest timestamp below this
heading and calculate the difference in days to today.

Is that possible with org-mode already?
Could I display this information in a tabular agenda view in a column?

Kind regards

Martin

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

* Re: How can I calculate the "age" of a headline?
  2014-08-19 15:26 How can I calculate the "age" of a headline? M
@ 2014-08-19 15:34 ` Thorsten Jolitz
  2014-08-19 16:30   ` M
  2014-08-19 15:41 ` John Kitchin
  2014-08-19 21:30 ` Samuel Wales
  2 siblings, 1 reply; 6+ messages in thread
From: Thorsten Jolitz @ 2014-08-19 15:34 UTC (permalink / raw)
  To: emacs-orgmode

M <Elwood151@web.de> writes:

> In my task lists, I'm working with scheduled and deadline dates.
> However, it would also often be very interesting, how "old" a task is, how
> long it is lurking around on my lists..

I copied Bernt Hansens setup for toggling automatic insertion of
inactive timestamps at headline creation. The tj/ prefix is there only
for my convenience, it should really be bh/ (-> Bernt Hansen).

#+BEGIN_SRC emacs-lisp  
;; *** Timestamps

;; **** Configuration 

(add-hook 'org-insert-heading-hook
          'tj/insert-heading-inactive-timestamp 'append)

;; **** Functions

(defvar tj/insert-inactive-timestamp t)

(defun tj/toggle-insert-inactive-timestamp ()
  (interactive)
  (setq tj/insert-inactive-timestamp
        (not tj/insert-inactive-timestamp))
  (message "Heading timestamps are %s"
           (if tj/insert-inactive-timestamp "ON" "OFF")))

(defun tj/insert-inactive-timestamp ()
  (interactive)
  (org-insert-time-stamp nil t t nil nil nil))

(defun tj/insert-heading-inactive-timestamp ()
  (save-excursion
    (when tj/insert-inactive-timestamp
      (org-return)
      (org-cycle)
      (tj/insert-inactive-timestamp))))
#+END_SRC

-- 
cheers,
Thorsten

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

* Re: How can I calculate the "age" of a headline?
  2014-08-19 15:26 How can I calculate the "age" of a headline? M
  2014-08-19 15:34 ` Thorsten Jolitz
@ 2014-08-19 15:41 ` John Kitchin
  2014-08-19 21:30 ` Samuel Wales
  2 siblings, 0 replies; 6+ messages in thread
From: John Kitchin @ 2014-08-19 15:41 UTC (permalink / raw)
  To: M; +Cc: emacs orgmode-mailinglist


I think this does what you want. I do not know if it would be easy to
get in a tabular agenda view though.

* Calculate age of this headline

#+BEGIN_SRC emacs-lisp
(org-narrow-to-subtree)
(org-time-stamp-to-now
 (car
  (cl-sort (org-element-map (org-element-parse-buffer) 'headline
	     (lambda (headline)
	       (org-element-property
		:raw-value
		(org-element-property :deadline headline))))
	   'org-time<)))
#+END_SRC

#+RESULTS:
: -14



** task 1
   DEADLINE: <2014-08-12 Tue>


** task 2
   DEADLINE: <2014-08-05 Tue>

M <Elwood151@web.de> writes:

> In my task lists, I'm working with scheduled and deadline dates.
> However, it would also often be very interesting, how "old" a task is, how
> long it is lurking around on my lists..
>
> Therefore it would be interesting to find the oldest timestamp below this
> heading and calculate the difference in days to today.
>
> Is that possible with org-mode already?
> Could I display this information in a tabular agenda view in a column?
>
> Kind regards
>
> Martin
>
>
>
>

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

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

* Re: How can I calculate the "age" of a headline?
  2014-08-19 15:34 ` Thorsten Jolitz
@ 2014-08-19 16:30   ` M
  2014-08-19 17:50     ` Thorsten Jolitz
  0 siblings, 1 reply; 6+ messages in thread
From: M @ 2014-08-19 16:30 UTC (permalink / raw)
  To: Thorsten Jolitz, emacs-orgmode

Thanks!
I'm using a setup based on Bert Hansen's, so I think I'm already using this
feature and a new headline looks like that:

** new headline
[2014-08-19 Di 18:28]

however, my question is how I can search for this timestamp (I'm not sure if
it is always at the same line below the headline, as sometimes there is a
logbook inbetween) and calculate the difference to today in days and then
display that as a separate column

Kind regards

Martin 


> Von: Thorsten Jolitz <tjolitz@gmail.com>
> Datum: Tue, 19 Aug 2014 17:34:25 +0200
> An: <emacs-orgmode@gnu.org>
> Betreff: Re: [O] How can I calculate the "age" of a headline?
> 
> M <Elwood151@web.de> writes:
> 
>> In my task lists, I'm working with scheduled and deadline dates.
>> However, it would also often be very interesting, how "old" a task is, how
>> long it is lurking around on my lists..
> 
> I copied Bernt Hansens setup for toggling automatic insertion of
> inactive timestamps at headline creation. The tj/ prefix is there only
> for my convenience, it should really be bh/ (-> Bernt Hansen).
> 
> #+BEGIN_SRC emacs-lisp
> ;; *** Timestamps
> 
> ;; **** Configuration
> 
> (add-hook 'org-insert-heading-hook
>           'tj/insert-heading-inactive-timestamp 'append)
> 
> ;; **** Functions
> 
> (defvar tj/insert-inactive-timestamp t)
> 
> (defun tj/toggle-insert-inactive-timestamp ()
>   (interactive)
>   (setq tj/insert-inactive-timestamp
>         (not tj/insert-inactive-timestamp))
>   (message "Heading timestamps are %s"
>            (if tj/insert-inactive-timestamp "ON" "OFF")))
> 
> (defun tj/insert-inactive-timestamp ()
>   (interactive)
>   (org-insert-time-stamp nil t t nil nil nil))
> 
> (defun tj/insert-heading-inactive-timestamp ()
>   (save-excursion
>     (when tj/insert-inactive-timestamp
>       (org-return)
>       (org-cycle)
>       (tj/insert-inactive-timestamp))))
> #+END_SRC
> 
> -- 
> cheers,
> Thorsten
> 
> 

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

* Re: How can I calculate the "age" of a headline?
  2014-08-19 16:30   ` M
@ 2014-08-19 17:50     ` Thorsten Jolitz
  0 siblings, 0 replies; 6+ messages in thread
From: Thorsten Jolitz @ 2014-08-19 17:50 UTC (permalink / raw)
  To: emacs-orgmode

M <Elwood151@web.de> writes:

> Thanks!
> I'm using a setup based on Bert Hansen's, so I think I'm already using this
> feature and a new headline looks like that:
>
> ** new headline
> [2014-08-19 Di 18:28]
>
> however, my question is how I can search for this timestamp (I'm not
> sure if
> it is always at the same line below the headline, as sometimes there is a
> logbook inbetween) and calculate the difference to today in days and then
> display that as a separate column


M <Elwood151@web.de> writes:

> Thanks!
> I'm using a setup based on Bert Hansen's, so I think I'm already using this
> feature and a new headline looks like that:
>
> ** new headline
> [2014-08-19 Di 18:28]
>
> however, my question is how I can search for this timestamp (I'm not
> sure if
> it is always at the same line below the headline, as sometimes there is a
> logbook inbetween) and calculate the difference to today in days and then
> display that as a separate column

I don't know about that column stuff, but a variation of John's
solution should give you the info you want:

#+BEGIN_SRC emacs-lisp
  (defun my-time-to-now ()
    (interactive)
    (save-restriction
      (org-narrow-to-subtree)
      (org-time-stamp-to-now
       (org-element-map (org-element-parse-buffer) 'timestamp
         (lambda (--stamp)
           (when (eq (org-element-property :type --stamp) 'inactive)
             (org-element-property :raw-value --stamp)))
         nil 'FIRST-MATCH))))
#+END_SRC

#+results:
: my-time-to-now


#+BEGIN_SRC emacs-lisp  :results pp
  (save-excursion
    (outline-next-heading)
    (my-time-to-now))
#+END_SRC

#+results:
: -2


* ORG SCRATCH <2014-08-19 Di>
[2014-08-17 So 19:30]


> Kind regards
>
> Martin 
>
>
>> Von: Thorsten Jolitz <tjolitz@gmail.com>
>> Datum: Tue, 19 Aug 2014 17:34:25 +0200
>> An: <emacs-orgmode@gnu.org>
>> Betreff: Re: [O] How can I calculate the "age" of a headline?
>> 
>> M <Elwood151@web.de> writes:
>> 
>>> In my task lists, I'm working with scheduled and deadline dates.
>>> However, it would also often be very interesting, how "old" a task
>>> is, how
>>> long it is lurking around on my lists..
>> 
>> I copied Bernt Hansens setup for toggling automatic insertion of
>> inactive timestamps at headline creation. The tj/ prefix is there only
>> for my convenience, it should really be bh/ (-> Bernt Hansen).
>> 
>> #+BEGIN_SRC emacs-lisp
>> ;; *** Timestamps
>> 
>> ;; **** Configuration
>> 
>> (add-hook 'org-insert-heading-hook
>>           'tj/insert-heading-inactive-timestamp 'append)
>> 
>> ;; **** Functions
>> 
>> (defvar tj/insert-inactive-timestamp t)
>> 
>> (defun tj/toggle-insert-inactive-timestamp ()
>>   (interactive)
>>   (setq tj/insert-inactive-timestamp
>>         (not tj/insert-inactive-timestamp))
>>   (message "Heading timestamps are %s"
>>            (if tj/insert-inactive-timestamp "ON" "OFF")))
>> 
>> (defun tj/insert-inactive-timestamp ()
>>   (interactive)
>>   (org-insert-time-stamp nil t t nil nil nil))
>> 
>> (defun tj/insert-heading-inactive-timestamp ()
>>   (save-excursion
>>     (when tj/insert-inactive-timestamp
>>       (org-return)
>>       (org-cycle)
>>       (tj/insert-inactive-timestamp))))
>> #+END_SRC
>> 
>> -- 
>> cheers,
>> Thorsten
>> 
>> 
>
>
>
>

-- 
cheers,
Thorsten

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

* Re: How can I calculate the "age" of a headline?
  2014-08-19 15:26 How can I calculate the "age" of a headline? M
  2014-08-19 15:34 ` Thorsten Jolitz
  2014-08-19 15:41 ` John Kitchin
@ 2014-08-19 21:30 ` Samuel Wales
  2 siblings, 0 replies; 6+ messages in thread
From: Samuel Wales @ 2014-08-19 21:30 UTC (permalink / raw)
  To: M; +Cc: emacs orgmode-mailinglist

i call these time spans.

to me, it would be excellent as a custom timestamp format.

this requires a patch to org at this location:

	Modified lisp/org.el
diff --git a/lisp/org.el b/lisp/org.el
index b1dc1ce..4497693 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -16814,6 +16814,8 @@ The command returns the inserted time stamp."
 	  tf (funcall (if with-hm 'cdr 'car) org-time-stamp-custom-formats)
 	  time (org-fix-decoded-time t1)
 	  str (org-add-props
+                  ;; fixme alpha make it so that you can run a function
+                  ;; (alpha-org-annotate-ts-with-time-span
 		  (format-time-string
 		   (substring tf 1 -1) (apply 'encode-time time))
 		  nil 'mouse-face 'highlight)

then the code for the time spans is as follows.

(defun alpha-org-time-span-as-string (&optional from now)
  "Return the time span from now
to the active or inactive Org timestamp at point, or nil.

+1 means tomorrow.
 0 means today.
-1 means yesterday.

from and now are daynums.
"
  ;; (alpha-org-time-span from now)
  (let ((from (or from (alpha-org-daynum-from-ts-at-point)))
        (now (or now (alpha-org-daynum-from-now))))
    (when (and from now)
      (alpha-org-format-time-span (- from now)))))
(defun alpha-org-format-time-span (span)
  ;; + makes the numbers line up better
  ;; fixme emacs bug with 0
  (format " = %+-3g" span))
  ;; (format " [= %+-3g]" span))

(defun alpha-org-daynum-from-ts (ts)
  (time-to-days (org-time-string-to-time ts)))
;; (alpha-org-daynum-from-now)
(defun alpha-org-daynum-from-now ()
  (alpha-org-daynum-from-ts "<now>"))
(defun alpha-org-daynum-from-ts-at-point ()
  ;; inactive too
  ;; (if ts
  ;; (alpha-org-daynum-from-ts ts)
  (when (org-at-timestamp-p t)
    (alpha-org-daynum-from-ts
     (substring (match-string 1) 0 10))))





On 8/19/14, M <Elwood151@web.de> wrote:
> In my task lists, I'm working with scheduled and deadline dates.
> However, it would also often be very interesting, how "old" a task is, how
> long it is lurking around on my lists..
>
> Therefore it would be interesting to find the oldest timestamp below this
> heading and calculate the difference in days to today.
>
> Is that possible with org-mode already?
> Could I display this information in a tabular agenda view in a column?
>
> Kind regards
>
> Martin
>
>
>
>


-- 
The Kafka Pandemic: http://thekafkapandemic.blogspot.com

The disease DOES progress.  MANY people have died from it.  And
ANYBODY can get it.

Denmark: free Karina Hansen NOW.

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

end of thread, other threads:[~2014-08-19 21:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-19 15:26 How can I calculate the "age" of a headline? M
2014-08-19 15:34 ` Thorsten Jolitz
2014-08-19 16:30   ` M
2014-08-19 17:50     ` Thorsten Jolitz
2014-08-19 15:41 ` John Kitchin
2014-08-19 21:30 ` Samuel Wales

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