emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH 2/2] Log yesterday item today, better org-extend-today-until
@ 2011-07-21 17:56 Max Mikhanosha
  2011-07-28  8:36 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Max Mikhanosha @ 2011-07-21 17:56 UTC (permalink / raw)
  To: Org Mode List

Started using habits, which are a great addition. My only problem with
habits is that for some of them such as "workout" or "cardio", I just
don't have the energy to get to the computer in the evening and mark
them done.

Instead I do most of my planning for the day in the first 20 minutes
or so of the morning, catching up, refiling, etc. But there is no way
to mark the habit DONE yesterday, and have the correct consistency
graph shown, without manual editing of LOGGING drawer.

There is already unfinished support for "backdating" stuff via
org-extend-today-until variable, but it does not work in the log-note
time-stamp. Following patch fixes that oversight, and adds two new
commands: (org-done-yesterday) and (org-agenda-done-yesterday), which are
exactly as their "today" counterparts, but all the timestamps and
CLOSED line will be marked as of 23:59 yesterday.

From daebd6ca8f75ad3266075a8b3ec5d3a1f411ecfb Mon Sep 17 00:00:00 2001
From: Max Mikhanosha <max@openchat.com>
Date: Thu, 21 Jul 2011 13:20:01 -0400
Subject: [PATCH 2/2] Make `org-extend-today-until' variable affect log notes, and CLOSED: line.

(org-done-yesterday), (org-agenda-done-yesterday): new functions
---
 lisp/org.el |   42 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 611672b..b0f113a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10918,6 +10918,32 @@ nil or a string to be used for the todo mark." )
 
 (defvar org-agenda-headline-snapshot-before-repeat)
 
+(defun org-current-effective-time ()
+  "Return current time adjusted for `org-extend-today-until' variable"
+  (let* ((ct (org-current-time))
+	  (dct (decode-time ct))
+	  (ct1
+	   (if (< (nth 2 dct) org-extend-today-until)
+	       (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
+	     ct)))
+    ct1))
+
+(defun org-todo-yesterday (&optional arg)
+  "Like `org-todo' but the time of change will be 23:59 of yesterday"
+  (interactive "P")
+  (let* ((hour (third (decode-time
+                       (org-current-time))))
+         (org-extend-today-until (1+ hour)))
+    (org-todo arg)))
+
+(defun org-agenda-todo-yesterday (&optional arg)
+  "Like `org-agenda-todo' but the time of change will be 23:59 of yesterday"
+  (interactive "P")
+  (let* ((hour (third (decode-time
+                       (org-current-time))))
+         (org-extend-today-until (1+ hour)))
+    (org-agenda-todo arg)))
+
 (defun org-todo (&optional arg)
   "Change the TODO state of an item.
 The state of an item is given by a keyword at the start of the heading,
@@ -11097,7 +11123,7 @@ For calling through lisp, arg is also interpreted in the following way:
 	      (org-add-planning-info nil nil 'closed))
 	    (when (and now-done-p org-log-done)
 	      ;; It is now done, and it was not done before
-	      (org-add-planning-info 'closed (org-current-time))
+	      (org-add-planning-info 'closed (org-current-effective-time))
 	      (if (and (not dolog) (eq 'note org-log-done))
 		  (org-add-log-setup 'done state this 'findpos 'note)))
 	    (when (and state dolog)
@@ -11638,7 +11664,7 @@ This function is run automatically after each state change to a DONE state."
 	     ((equal (match-string 1 ts) ".")
 	      ;; Shift starting date to today
 	      (org-timestamp-change
-	       (- (time-to-days (current-time)) (time-to-days time))
+	       (- (org-today) (time-to-days time))
 	       'day))
 	     ((equal (match-string 1 ts) "+")
 	      (let ((nshiftmax 10) (nshift 0))
@@ -11909,6 +11935,11 @@ be removed."
 (defvar org-log-note-extra nil)
 (defvar org-log-note-window-configuration nil)
 (defvar org-log-note-return-to (make-marker))
+(defvar org-log-note-effective-time nil
+  "Remembered current time so that dynamically scoped
+`org-extend-today-until' affects tha timestamps in state change
+log")
+
 (defvar org-log-post-message nil
   "Message to be displayed after a log note has been stored.
 The auto-repeater uses this.")
@@ -11976,7 +12007,8 @@ EXTRA is additional text that will be inserted into the notes buffer."
 	      org-log-note-state state
 	      org-log-note-previous-state prev-state
 	      org-log-note-how how
-	      org-log-note-extra extra)
+	      org-log-note-extra extra
+	      org-log-note-effective-time (org-current-effective-time))
 	(add-hook 'post-command-hook 'org-add-log-note 'append)))))
 
 (defun org-skip-over-state-notes ()
@@ -12047,10 +12079,10 @@ EXTRA is additional text that will be inserted into the notes buffer."
 		   (cons "%U" user-full-name)
 		   (cons "%t" (format-time-string
 			       (org-time-stamp-format 'long 'inactive)
-			       (current-time)))
+			       org-log-note-effective-time))
 		   (cons "%T" (format-time-string
 			       (org-time-stamp-format 'long nil)
-			       (current-time)))
+			       org-log-note-effective-time))
 		   (cons "%s" (if org-log-note-state
 				  (concat "\"" org-log-note-state "\"")
 				""))
-- 
1.7.3.4

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

* Re: [PATCH 2/2] Log yesterday item today, better org-extend-today-until
  2011-07-21 17:56 [PATCH 2/2] Log yesterday item today, better org-extend-today-until Max Mikhanosha
@ 2011-07-28  8:36 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2011-07-28  8:36 UTC (permalink / raw)
  To: Max Mikhanosha; +Cc: Org Mode List

Hi Max,

Max Mikhanosha <max@openchat.com> writes:

> There is already unfinished support for "backdating" stuff via
> org-extend-today-until variable, but it does not work in the log-note
> time-stamp. Following patch fixes that oversight, and adds two new
> commands: (org-done-yesterday) and (org-agenda-done-yesterday), which are
> exactly as their "today" counterparts, but all the timestamps and
> CLOSED line will be marked as of 23:59 yesterday.

I've now tested and applied this patch, thanks a lot for it.

I guess the warning in `org-extend-today-until' is a bit obsolete :)

Best,

-- 
 Bastien

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

end of thread, other threads:[~2011-07-28  8:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-21 17:56 [PATCH 2/2] Log yesterday item today, better org-extend-today-until Max Mikhanosha
2011-07-28  8:36 ` Bastien

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