* 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


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to