org-element: Return nil for unspecified time values

* lisp/org-element.el (org-element-timestamp-parser): Return nil for
  unspecified :hour-end and :minute-end properties.
* testing/lisp/test-org-element.el: Add tests.
This commit is contained in:
Nicolas Goaziou 2012-11-15 21:02:26 +01:00
parent aa7dbec775
commit b46b5d1c44
2 changed files with 20 additions and 11 deletions

View File

@ -3449,7 +3449,6 @@ Assume point is at the beginning of the timestamp."
(post-blank (progn (goto-char (match-end 0))
(skip-chars-forward " \t")))
(end (point))
(with-time-p (string-match "[012]?[0-9]:[0-5][0-9]" date-start))
(repeater-props
(and (not diaryp)
(string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)>"
@ -3478,17 +3477,17 @@ Assume point is at the beginning of the timestamp."
(setq date-start (replace-match "" nil nil date-start 1)))
;; Parse date-start.
(unless diaryp
(let ((date (org-parse-time-string date-start)))
(let ((date (org-parse-time-string date-start t)))
(setq year-start (nth 5 date)
month-start (nth 4 date)
day-start (nth 3 date)
hour-start (and with-time-p (nth 2 date))
minute-start (and with-time-p (nth 1 date)))))
hour-start (nth 2 date)
minute-start (nth 1 date))))
;; Compute date-end. It can be provided directly in time-stamp,
;; or extracted from time range. Otherwise, it defaults to the
;; same values as date-start.
(unless diaryp
(let ((date (and date-end (org-parse-time-string date-end))))
(let ((date (and date-end (org-parse-time-string date-end t))))
(setq year-end (or (nth 5 date) year-start)
month-end (or (nth 4 date) month-start)
day-end (or (nth 3 date) day-start)

View File

@ -1718,9 +1718,14 @@ Outside list"
(should
(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.>"
(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 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)
@ -1729,12 +1734,12 @@ Outside list"
(org-element-property :minute-start object))))))
;; Inactive timestamp.
(should
(org-test-with-temp-text "[2012-03-29 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 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)
@ -1745,16 +1750,21 @@ Outside list"
(org-element-property :minute-start object))))))
;; Date range.
(should
(org-test-with-temp-text "[2012-03-29 16:40]--[2012-03-29 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.]"
(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 ++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 16:40>"
(org-test-with-temp-text "SCHEDULED: <2012-03-29 Thu. 16:40>"
(org-element-map (org-element-parse-buffer) 'timestamp 'identity))))