Browse Source

org-element: Timestamp with time range has active/inactive-range type

* lisp/org-element.el (org-element-timestamp-parser): Timestamp with
  time range has active/inactive-range type.
* testing/lisp/test-org-element.el: Add test.

In order to know if starting date/time is really the same as ending
date/time, this patch permits to use the following:

  (memq (org-element-property :type timestamp) '(active inactive))
Nicolas Goaziou 12 years ago
parent
commit
cb32494e24
2 changed files with 26 additions and 25 deletions
  1. 14 17
      lisp/org-element.el
  2. 12 8
      testing/lisp/test-org-element.el

+ 14 - 17
lisp/org-element.el

@@ -3441,14 +3441,21 @@ Assume point is at the beginning of the timestamp."
 	   (date-start (match-string-no-properties 1))
 	   (date-end (match-string 3))
 	   (diaryp (match-beginning 2))
-	   (type (cond (diaryp 'diary)
-		       ((and activep date-end) 'active-range)
-		       (activep 'active)
-		       (date-end 'inactive-range)
-		       (t 'inactive)))
 	   (post-blank (progn (goto-char (match-end 0))
 			      (skip-chars-forward " \t")))
 	   (end (point))
+	   (time-range
+	    (and (not diaryp)
+		 (string-match
+		  "[012]?[0-9]:[0-5][0-9]\\(-\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)"
+		  date-start)
+		 (cons (string-to-number (match-string 2 date-start))
+		       (string-to-number (match-string 3 date-start)))))
+	   (type (cond (diaryp 'diary)
+		       ((and activep (or date-end time-range)) 'active-range)
+		       (activep 'active)
+		       ((or date-end time-range) 'inactive-range)
+		       (t 'inactive)))
 	   (repeater-props
 	    (and (not diaryp)
 		 (string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)>"
@@ -3463,18 +3470,8 @@ Assume point is at the beginning of the timestamp."
 		  :repeater-unit
 		  (case (string-to-char (match-string 3 raw-value))
 		    (?h 'hour) (?d 'day) (?w 'week) (?m 'month) (t 'year)))))
-	   time-range year-start month-start day-start hour-start minute-start
-	   year-end month-end day-end hour-end minute-end)
-      ;; Extract time range, if any, and remove it from date start.
-      (setq time-range
-	    (and (not diaryp)
-		 (string-match
-		  "[012]?[0-9]:[0-5][0-9]\\(-\\([012]?[0-9]\\):\\([0-5][0-9]\\)\\)"
-		  date-start)
-		 (cons (string-to-number (match-string 2 date-start))
-		       (string-to-number (match-string 3 date-start)))))
-      (when time-range
-	(setq date-start (replace-match "" nil nil date-start 1)))
+	   year-start month-start day-start hour-start minute-start year-end
+	   month-end day-end hour-end minute-end)
       ;; Parse date-start.
       (unless diaryp
 	(let ((date (org-parse-time-string date-start t)))

+ 12 - 8
testing/lisp/test-org-element.el

@@ -1719,13 +1719,13 @@ Outside list"
    (org-test-with-temp-text "<2012-03-29 16:40>"
      (eq (org-element-property :type (org-element-context)) 'active)))
   (should-not
-   (org-test-with-temp-text "<2012-03-29 Thu.>"
+   (org-test-with-temp-text "<2012-03-29 Thu>"
      (let ((timestamp (org-element-context)))
        (or (org-element-property :hour-start timestamp)
 	   (org-element-property :minute-start timestamp)))))
   (should
    (equal '(2012 3 29 16 40)
-	  (org-test-with-temp-text "<2012-03-29 Thu. 16:40>"
+	  (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
 	    (let ((object (org-element-context)))
 	      (list (org-element-property :year-start object)
 		    (org-element-property :month-start object)
@@ -1734,12 +1734,12 @@ Outside list"
 		    (org-element-property :minute-start object))))))
   ;; Inactive timestamp.
   (should
-   (org-test-with-temp-text "[2012-03-29 Thu. 16:40]"
+   (org-test-with-temp-text "[2012-03-29 Thu 16:40]"
      (eq (org-element-property :type (org-element-context)) 'inactive)))
   ;; Time range.
   (should
    (equal '(2012 3 29 16 40 7 30)
-	  (org-test-with-temp-text "<2012-03-29 Thu. 7:30-16:40>"
+	  (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
 	    (let ((object (org-element-context)))
 	      (list (org-element-property :year-end object)
 		    (org-element-property :month-end object)
@@ -1748,23 +1748,27 @@ Outside list"
 		    (org-element-property :minute-end object)
 		    (org-element-property :hour-start object)
 		    (org-element-property :minute-start object))))))
+  (should
+   (eq 'active-range
+       (org-test-with-temp-text "<2012-03-29 Thu 7:30-16:40>"
+	 (org-element-property :type (org-element-context)))))
   ;; Date range.
   (should
-   (org-test-with-temp-text "[2012-03-29 Thu. 16:40]--[2012-03-29 Thu. 16:41]"
+   (org-test-with-temp-text "[2012-03-29 Thu 16:40]--[2012-03-29 Thu 16:41]"
      (eq (org-element-property :type (org-element-context)) 'inactive-range)))
   (should-not
-   (org-test-with-temp-text "[2011-07-14 Thu.]--[2012-03-29 Thu.]"
+   (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
      (let ((timestamp (org-element-context)))
        (or (org-element-property :hour-end timestamp)
 	   (org-element-property :minute-end timestamp)))))
   ;; With repeater.
   (should
    (eq 'catch-up
-       (org-test-with-temp-text "<2012-03-29 Thu. ++1y>"
+       (org-test-with-temp-text "<2012-03-29 Thu ++1y>"
 	 (org-element-property :repeater-type (org-element-context)))))
   ;; Timestamps are not planning elements.
   (should-not
-   (org-test-with-temp-text "SCHEDULED: <2012-03-29 Thu. 16:40>"
+   (org-test-with-temp-text "SCHEDULED: <2012-03-29 Thu 16:40>"
      (org-element-map (org-element-parse-buffer) 'timestamp 'identity))))