From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tassilo Horn 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 Message-ID: <87bp3t7oby.fsf_-_@member.fsf.org> References: <87k4ijzevd.fsf@member.fsf.org> <87pqsb6zyv.fsf@mean.albasani.net> <87mxneb27m.fsf@member.fsf.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=41724 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pawj6-0000UV-0X for emacs-orgmode@gnu.org; Thu, 06 Jan 2011 15:46:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pawj3-00054t-8z for emacs-orgmode@gnu.org; Thu, 06 Jan 2011 15:46:26 -0500 Received: from lo.gmane.org ([80.91.229.12]:56026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pawj2-00054l-Tt for emacs-orgmode@gnu.org; Thu, 06 Jan 2011 15:46:25 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Pawj1-0003nt-7b for emacs-orgmode@gnu.org; Thu, 06 Jan 2011 21:46:23 +0100 Received: from 95-88-32-105-dynip.superkabel.de ([95.88.32.105]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 06 Jan 2011 21:46:23 +0100 Received: from tassilo by 95-88-32-105-dynip.superkabel.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 06 Jan 2011 21:46:23 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.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