2

My config (spacemacs with ~0 extra) sets a CLOSED time when I move a task in org-mode to DONE:

***** DONE A task
CLOSED: [2022-09-12 Mon 16:18] SCHEDULED: <2022-09-07 Wed>

It's easy to only show DONE tasks, but now I'd like to get an agenda view that can use the timestamp set for CLOSED so that I can look back at what items I've finished in the past week. What can I do to build this?

I'm a beginner at this so I'm probably missing some basics. For instance I don't know what the difference is between a [timestamp] and a <timestamp>.

2
  • For the difference between [ts] and <ts> see Inactive timestamp.
    – NickD
    Commented Sep 13, 2022 at 17:34
  • Inactive timestamps ([ts]) do not contribute to the agenda, whereas active timestamps (<ts>) do.
    – NickD
    Commented Jul 11, 2023 at 2:10

2 Answers 2

3

I know this is an old question, but I was trying to do the same thing and ended cooking something up. So I might as well share.

Since there doesn't seem to be anything of the sort available out of the box, we need a custom sort function and thus also to set an entry in org-agenda-custom-commands so as to be able to set proper sorting. For an custom-commands entry like:

("n" "Whatever"
 ((tags "CLOSED<=\"<now>\""))
 ((org-agenda-cmp-user-defined 'org-cmp-closed)
  (org-agenda-sorting-strategy '(user-defined-down))))

We define the corresponding sort function as:

(defun org-cmp-closed (a b)
  (let* ((a-marker (get-text-property 0 'org-marker a))
         (b-marker (get-text-property 0 'org-marker b))
         (now (current-time))
         (a-closed-ts (org-timestamp-from-string
                       (org-entry-get a-marker "CLOSED")))
         (b-closed-ts (org-timestamp-from-string
                       (org-entry-get b-marker "CLOSED")))
         (a-closed-time (or (and a-closed-ts
                                 (org-timestamp-to-time a-closed-ts))
                            now))
         (b-closed-time (or (and b-closed-ts
                                 (org-timestamp-to-time b-closed-ts))
                            now)))
    (cond ((time-less-p b-closed-time a-closed-time) +1)
          ((time-less-p a-closed-time b-closed-time) -1)
          (t nil))))
5
  • Is this supposed to work with CLOSED entries place in Logbook? Commented May 10 at 23:29
  • 1
    @JasonHunter Whether an entry is considered closed or not is taken from the planning line, not the logbook drawer, which only stores changes in todo states.
    – gusbrs
    Commented May 11 at 0:51
  • ok, it seems that (customize-set-variable 'org-log-into-drawer t) does not update the planning line. So, I can't have the cake and eat it, too? Commented May 11 at 8:56
  • 1
    @JasonHunter I think you are just mixing up two different things. "CLOSED" is not logged in the drawer, the done keyword is (unless you have a todo keyword named "CLOSED"...). On the other hand, whenever (if you enable org-log-done, that is) an entry goes from an open state into a "done" state, the planning line receives the "CLOSED" timestamp. And that's what defines the time the entry has been closed for Org.
    – gusbrs
    Commented May 11 at 11:32
  • Indeed, I figured it out the same time you wrote it;). Great, thanks;) Commented May 11 at 11:36
1

In the agenda dispatcher view (i.e. after C-c a if you have customized the setting as the manual suggests - or after M-x org-agenda), select m for a query to match tags/properties/todo and specify the following entry:

TODO="DONE"&CLOSED>="<-1w>"

That should give you a list of DONE items that were CLOSED in the past week. I don't think it's sorted though and I don't remember how to sort that view (or even if it is possible). Untested.

EDIT: I tested in response to the comment. Here's an example Org mode file (/tmp/foo.org):

#+STARTUP: logdone

* DONE one
CLOSED: [2024-05-03 Fri 14:17]
:PROPERTIES:
:VISIBILITY: folded
:END:

* DONE two
CLOSED: [2024-05-06 Mon 14:17]
:PROPERTIES:
:VISIBILITY: folded
:END:

* TODO three
SCHEDULED: <2024-05-11 Sat>

I start with emacs -Q /tmp/foo.org, add the file to the (empty) agenda list with C-c [ and do M-x org-agenda RET m TODO="DONE"&CLOSED>="<-1w>" RET. The result is:

Headlines with TAGS match: TODO="DONE"&CLOSED>="<-1w>"
Press ‘C-u r’ to search again
  foo:     DONE two

It shows the only item (two) that is DONE and closed during the past week. Item one was closed more than a week ago and item three is not DONE.

3
  • I tried this, but it returns no results. I have some todos with CLOSED on the planning line and I also got some CLOSED entries in the logbook drawer. None of them are shown;) Commented May 11 at 11:12
  • 1
    As @gusbrs pointed out, CLOSED in the logbook drawer does not mean anything to Org mode: it's only the planning line that matters. As for the other part of your question, you are doing something wrong: see my edit.
    – NickD
    Commented May 11 at 18:43
  • Indeed;). Thanks for that. It works perfectly. Commented May 11 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.