org-element: Fix interpreter for timestamp with delay

* lisp/org-element.el (org-element-timestamp-interpreter): Correctly
  interpret timestamps with delays.
* testing/lisp/test-org-element.el: Add test.
This commit is contained in:
Nicolas Goaziou 2013-10-13 18:13:35 +02:00
parent 11514badc1
commit 92c2ccb1fb
2 changed files with 29 additions and 11 deletions

View File

@ -3660,12 +3660,12 @@ CONTENTS is nil."
(hour "h") (day "d") (week "w") (month "m") (year "y"))))
(warning-string
(concat
(and (eq (org-element-property :warninger-type timestamp) 'first)
"-")
"-"
(let ((val (org-element-property :warninger-value timestamp)))
(case (org-element-property :warning-type timestamp)
(first "--")
(all "-"))
(let ((val (org-element-property :warning-value timestamp)))
(and val (number-to-string val)))
(case (org-element-property :warninger-unit timestamp)
(case (org-element-property :warning-unit timestamp)
(hour "h") (day "d") (week "w") (month "m") (year "y"))))
(build-ts-string
;; Build an Org timestamp string from TIME. ACTIVEP is
@ -3685,11 +3685,12 @@ CONTENTS is nil."
(format "\\&-%02d:%02d" hour-end minute-end)
nil nil ts)))
(unless activep (setq ts (format "[%s]" (substring ts 1 -1))))
(when (org-string-nw-p repeat-string)
(setq ts (concat (substring ts 0 -1)
" "
repeat-string
(substring ts -1))))
(dolist (s (list repeat-string warning-string))
(when (org-string-nw-p s)
(setq ts (concat (substring ts 0 -1)
" "
s
(substring ts -1)))))
;; Return value.
ts)))
(type (org-element-property :type timestamp)))

View File

@ -2456,7 +2456,7 @@ DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01> CLOSED: [2012-01-01]\n"))))
;; Diary.
(should (equal (org-test-parse-and-interpret "<%%diary-float t 4 2>")
"<%%diary-float t 4 2>\n"))
;; Timestamp with repeater interval.
;; Timestamp with repeater interval, with delay, with both.
(should (equal (org-test-parse-and-interpret "<2012-03-29 thu. +1y>")
"<2012-03-29 thu. +1y>\n"))
(should
@ -2467,6 +2467,23 @@ DEADLINE: <2012-01-01> SCHEDULED: <2012-01-01> CLOSED: [2012-01-01]\n"))))
(:type active :year-start 2012 :month-start 3 :day-start 29
:repeater-type cumulate :repeater-value 1 :repeater-unit year))
nil)))
(should
(string-match
"<2012-03-29 .* -1y>"
(org-element-timestamp-interpreter
'(timestamp
(:type active :year-start 2012 :month-start 3 :day-start 29
:warning-type all :warning-value 1 :warning-unit year))
nil)))
(should
(string-match
"<2012-03-29 .* \\+1y -1y>"
(org-element-timestamp-interpreter
'(timestamp
(:type active :year-start 2012 :month-start 3 :day-start 29
:warning-type all :warning-value 1 :warning-unit year
:repeater-type cumulate :repeater-value 1 :repeater-unit year))
nil)))
;; Timestamp range with repeater interval
(should (equal (org-test-parse-and-interpret
"<2012-03-29 Thu +1y>--<2012-03-30 Thu +1y>")