1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-14 09:39:42 +00:00

Port timestamp tests to odd timezones, (TICKS . HZ)

* test/src/timefns-tests.el:
(format-time-string-padding-minimal-deletes-unneeded-zeros)
(format-time-string-padding-minimal-retains-needed-zeros)
(format-time-string-padding-spaces)
(format-time-string-padding-zeros-adds-on-insignificant-side):
Don't assume local time can represent 2000-02-15 00:00:00,
as there might be a DST jump over midnight.
Work even when timestamps are of (TICKS . HZ) form.
Simplify by avoiding need to call time-add.
This commit is contained in:
Paul Eggert 2020-02-27 23:16:44 -08:00
parent ef4440a9c8
commit 8ab0e7316a

View File

@ -124,44 +124,44 @@
;;; Tests of format-time-string padding
(ert-deftest format-time-string-padding-minimal-deletes-unneeded-zeros ()
(let ((ref-time (append (encode-time 0 0 0 15 2 2000) '(123450))))
(let ((ref-time (encode-time '((123450 . 1000000) 0 0 15 2 2000 - - t))))
(should (equal (format-time-string "%-:::z" ref-time "FJT-12") "+12"))
(should (equal (format-time-string "%-N" ref-time) "12345"))
(should (equal (format-time-string "%-6N" ref-time) "12345"))
(should (equal (format-time-string "%-m" ref-time) "2")))) ;not "02"
(should (equal (format-time-string "%-N" ref-time t) "12345"))
(should (equal (format-time-string "%-6N" ref-time t) "12345"))
(should (equal (format-time-string "%-m" ref-time t) "2")))) ;not "02"
(ert-deftest format-time-string-padding-minimal-retains-needed-zeros ()
(let ((ref-time (append (encode-time 0 0 0 20 10 2000) '(3450))))
(let ((ref-time (encode-time '((3450 . 1000000) 0 0 20 10 2000 - - t))))
(should (equal (format-time-string "%-z" ref-time "IST-5:30") "+530"))
(should (equal (format-time-string "%-4z" ref-time "IST-5:30") "+530"))
(should (equal (format-time-string "%4z" ref-time "IST-5:30") "+530"))
(should (equal (format-time-string "%-N" ref-time) "00345"))
(should (equal (format-time-string "%-3N" ref-time) "003"))
(should (equal (format-time-string "%3N" ref-time) "003"))
(should (equal (format-time-string "%-m" ref-time) "10")) ;not "1"
(should (equal (format-time-string "%-1m" ref-time) "10")) ;not "1"
(should (equal (format-time-string "%1m" ref-time) "10")))) ;not "1"
(should (equal (format-time-string "%-N" ref-time t) "00345"))
(should (equal (format-time-string "%-3N" ref-time t) "003"))
(should (equal (format-time-string "%3N" ref-time t) "003"))
(should (equal (format-time-string "%-m" ref-time t) "10")) ;not "1"
(should (equal (format-time-string "%-1m" ref-time t) "10")) ;not "1"
(should (equal (format-time-string "%1m" ref-time t) "10")))) ;not "1"
(ert-deftest format-time-string-padding-spaces ()
(let ((ref-time (append (encode-time 0 0 0 10 12 2000) '(123000))))
(let ((ref-time (encode-time '((123000 . 1000000) 0 0 10 12 2000 - - t))))
(should (equal (format-time-string "%_7z" ref-time "CHA-12:45") " +1245"))
(should (equal (format-time-string "%_6N" ref-time) "123 "))
(should (equal (format-time-string "%_9N" ref-time) "123 "))
(should (equal (format-time-string "%_12N" ref-time) "123 "))
(should (equal (format-time-string "%_m" ref-time) "12"))
(should (equal (format-time-string "%_2m" ref-time) "12"))
(should (equal (format-time-string "%_3m" ref-time) " 12"))))
(should (equal (format-time-string "%_6N" ref-time t) "123 "))
(should (equal (format-time-string "%_9N" ref-time t) "123 "))
(should (equal (format-time-string "%_12N" ref-time t) "123 "))
(should (equal (format-time-string "%_m" ref-time t) "12"))
(should (equal (format-time-string "%_2m" ref-time t) "12"))
(should (equal (format-time-string "%_3m" ref-time t) " 12"))))
(ert-deftest format-time-string-padding-zeros-adds-on-insignificant-side ()
"Fractional seconds have a fixed place on the left,
and any padding must happen on the right. All other numbers have
a fixed place on the right and are padded on the left."
(let ((ref-time (append (encode-time 0 0 0 10 12 2000) '(123000))))
(should (equal (format-time-string "%3m" ref-time) "012"))
(let ((ref-time (encode-time '((123000 . 1000000) 0 0 10 12 2000 - - t))))
(should (equal (format-time-string "%3m" ref-time t) "012"))
(should (equal (format-time-string "%7z" ref-time "CHA-12:45") "+001245"))
(should (equal (format-time-string "%12N" ref-time) "123000000000"))
(should (equal (format-time-string "%9N" ref-time) "123000000"))
(should (equal (format-time-string "%6N" ref-time) "123000"))))
(should (equal (format-time-string "%12N" ref-time t) "123000000000"))
(should (equal (format-time-string "%9N" ref-time t) "123000000"))
(should (equal (format-time-string "%6N" ref-time t) "123000"))))
(ert-deftest time-equal-p-nil-nil ()