summaryrefslogtreecommitdiff
path: root/lisp/org/org-duration.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2022-11-29 23:05:53 -0500
committerKyle Meyer <kyle@kyleam.com>2022-11-29 23:05:53 -0500
commit0625651e8a61c9effc31ff771f15885a3a37c6e6 (patch)
treedb4c09e8ef119ad4a9a4028c5e615fd58d2dee69 /lisp/org/org-duration.el
parentedd64e64a389e0f0e6ce670846d4fae79a9d8b35 (diff)
downloademacs-0625651e8a61c9effc31ff771f15885a3a37c6e6.tar.gz
emacs-0625651e8a61c9effc31ff771f15885a3a37c6e6.tar.bz2
emacs-0625651e8a61c9effc31ff771f15885a3a37c6e6.zip
Update to Org 9.6-3-ga4d38e
Diffstat (limited to 'lisp/org/org-duration.el')
-rw-r--r--lisp/org/org-duration.el54
1 files changed, 29 insertions, 25 deletions
diff --git a/lisp/org/org-duration.el b/lisp/org/org-duration.el
index 6d55ba88408..6d6b8b5cf1d 100644
--- a/lisp/org/org-duration.el
+++ b/lisp/org/org-duration.el
@@ -51,6 +51,9 @@
;;; Code:
+(require 'org-macs)
+(org-assert-version)
+
(require 'cl-lib)
(require 'org-macs)
@@ -98,7 +101,7 @@ sure to call the following command:
:version "26.1"
:package-version '(Org . "9.1")
:set (lambda (var val)
- (set-default var val)
+ (set-default-toplevel-value var val)
;; Avoid recursive load at startup.
(when (featurep 'org-duration)
(org-duration-set-regexps)))
@@ -284,30 +287,31 @@ 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)
- (mapcar #'string-to-number (split-string duration ":"))))
- (+ (/ (or seconds 0) 60.0) minutes (* 60 hours))))
- ((string-match-p org-duration--full-re duration)
- (let ((minutes 0)
- (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)))))
- (float minutes)))
- ((string-match org-duration--mixed-re duration)
- (let ((units-part (match-string 1 duration))
- (hms-part (match-string 2 duration)))
- (+ (org-duration-to-minutes units-part)
- (org-duration-to-minutes hms-part))))
- ((string-match-p "\\`[0-9]+\\(\\.[0-9]*\\)?\\'" duration)
- (float (string-to-number duration)))
- (t (error "Invalid duration format: %S" duration))))
+ (save-match-data
+ (cond
+ ((equal duration "") 0.0)
+ ((numberp duration) (float duration))
+ ((string-match-p org-duration--h:mm-re duration)
+ (pcase-let ((`(,hours ,minutes ,seconds)
+ (mapcar #'string-to-number (split-string duration ":"))))
+ (+ (/ (or seconds 0) 60.0) minutes (* 60 hours))))
+ ((string-match-p org-duration--full-re duration)
+ (let ((minutes 0)
+ (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)))))
+ (float minutes)))
+ ((string-match org-duration--mixed-re duration)
+ (let ((units-part (match-string 1 duration))
+ (hms-part (match-string 2 duration)))
+ (+ (org-duration-to-minutes units-part)
+ (org-duration-to-minutes hms-part))))
+ ((string-match-p "\\`[0-9]+\\(\\.[0-9]*\\)?\\'" duration)
+ (float (string-to-number duration)))
+ (t (error "Invalid duration format: %S" duration)))))
;;;###autoload
(defun org-duration-from-minutes (minutes &optional fmt canonical)