diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-08-16 22:09:04 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-08-16 23:25:07 -0700 |
commit | 37257d6acadff17bd1e52cfa460950bcb684c5c3 (patch) | |
tree | ab7088cfa725561c8456f388cff79466948b3532 /test/src | |
parent | d7c9ed8445d13de7350be3360d68717362f89929 (diff) | |
download | emacs-37257d6acadff17bd1e52cfa460950bcb684c5c3.tar.gz |
More-compatible subsecond calendrical timestamps
Instead of appending a subseconds member to the result of
‘decode-time’, this keeps the format unchanged unless you give
a new optional argument to ‘decode-time’. Also, the augmented
format now puts the subsecond info in the SECONDS element, so
the total number of elements is unchanged; this is more
compatible with code that expects the traditional 9 elements,
such as ‘(pcase decoded-time (`(,SEC ,MIN ,HOUR ,DAY ,MON
,YEAR ,DOW ,DST ,ZONE) ...) ...)’.
* doc/lispref/os.texi, doc/misc/emacs-mime.texi, etc/NEWS:
* lisp/net/soap-client.el (soap-decode-date-time):
* lisp/simple.el (decoded-time):
Document the new behavior.
* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
* lisp/calendar/iso8601.el (iso8601-parse)
(iso8601-parse-time, iso8601-parse-duration)
(iso8601--decoded-time):
* lisp/calendar/parse-time.el (parse-time-string):
* lisp/calendar/time-date.el (decoded-time-add)
(decoded-time--alter-second):
* lisp/org/org.el (org-parse-time-string):
* lisp/simple.el (decoded-time):
* src/timefns.c (Fdecode_time, Fencode_time):
* test/lisp/calendar/icalendar-tests.el:
(icalendar--decode-isodatetime):
* test/lisp/calendar/iso8601-tests.el (test-iso8601-date-years)
(test-iso8601-date-dates, test-iso8601-date-obsolete)
(test-iso8601-date-weeks, test-iso8601-date-ordinals)
(test-iso8601-time, test-iso8601-combined)
(test-iso8601-duration, test-iso8601-intervals)
(standard-test-dates, standard-test-time-of-day-fractions)
(standard-test-time-of-day-beginning-of-day)
(standard-test-time-of-day-utc)
(standard-test-time-of-day-zone)
(standard-test-date-and-time-of-day, standard-test-interval):
* test/lisp/calendar/parse-time-tests.el (parse-time-tests):
* test/src/timefns-tests.el (format-time-string-with-zone)
(encode-time-dst-numeric-zone):
Revert recent changes that added a SUBSECS member to
calendrical timestamps, since that component is no longer
present (the info, if any, is now in the SECONDS member).
* lisp/calendar/time-date.el (decoded-time-add)
(decoded-time--alter-second):
Support fractional seconds in the new form. Simplify.
* src/timefns.c (Fdecode_time): Support new arg FORM.
(Fencode_time): Support subsecond resolution.
* test/src/timefns-tests.el (format-time-string-with-zone)
(decode-then-encode-time): Test subsecond calendrical timestamps.
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/timefns-tests.el | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el index 362e7655a91..13ab7d83c3e 100644 --- a/test/src/timefns-tests.el +++ b/test/src/timefns-tests.el @@ -40,25 +40,31 @@ (7879679999900 . 100000) (78796799999999999999 . 1000000000000))) ;; UTC. - (let ((subsec (time-subtract (time-convert look t) - (time-convert look 'integer)))) + (let ((sec (time-add 59 (time-subtract (time-convert look t) + (time-convert look 'integer))))) (should (string-equal (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" look t) "1972-06-30 23:59:59.999 +0000")) - (should (equal (decode-time look t) - (list 59 59 23 30 6 1972 5 nil 0 subsec))) + (should (equal (decode-time look t 'integer) + '(59 59 23 30 6 1972 5 nil 0))) + (should (equal (decode-time look t t) + (list sec 59 23 30 6 1972 5 nil 0))) ;; "UTC0". (should (string-equal (format-time-string format look "UTC0") "1972-06-30 23:59:59.999 +0000 (UTC)")) - (should (equal (decode-time look "UTC0") - (list 59 59 23 30 6 1972 5 nil 0 subsec))) + (should (equal (decode-time look "UTC0" 'integer) + '(59 59 23 30 6 1972 5 nil 0))) + (should (equal (decode-time look "UTC0" t) + (list sec 59 23 30 6 1972 5 nil 0))) ;; Negative UTC offset, as a Lisp list. (should (string-equal (format-time-string format look '(-28800 "PST")) "1972-06-30 15:59:59.999 -0800 (PST)")) - (should (equal (decode-time look '(-28800 "PST")) - (list 59 59 15 30 6 1972 5 nil -28800 subsec))) + (should (equal (decode-time look '(-28800 "PST") 'integer) + '(59 59 15 30 6 1972 5 nil -28800))) + (should (equal (decode-time look '(-28800 "PST") t) + (list sec 59 15 30 6 1972 5 nil -28800))) ;; Negative UTC offset, as a Lisp integer. (should (string-equal (format-time-string format look -28800) @@ -67,14 +73,18 @@ (if (eq system-type 'windows-nt) "1972-06-30 15:59:59.999 -0800 (ZZZ)" "1972-06-30 15:59:59.999 -0800 (-08)"))) - (should (equal (decode-time look -28800) - (list 59 59 15 30 6 1972 5 nil -28800 subsec))) + (should (equal (decode-time look -28800 'integer) + '(59 59 15 30 6 1972 5 nil -28800))) + (should (equal (decode-time look -28800 t) + (list sec 59 15 30 6 1972 5 nil -28800))) ;; Positive UTC offset that is not an hour multiple, as a string. (should (string-equal (format-time-string format look "IST-5:30") "1972-07-01 05:29:59.999 +0530 (IST)")) - (should (equal (decode-time look "IST-5:30") - (list 59 29 5 1 7 1972 6 nil 19800 subsec))))))) + (should (equal (decode-time look "IST-5:30" 'integer) + '(59 29 5 1 7 1972 6 nil 19800))) + (should (equal (decode-time look "IST-5:30" t) + (list sec 29 5 1 7 1972 6 nil 19800))))))) (ert-deftest decode-then-encode-time () (let ((time-values (list 0 -2 1 0.0 -0.0 -2.0 1.0 @@ -87,11 +97,13 @@ (cons (1+ most-positive-fixnum) 1000000000000) (cons 1000000000000 (1+ most-positive-fixnum))))) (dolist (a time-values) - (let* ((d (ignore-errors (decode-time a t))) + (let* ((d (ignore-errors (decode-time a t t))) + (d-integer (ignore-errors (decode-time a t 'integer))) (e (if d (encode-time d))) - (diff (float-time (time-subtract a e)))) - (should (or (not d) - (and (<= 0 diff) (< diff 1)))))))) + (e-integer (if d-integer (encode-time d-integer)))) + (should (or (not d) (time-equal-p a e))) + (should (or (not d-integer) (time-equal-p (time-convert a 'integer) + e-integer))))))) ;;; This should not dump core. (ert-deftest format-time-string-with-outlandish-zone () @@ -151,7 +163,7 @@ (ert-deftest encode-time-dst-numeric-zone () "Check for Bug#35502." (should (time-equal-p - (encode-time '(29 31 17 30 4 2019 2 t 7200 0)) + (encode-time '(29 31 17 30 4 2019 2 t 7200)) '(23752 27217)))) (ert-deftest float-time-precision () |