summaryrefslogtreecommitdiff
path: root/lisp/calendar/iso8601.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-06-14 15:32:03 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2021-06-14 15:32:03 +0200
commit00f1a4be719cab4f1a3591ab3321ff34c86af86b (patch)
tree5d6a8a785b8d34fbac4ea919d7be89606289a4d6 /lisp/calendar/iso8601.el
parent663fb3b774887d3d15a6791c3f35af56daa3c676 (diff)
downloademacs-00f1a4be719cab4f1a3591ab3321ff34c86af86b.tar.gz
emacs-00f1a4be719cab4f1a3591ab3321ff34c86af86b.tar.bz2
emacs-00f1a4be719cab4f1a3591ab3321ff34c86af86b.zip
Get fractional seconds in iso8601 parsing right
* lisp/calendar/iso8601.el (iso8601-parse-time): Get fractional times (with leading zeroes in the fraction part) right (bug#49017). Fix based on a patch by "J.P." <jp@neverwas.me>.
Diffstat (limited to 'lisp/calendar/iso8601.el')
-rw-r--r--lisp/calendar/iso8601.el17
1 files changed, 11 insertions, 6 deletions
diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el
index 44c48119845..f22f060e205 100644
--- a/lisp/calendar/iso8601.el
+++ b/lisp/calendar/iso8601.el
@@ -231,17 +231,22 @@ See `decode-time' for the meaning of FORM."
(string-to-number (match-string 2 time))))
(second (and (match-string 3 time)
(string-to-number (match-string 3 time))))
- (fraction (and (not (zerop (length (match-string 4 time))))
- (string-to-number (match-string 4 time)))))
+ (frac-string (match-string 4 time))
+ fraction fraction-precision)
+ (when frac-string
+ ;; Remove trailing zeroes.
+ (setq frac-string (replace-regexp-in-string "0+\\'" "" frac-string))
+ (when (length> frac-string 0)
+ (setq fraction (string-to-number frac-string)
+ fraction-precision (length frac-string))))
(when (and fraction
(eq form t))
(cond
;; Sub-second time.
(second
- (let ((digits (1+ (truncate (log fraction 10)))))
- (setq second (cons (+ (* second (expt 10 digits))
- fraction)
- (expt 10 digits)))))
+ (setq second (cons (+ (* second (expt 10 fraction-precision))
+ fraction)
+ (expt 10 fraction-precision))))
;; Fractional minute.
(minute
(setq second (iso8601--decimalize fraction 60)))