Ver Fonte

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.
Bastien Guerry há 12 anos atrás
pai
commit
e1c491e72d
2 ficheiros alterados com 26 adições e 12 exclusões
  1. 13 11
      lisp/org.el
  2. 13 1
      testing/lisp/test-org.el

+ 13 - 11
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.

+ 13 - 1
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