(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)))
(should (equal (iso8601-parse-time "15:27:35.123" t)
'((35123 . 1000) 27 15 nil nil nil nil -1 nil)))
(should (equal (iso8601-parse-time "15:27:35.123456789" t)
- '((35123456789 . 1000000000) 27 15 nil nil nil nil -1 nil))))
+ '((35123456789 . 1000000000) 27 15 nil nil nil nil -1 nil)))
+ (should (equal (iso8601-parse-time "15:27:35.012345678" t)
+ '((35012345678 . 1000000000) 27 15 nil nil nil nil -1 nil)))
+ (should (equal (iso8601-parse-time "15:27:35.00001" t)
+ '((3500001 . 100000) 27 15 nil nil nil nil -1 nil)))
+ (should (equal (iso8601-parse-time "15:27:35.0000100" t)
+ '((3500001 . 100000) 27 15 nil nil nil nil -1 nil)))
+ (should (equal (iso8601-parse-time "15:27:35.0" t)
+ '(35 27 15 nil nil nil nil -1 nil))))
(ert-deftest standard-test-time-of-day-beginning-of-day ()
(should (equal (iso8601-parse-time "000000")