Browse Source

org-duration: Fix bug with decimal units

* lisp/org-duration.el (org-duration-to-minutes): Fix bug where the
  same unit with a decimal unit would be matched multiple times.
* testing/lisp/test-org-duration.el (test-org-duration/to-minutes):
  Fix test.
Nicolas Goaziou 8 years ago
parent
commit
b1353cb6f8
2 changed files with 4 additions and 3 deletions
  1. 3 2
      lisp/org-duration.el
  2. 1 1
      testing/lisp/test-org-duration.el

+ 3 - 2
lisp/org-duration.el

@@ -285,8 +285,9 @@ not recognized."
       (+ (/ (or seconds 0) 60.0) minutes (* 60 hours))))
    ((string-match-p org-duration--full-re duration)
     (let ((minutes 0)
-	  (s -1))
-      (while (setq s (string-match org-duration--unit-re duration (1+ s)))
+	  (s 0))
+      (while (string-match org-duration--unit-re duration s)
+	(setq s (match-end 0))
 	(let ((value (string-to-number (match-string 1 duration)))
 	      (unit (match-string 2 duration)))
 	  (cl-incf minutes (* value (org-duration--modifier unit canonical)))))

+ 1 - 1
testing/lisp/test-org-duration.el

@@ -30,7 +30,7 @@
   (should (= (org-duration-to-minutes "1:20:30") 80.5))
   (should (= (org-duration-to-minutes "2h 10min") 130))
   (should (= (org-duration-to-minutes "1d 1:02") 1502))
-  (should (= (org-duration-to-minutes "2.5h") 450))
+  (should (= (org-duration-to-minutes "2.5h") 150))
   ;; Special case: a bare number is treated as minutes.
   (should (= (org-duration-to-minutes "2") 2))
   (should (= (org-duration-to-minutes "2.5") 2.5))