Discussion:
[O] How can I calculate the "age" of a headline?
M
2014-08-19 15:26:55 UTC
Permalink
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
Thorsten Jolitz
2014-08-19 15:34:25 UTC
Permalink
Post by M
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
John Kitchin
2014-08-19 15:41:19 UTC
Permalink
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>
Post by M
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
M
2014-08-19 16:30:22 UTC
Permalink
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
Datum: Tue, 19 Aug 2014 17:34:25 +0200
Betreff: Re: [O] How can I calculate the "age" of a headline?
Post by M
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
Thorsten Jolitz
2014-08-19 17:50:00 UTC
Permalink
Post by M
Thanks!
I'm using a setup based on Bert Hansen's, so I think I'm already using this
** 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
Thanks!
I'm using a setup based on Bert Hansen's, so I think I'm already using this
** 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]
Post by M
Kind regards
Martin
Datum: Tue, 19 Aug 2014 17:34:25 +0200
Betreff: Re: [O] How can I calculate the "age" of a headline?
Post by M
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
Samuel Wales
2014-08-19 21:30:33 UTC
Permalink
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))))
Post by M
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.
Continue reading on narkive:
Loading...