From 92c2ccb1fb438064453c60ff215adad1c213218d Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 13 Oct 2013 18:13:35 +0200 Subject: [PATCH] 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. --- lisp/org-element.el | 21 +++++++++++---------- testing/lisp/test-org-element.el | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 62461f72c..f57ef1cae 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -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))) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index b124f7143..7d36ba59e 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -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>") -- 2.11.4.GIT