|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (test-suite test-time) |
|
#:use-module (test-suite lib) |
|
#:use-module (ice-9 threads)) |
|
|
|
|
|
|
|
|
|
|
|
(with-test-prefix "gmtime" |
|
|
|
(for-each (lambda (t) |
|
(pass-if (list "in another thread after error" t) |
|
(or (provided? 'threads) (throw 'unsupported)) |
|
|
|
(alarm 5) |
|
(false-if-exception (gmtime t)) |
|
(join-thread (begin-thread (catch #t |
|
(lambda () (gmtime t)) |
|
(lambda args #f)))) |
|
(alarm 0) |
|
#t)) |
|
|
|
|
|
|
|
|
|
(list (1- (ash 1 31)) (1- (ash 1 63)) |
|
-1 (- (ash 1 31)) (- (ash 1 63))))) |
|
|
|
|
|
|
|
|
|
|
|
(with-test-prefix "internal-time-units-per-second" |
|
|
|
|
|
|
|
|
|
|
|
(pass-if "versus times and sleep" |
|
(or (defined? 'times) (throw 'unsupported)) |
|
|
|
(let ((old (times))) |
|
(sleep 1) |
|
(let* ((new (times)) |
|
(elapsed (- (tms:clock new) (tms:clock old)))) |
|
(<= (* 0.5 internal-time-units-per-second) |
|
elapsed |
|
(* 2 internal-time-units-per-second)))))) |
|
|
|
|
|
|
|
|
|
|
|
(with-test-prefix "localtime" |
|
|
|
|
|
|
|
|
|
|
|
(pass-if "gmtoff of EST+5 at GMT 10:00am on 10 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 10) |
|
(set-tm:mday tm 10) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let* ((t (car (mktime tm "GMT"))) |
|
(tm (localtime t "EST+5"))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of EST+5 at GMT 3am on 10 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 3) |
|
(set-tm:mday tm 10) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let* ((t (car (mktime tm "GMT"))) |
|
(tm (localtime t "EST+5"))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of AST-10 at GMT 10pm on 10 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 22) |
|
(set-tm:mday tm 10) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let* ((t (car (mktime tm "GMT"))) |
|
(tm (localtime t "AST-10"))) |
|
(eqv? (* -10 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of EST+5 at GMT 3am on 1 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 3) |
|
(set-tm:mday tm 1) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let* ((t (car (mktime tm "GMT"))) |
|
(tm (localtime t "EST+5"))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of AST-10 at GMT 10pm on 31 Dec 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 22) |
|
(set-tm:mday tm 31) |
|
(set-tm:mon tm 11) |
|
(set-tm:year tm 100) |
|
(let* ((t (car (mktime tm "GMT"))) |
|
(tm (localtime t "AST-10"))) |
|
(eqv? (* -10 3600) (tm:gmtoff tm)))))) |
|
|
|
|
|
|
|
|
|
|
|
(with-test-prefix "mktime" |
|
|
|
|
|
|
|
|
|
|
|
(pass-if "gmtoff of EST+5 at 10:00am on 10 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 10) |
|
(set-tm:mday tm 10) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let ((tm (cdr (mktime tm "EST+5")))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of EST+5 at 10:00pm on 10 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 22) |
|
(set-tm:mday tm 10) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let ((tm (cdr (mktime tm "EST+5")))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of AST-10 at 3:00am on 10 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 3) |
|
(set-tm:mday tm 10) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let ((tm (cdr (mktime tm "AST-10")))) |
|
(eqv? (* -10 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of EST+5 at 10:00pm on 31 Dec 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 22) |
|
(set-tm:mday tm 31) |
|
(set-tm:mon tm 11) |
|
(set-tm:year tm 100) |
|
(let ((tm (cdr (mktime tm "EST+5")))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm))))) |
|
|
|
|
|
(pass-if "gmtoff of AST-10 at 3:00am on 1 Jan 2000" |
|
(let ((tm (gmtime 0))) |
|
(set-tm:hour tm 3) |
|
(set-tm:mday tm 1) |
|
(set-tm:mon tm 0) |
|
(set-tm:year tm 100) |
|
(let ((tm (cdr (mktime tm "AST-10")))) |
|
(eqv? (* -10 3600) (tm:gmtoff tm)))))) |
|
|
|
|
|
|
|
|
|
|
|
(with-test-prefix "strftime" |
|
|
|
(pass-if-equal "strftime %Z doesn't return garbage" |
|
"ZOW" |
|
(let ((t (localtime (current-time)))) |
|
(set-tm:zone t "ZOW") |
|
(set-tm:isdst t 0) |
|
(strftime "%Z" t))) |
|
|
|
(pass-if-equal "strftime passes wide characters" |
|
"\u0100" |
|
(with-locale "en_US.utf8" |
|
(let ((t (localtime (current-time)))) |
|
(substring (strftime "\u0100%Z" t) 0 1)))) |
|
|
|
(with-test-prefix "C99 %z format" |
|
|
|
|
|
|
|
|
|
(pass-if-equal "GMT" |
|
"+0000" |
|
(begin |
|
(putenv "TZ=GMT+0") |
|
(tzset) |
|
(let ((tm (localtime 86400))) |
|
(strftime "%z" tm)))) |
|
|
|
|
|
|
|
|
|
(pass-if-equal "EST+5" |
|
"-0500" |
|
(begin |
|
(putenv "TZ=EST+5") |
|
(tzset) |
|
(let ((tm (localtime 86400))) |
|
(strftime "%z" tm)))) |
|
|
|
(pass-if-equal "strftime fr_FR.utf8" |
|
" 1 février 1970" |
|
(with-locale "fr_FR.utf8" |
|
(strftime "%e %B %Y" (gmtime (* 31 24 3600))))) |
|
|
|
(pass-if-equal "strftime fr_FR.iso88591" |
|
" 1 février 1970" |
|
(with-locale "fr_FR.iso88591" |
|
(strftime "%e %B %Y" (gmtime (* 31 24 3600))))))) |
|
|
|
|
|
|
|
|
|
|
|
(with-test-prefix "strptime" |
|
|
|
(pass-if "in another thread after error" |
|
(or (defined? 'strptime) (throw 'unsupported)) |
|
(or (provided? 'threads) (throw 'unsupported)) |
|
|
|
(alarm 5) |
|
(false-if-exception |
|
(strptime "%a" "nosuchday")) |
|
(join-thread (begin-thread (strptime "%d" "1"))) |
|
(alarm 0) |
|
#t) |
|
|
|
(with-test-prefix "GNU %s format" |
|
|
|
|
|
(define have-strptime-%s |
|
(false-if-exception (strptime "%s" "0"))) |
|
|
|
(pass-if "gmtoff on GMT" |
|
(or have-strptime-%s (throw 'unsupported)) |
|
(putenv "TZ=GMT+0") |
|
(tzset) |
|
(let ((tm (car (strptime "%s" "86400")))) |
|
(eqv? 0 (tm:gmtoff tm)))) |
|
|
|
(pass-if-equal "strftime fr_FR.utf8" |
|
'(1 2 1999) |
|
(with-locale "fr_FR.utf8" |
|
(let ((tm (car (strptime "%e %B %Y" "1 février 1999")))) |
|
(list (tm:mday tm) |
|
(+ 1 (tm:mon tm)) |
|
(+ 1900 (tm:year tm)))))) |
|
|
|
(pass-if-equal "strftime fr_FR.iso88591" |
|
'(1 2 1999) |
|
(with-locale "fr_FR.iso88591" |
|
(let ((tm (car (strptime "%e %B %Y" "1 février 1999")))) |
|
(list (tm:mday tm) |
|
(+ 1 (tm:mon tm)) |
|
(+ 1900 (tm:year tm)))))) |
|
|
|
|
|
|
|
(pass-if "gmtoff on EST+5" |
|
(or have-strptime-%s (throw 'unsupported)) |
|
(putenv "TZ=EST+5") |
|
(tzset) |
|
(let ((tm (car (strptime "%s" "86400")))) |
|
(eqv? (* 5 3600) (tm:gmtoff tm)))))) |
|
|