diff options
author | Bastien Guerry <bzg@altern.org> | 2012-12-30 10:27:02 +0100 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2012-12-30 10:27:02 +0100 |
commit | e1c491e72de45074206b24eea6170a926858a7ac (patch) | |
tree | aa8282dfee029255bb437233a485bd00beca2685 | |
parent | 460c4d4ed052329d349ead9476b21d19ab3a0692 (diff) | |
download | org-mode-e1c491e72de45074206b24eea6170a926858a7ac.tar.gz |
org.el (org-parse-time-string): Parse <+1w> and friends
* org.el (org-parse-time-string): Allow strings supported by
tags/properties matcher (eg <now>, <yesterday>, <-7d>).
* test-org.el (test-org/org-parse-time-string): New test.
This is based on Ilya's commit 001bcb9. This commit was
wrong because active timestamps were not parsed correctly
anymore. This commit handles them correctly.
Thanks to Ivan Vilata i Balaguer for pushing this forward.
-rw-r--r-- | lisp/org.el | 24 | ||||
-rw-r--r-- | testing/lisp/test-org.el | 14 |
2 files changed, 26 insertions, 12 deletions
diff --git a/lisp/org.el b/lisp/org.el index 9f816e5..0549c79 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16538,17 +16538,19 @@ When SHOW-ALL is nil, only return the current occurrence of a time stamp." This should be a lot faster than the normal `parse-time-string'. If time is not given, defaults to 0:00. However, with optional NODEFAULT, hour and minute fields will be nil if not given." - (if (string-match org-ts-regexp0 s) - (list 0 - (if (or (match-beginning 8) (not nodefault)) - (string-to-number (or (match-string 8 s) "0"))) - (if (or (match-beginning 7) (not nodefault)) - (string-to-number (or (match-string 7 s) "0"))) - (string-to-number (match-string 4 s)) - (string-to-number (match-string 3 s)) - (string-to-number (match-string 2 s)) - nil nil nil) - (error "Not a standard Org-mode time string: %s" s))) + (cond ((string-match org-ts-regexp0 s) + (list 0 + (if (or (match-beginning 8) (not nodefault)) + (string-to-number (or (match-string 8 s) "0"))) + (if (or (match-beginning 7) (not nodefault)) + (string-to-number (or (match-string 7 s) "0"))) + (string-to-number (match-string 4 s)) + (string-to-number (match-string 3 s)) + (string-to-number (match-string 2 s)) + nil nil nil)) + ((string-match "^<[^>]+>$" s) + (decode-time (seconds-to-time (org-matcher-time s)))) + (t (error "Not a standard Org-mode time string: %s" s)))) (defun org-timestamp-up (&optional arg) "Increase the date item at the cursor by one. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 33bec7e..10fedd7 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -88,7 +88,7 @@ -;;; Date Analysis +;;; Date and time analysis (ert-deftest test-org/org-read-date () "Test `org-read-date' specifications." @@ -105,6 +105,18 @@ (let ((org-time-was-given t)) (org-read-date t nil "29.03. 16:40"))))) +(ert-deftest test-org/org-parse-time-string () + "Test `org-parse-time-string'." + (should (equal (org-parse-time-string "2012-03-29 16:40") + '(0 40 16 29 3 2012 nil nil nil))) + (should (equal (org-parse-time-string "[2012-03-29 16:40]") + '(0 40 16 29 3 2012 nil nil nil))) + (should (equal (org-parse-time-string "<2012-03-29 16:40>") + '(0 40 16 29 3 2012 nil nil nil))) + (should (equal (org-parse-time-string "<2012-03-29>") + '(0 0 0 29 3 2012 nil nil nil))) + (should (equal (org-parse-time-string "<2012-03-29>" t) + '(0 nil nil 29 3 2012 nil nil nil)))) ;;; Filling |