summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-11-15 20:46:08 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-11-22 21:32:48 (GMT)
commitcb32494e246edf27b090ea54326f11f1a6e155f9 (patch)
treedfb3c2107235cf8258f93cf961e5bb11841cc256
parent68234d5a410c01ad9457f746bbd1f3d7fdfb0245 (diff)
downloadorg-mode-cb32494e246edf27b090ea54326f11f1a6e155f9.zip
org-mode-cb32494e246edf27b090ea54326f11f1a6e155f9.tar.gz
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))
-rw-r--r--lisp/org-element.el31
-rw-r--r--testing/lisp/test-org-element.el20
2 files changed, 26 insertions, 25 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 508b5fd..9ac4488 100644
--- a/lisp/org-element.el
+++ b/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)))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index e991f80..d19ce2a 100644
--- a/testing/lisp/test-org-element.el
+++ b/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))))