emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tassilo Horn <tassilo@member.fsf.org>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Properly format start and end times in time ranges. (was: Display of time/date ranges in the agenda)
Date: Thu, 06 Jan 2011 21:46:09 +0100	[thread overview]
Message-ID: <87bp3t7oby.fsf_-_@member.fsf.org> (raw)
In-Reply-To: 87mxneb27m.fsf@member.fsf.org

* org-agenda.el (org-format-agenda-item): Properly format start and
end times in time ranges, i.e., print the start time of the start
date, no times for intermediate dates, and the end time with
preceeding dots for the end date.

With this patch, an entry with time range like this

--8<---------------cut here---------------start------------->8---
** TESTENTRY
   <2011-01-07 Fri 19:05>--<2011-01-09 Sun 16:25>
--8<---------------cut here---------------end--------------->8---

is shown in the agenda as follows:

--8<---------------cut here---------------start------------->8---
Friday      7 January 2011
  private:    19:05...... (1/3):  TESTENTRY
Saturday    8 January 2011
  private:    ........... (2/3):  TESTENTRY
Sunday      9 January 2011
  private:    ......16:25 (3/3):  TESTENTRY
--8<---------------cut here---------------end--------------->8---

Before, "19:05......" was used for all days of the entry.
---
 lisp/org-agenda.el |   45 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index bf36758..3a20e2a 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -5164,12 +5164,39 @@ Any match of REMOVE-RE will be removed from TXT."
 	   (ts (if dotime (concat
 			   (if (stringp dotime) dotime "")
 			   (and org-agenda-search-headline-for-time txt))))
-	   (time-of-day (and dotime (org-get-time-of-day ts)))
+	   timerange
+	   (time-of-day (and dotime
+			     (cond
+			      ;; Time ranges
+			      ((string-match "\\(<.*>\\)--\\(<.*>\\)" ts)
+			       (let* ((start (match-string 1 ts))
+				      (end (match-string 2 ts))
+				      (starttime (let ((time (org-parse-time-string start)))
+						   (list (nth 4 time)
+							 (nth 3 time)
+							 (nth 5 time))))
+				      (endtime (let ((time (org-parse-time-string end)))
+						 (list (nth 4 time)
+						       (nth 3 time)
+						       (nth 5 time)))))
+				 (catch 'tod
+				   (when (equal date starttime)
+				     (setq timerange 'start)
+				     (setq time (org-get-time-of-day start 'string))
+				     (throw 'tod (org-get-time-of-day start)))
+				   (when (equal date endtime)
+				     (setq timerange 'end)
+				     (setq time (org-get-time-of-day end 'string))
+				     (throw 'tod (org-get-time-of-day end)))
+				   ;; Don't show a time for in-between dates
+				   (setq timerange 'inbetween)
+				   (throw 'tod nil))))
+			      (t (org-get-time-of-day ts)))))
 	   stamp plain s0 s1 s2 t1 t2 rtn srp l
 	   duration thecategory)
       (and (org-mode-p) buffer-file-name
 	   (add-to-list 'org-agenda-contributing-files buffer-file-name))
-      (when (and dotime time-of-day)
+      (when (and dotime time-of-day (not timerange))
 	;; Extract starting and ending time and move them to prefix
 	(when (or (setq stamp (string-match org-stamp-time-of-day-regexp ts))
 		  (setq plain (string-match org-plain-time-of-day-regexp ts)))
@@ -5243,7 +5270,19 @@ Any match of REMOVE-RE will be removed from TXT."
       (if noprefix
 	  (setq rtn txt)
 	;; Prepare the variables needed in the eval of the compiled format
-	(setq time (cond (s2 (concat
+	(setq time (cond ((eq timerange 'start)
+			  (concat (org-agenda-time-of-day-to-ampm-maybe time)
+				  (if org-agenda-timegrid-use-ampm
+				      "........ "
+				    "......")))
+			 ((eq timerange 'end)
+			  (concat (if org-agenda-timegrid-use-ampm
+				      "........ "
+				    "......")
+				  (org-agenda-time-of-day-to-ampm-maybe time)))
+			 ((eq timerange 'inbetween)
+			  "........... ")
+			 (s2 (concat
 			      (org-agenda-time-of-day-to-ampm-maybe s1)
 			      "-" (org-agenda-time-of-day-to-ampm-maybe s2)
 			      (if org-agenda-timegrid-use-ampm " ")))
-- 
1.7.4.rc1

  reply	other threads:[~2011-01-06 20:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-05 12:58 Display of time/date ranges in the agenda Tassilo Horn
2011-01-05 16:46 ` Michael Brand
2011-01-05 17:15 ` Memnon Anon
2011-01-06  0:50   ` suvayu ali
2011-01-06 13:18   ` Tassilo Horn
2011-01-06 20:46     ` Tassilo Horn [this message]
2011-02-13  0:40       ` [PATCH] Properly format start and end times in time ranges Bastien
2011-02-13 10:08         ` Tassilo Horn
2011-02-13 10:33           ` Bastien
2011-02-13 11:16             ` Tassilo Horn
2011-02-13 13:43               ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bp3t7oby.fsf_-_@member.fsf.org \
    --to=tassilo@member.fsf.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).