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)) (post-blank (progn (goto-char (match-end 0))
(skip-chars-forward " \t"))) (skip-chars-forward " \t")))
(end (point)) (end (point))
(with-time-p (string-match "[012]?[0-9]:[0-5][0-9]" date-start))
(repeater-props (repeater-props
(and (not diaryp) (and (not diaryp)
(string-match "\\([.+]?\\+\\)\\([0-9]+\\)\\([hdwmy]\\)>" (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))) (setq date-start (replace-match "" nil nil date-start 1)))
;; Parse date-start. ;; Parse date-start.
(unless diaryp (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) (setq year-start (nth 5 date)
month-start (nth 4 date) month-start (nth 4 date)
day-start (nth 3 date) day-start (nth 3 date)
hour-start (and with-time-p (nth 2 date)) hour-start (nth 2 date)
minute-start (and with-time-p (nth 1 date))))) minute-start (nth 1 date))))
;; Compute date-end. It can be provided directly in time-stamp, ;; Compute date-end. It can be provided directly in time-stamp,
;; or extracted from time range. Otherwise, it defaults to the ;; or extracted from time range. Otherwise, it defaults to the
;; same values as date-start. ;; same values as date-start.
(unless diaryp (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) (setq year-end (or (nth 5 date) year-start)
month-end (or (nth 4 date) month-start) month-end (or (nth 4 date) month-start)
day-end (or (nth 3 date) day-start) day-end (or (nth 3 date) day-start)

View File

@ -1718,9 +1718,14 @@ Outside list"
(should (should
(org-test-with-temp-text "<2012-03-29 16:40>" (org-test-with-temp-text "<2012-03-29 16:40>"
(eq (org-element-property :type (org-element-context)) 'active))) (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 (should
(equal '(2012 3 29 16 40) (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))) (let ((object (org-element-context)))
(list (org-element-property :year-start object) (list (org-element-property :year-start object)
(org-element-property :month-start object) (org-element-property :month-start object)
@ -1729,12 +1734,12 @@ Outside list"
(org-element-property :minute-start object)))))) (org-element-property :minute-start object))))))
;; Inactive timestamp. ;; Inactive timestamp.
(should (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))) (eq (org-element-property :type (org-element-context)) 'inactive)))
;; Time range. ;; Time range.
(should (should
(equal '(2012 3 29 16 40 7 30) (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))) (let ((object (org-element-context)))
(list (org-element-property :year-end object) (list (org-element-property :year-end object)
(org-element-property :month-end object) (org-element-property :month-end object)
@ -1745,16 +1750,21 @@ Outside list"
(org-element-property :minute-start object)))))) (org-element-property :minute-start object))))))
;; Date range. ;; Date range.
(should (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))) (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. ;; With repeater.
(should (should
(eq 'catch-up (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))))) (org-element-property :repeater-type (org-element-context)))))
;; Timestamps are not planning elements. ;; Timestamps are not planning elements.
(should-not (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)))) (org-element-map (org-element-parse-buffer) 'timestamp 'identity))))