Browse Source

org-duration: Fix `org-duration-to-minutes' with the empty string

* lisp/org-duration.el (org-duration-to-minutes): Accept the empty
  string.

* testing/lisp/test-org-duration.el (test-org-duration/to-minutes):
  Add test.

For backward compatibility with `org-duration-string-to-minutes'
accept the empty string as a duration.
Nicolas Goaziou 2 years ago
parent
commit
91a76063d8
2 changed files with 5 additions and 1 deletions
  1. 3 1
      lisp/org-duration.el
  2. 2 0
      testing/lisp/test-org-duration.el

+ 3 - 1
lisp/org-duration.el

@@ -272,11 +272,13 @@ When optional argument CANONICAL is non-nil, refer to
 When optional argument CANONICAL is non-nil, ignore
 `org-duration-units' and use standard time units value.
 
-As a special case, a bare number represents minutes.
+A bare number is translated into minutes.  The empty string is
+translated into 0.0.
 
 Return value as a float.  Raise an error if duration format is
 not recognized."
   (cond
+   ((equal duration "") 0.0)
    ((numberp duration) (float duration))
    ((string-match-p org-duration--h:mm-re duration)
     (pcase-let ((`(,hours ,minutes ,seconds)

+ 2 - 0
testing/lisp/test-org-duration.el

@@ -35,6 +35,8 @@
   (should (= (org-duration-to-minutes "2") 2))
   (should (= (org-duration-to-minutes "2.5") 2.5))
   (should (= (org-duration-to-minutes 1) 1))
+  ;; Special case: the empty string is 0.0.
+  (should (= (org-duration-to-minutes "") 0.0))
   ;; Support custom units.
   (should (= 4
 	     (let ((org-duration-units '(("longmin" . 2)))