(require 'ert)
(require 'time-date)
+(ert-deftest test-obsolete-with-decoded-time-value ()
+ (with-suppressed-warnings ((obsolete with-decoded-time-value))
+ (with-decoded-time-value ((high low micro pico type '(1 2 3 4 5 6 8 8)))
+ (should (equal (list high low micro pico type) '(1 2 3 4 3))))))
+
+(ert-deftest test-obsolete-encode-time-value ()
+ (should (equal (with-suppressed-warnings ((obsolete encode-time-value))
+ (encode-time-value 1 2 3 4 0))
+ '(1 . 2)))
+ (should (equal (with-suppressed-warnings ((obsolete encode-time-value))
+ (encode-time-value 1 2 3 4 1))
+ '(1 2)))
+ (should (equal (with-suppressed-warnings ((obsolete encode-time-value))
+ (encode-time-value 1 2 3 4 2))
+ '(1 2 3)))
+ (should (equal (with-suppressed-warnings ((obsolete encode-time-value))
+ (encode-time-value 1 2 3 4 3))
+ '(1 2 3 4))))
+
(ert-deftest test-leap-year ()
(should-not (date-leap-year-p 1999))
(should-not (date-leap-year-p 1900))
(should (date-leap-year-p 2000))
(should (date-leap-year-p 2004)))
+(ert-deftest test-days-to-time ()
+ (should (equal (days-to-time 0) '(0 0)))
+ (should (equal (days-to-time 1) '(1 20864)))
+ (should (equal (days-to-time 999) '(1317 2688)))
+ (should (equal (days-to-time 0.0) '(0 0 0 0)))
+ (should (equal (days-to-time 0.5) '(0 43200 0 0)))
+ (should (equal (days-to-time 1.0) '(1 20864 0 0)))
+ (should (equal (days-to-time 999.0) '(1317 2688 0 0))))
+
+(ert-deftest test-seconds-to-string ()
+ (should (equal (seconds-to-string 0) "0s"))
+ (should (equal (seconds-to-string 9) "9.00s"))
+ (should (equal (seconds-to-string 99) "99.00s"))
+ (should (equal (seconds-to-string 999) "16.65m"))
+ (should (equal (seconds-to-string 9999) "2.78h"))
+ (should (equal (seconds-to-string 99999) "27.78h"))
+ (should (equal (seconds-to-string 999999) "11.57d"))
+ (should (equal (seconds-to-string 9999999) "115.74d"))
+ (should (equal (seconds-to-string 99999999) "3.17y"))
+ (should (equal (seconds-to-string 999999999) "31.69y")))
+
(ert-deftest test-days-in-month ()
(should (= (date-days-in-month 2004 2) 29))
(should (= (date-days-in-month 2004 3) 31))
+ (should (= (date-days-in-month 2019 2) 28))
+ (should (= (date-days-in-month 2020 12) 31))
(should-not (= (date-days-in-month 1900 3) 28))
+ (should-error (date-days-in-month 2020 0))
(should-error (date-days-in-month 2020 15))
(should-error (date-days-in-month 2020 'foo)))
+(ert-deftest test-format-seconds ()
+ (should (equal (format-seconds "%y %d %h %m %s %%" 0) "0 0 0 0 0 %"))
+ (should (equal (format-seconds "%y %d %h %m %s %%" 9999999) "0 115 17 46 39 %"))
+ (should (equal (format-seconds "%y %d %h %m %z %s %%" 1) " 1 %")))
+
(ert-deftest test-ordinal ()
(should (equal (date-ordinal-to-time 2008 271)
'(nil nil nil 27 9 2008 nil nil nil)))
'(12 15 14 8 7 2019 1 t 7200)))))
(ert-deftest test-time-since ()
- (should (time-equal-p 0 (time-since nil))))
+ (should (time-equal-p 0 (time-since nil)))
+ (should (= (cadr (time-since (time-subtract (current-time) 1))) 1)))
(ert-deftest test-time-decoded-period ()
(should (equal (decoded-time-period '(nil nil 1 nil nil nil nil nil nil))
(should (equal (decoded-time-period '(0 0 0 1 0 0 nil nil nil)) 86400))
(should (equal (decoded-time-period '(0 0 0 0 1 0 nil nil nil)) 2592000))
(should (equal (decoded-time-period '(0 0 0 0 0 1 nil nil nil)) 31536000))
+ (should (equal (decoded-time-period '(1 2 3 4 5 6 nil nil nil)) 202532521))
(should (equal (decoded-time-period '((135 . 10) 0 0 0 0 0 nil nil nil))
13.5)))