org-duration-from-minutes: Accept negative durations

* lisp/org-duration.el (org-duration-from-minutes): Allow MINUTES
argument to be negative.

Reported-by: Raffael Stocker <r.stocker@mnet-mail.de>
Link: https://orgmode.org/list/yplmzfsrqjw6.fsf@mnet-mail.de
This commit is contained in:
Ihor Radchenko 2024-05-17 14:43:04 +03:00
parent 288c7069c4
commit ee58259bc7
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 104 additions and 103 deletions

View File

@ -324,6 +324,7 @@ When optional argument CANONICAL is non-nil, ignore
`org-duration-units' and use standard time units value. `org-duration-units' and use standard time units value.
Raise an error if expected format is unknown." Raise an error if expected format is unknown."
(if (< minutes 0) (concat "-" (org-duration-from-minutes (abs minutes) fmt canonical))
(pcase (or fmt org-duration-format) (pcase (or fmt org-duration-format)
(`h:mm (`h:mm
(format "%d:%02d" (/ minutes 60) (mod minutes 60))) (format "%d:%02d" (/ minutes 60) (mod minutes 60)))
@ -426,7 +427,7 @@ Raise an error if expected format is unknown."
;; one anyway. ;; one anyway.
(t (t
(pcase-let ((`((,unit . ,_)) (last selected-units))) (pcase-let ((`((,unit . ,_)) (last selected-units)))
(concat "0" unit)))))))) (concat "0" unit)))))))))
;;;###autoload ;;;###autoload
(defun org-duration-h:mm-only-p (times) (defun org-duration-h:mm-only-p (times)