| 1 |
;;;; srfi-19.test --- test suite for SRFI-19 -*- scheme -*- |
| 2 |
;;;; Matthias Koeppe <[email protected]> --- June 2001 |
| 3 |
;;;; |
| 4 |
;;;; Copyright (C) 2001, 2003-2008, 2011, 2014, 2017, 2018 |
| 5 |
;;;; Free Software Foundation, Inc. |
| 6 |
;;;; |
| 7 |
;;;; This library is free software; you can redistribute it and/or |
| 8 |
;;;; modify it under the terms of the GNU Lesser General Public |
| 9 |
;;;; License as published by the Free Software Foundation; either |
| 10 |
;;;; version 3 of the License, or (at your option) any later version. |
| 11 |
;;;; |
| 12 |
;;;; This library is distributed in the hope that it will be useful, |
| 13 |
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
;;;; Lesser General Public License for more details. |
| 16 |
;;;; |
| 17 |
;;;; You should have received a copy of the GNU Lesser General Public |
| 18 |
;;;; License along with this library; if not, write to the Free Software |
| 19 |
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
|
| 21 |
;; SRFI-19 overrides current-date, so we have to do the test in a |
| 22 |
;; separate module, or later tests will fail. |
| 23 |
|
| 24 |
(define-module (test-suite test-srfi-19) |
| 25 |
#:duplicates (last) ;; avoid warning about srfi-19 replacing `current-time' |
| 26 |
#:use-module (test-suite lib) |
| 27 |
#:use-module (srfi srfi-1) |
| 28 |
#:use-module (srfi srfi-19) |
| 29 |
#:use-module (ice-9 format) |
| 30 |
#:use-module (ice-9 match)) |
| 31 |
|
| 32 |
;; Make sure we use the default locale. |
| 33 |
(when (defined? 'setlocale) |
| 34 |
(setlocale LC_ALL "C")) |
| 35 |
|
| 36 |
(define (with-tz* tz thunk) |
| 37 |
"Temporarily set the TZ environment variable to the passed string |
| 38 |
value and call THUNK." |
| 39 |
(let ((old-tz #f)) |
| 40 |
(dynamic-wind |
| 41 |
(lambda () |
| 42 |
(set! old-tz (getenv "TZ")) |
| 43 |
(putenv (format #f "TZ=~A" tz))) |
| 44 |
thunk |
| 45 |
(lambda () |
| 46 |
(if old-tz |
| 47 |
(putenv (format #f "TZ=~A" old-tz)) |
| 48 |
(putenv "TZ")))))) |
| 49 |
|
| 50 |
(defmacro with-tz (tz . body) |
| 51 |
`(with-tz* ,tz (lambda () ,@body))) |
| 52 |
|
| 53 |
(define (test-integral-time-structure date->time) |
| 54 |
"Test whether the given DATE->TIME procedure creates a time |
| 55 |
structure with integral seconds. (The seconds shall be maintained as |
| 56 |
integers, or precision may go away silently. The SRFI-19 reference |
| 57 |
implementation was not OK for Guile in this respect because of Guile's |
| 58 |
incomplete numerical tower implementation.)" |
| 59 |
(pass-if (format #f "~A makes integer seconds" |
| 60 |
date->time) |
| 61 |
(exact? (time-second |
| 62 |
(date->time (make-date 0 0 0 12 1 6 2001 0)))))) |
| 63 |
|
| 64 |
(define (test-time->date time->date date->time) |
| 65 |
(pass-if (format #f "~A works" |
| 66 |
time->date) |
| 67 |
(begin |
| 68 |
(time->date (date->time (make-date 0 0 0 12 1 6 2001 0))) |
| 69 |
#t))) |
| 70 |
|
| 71 |
(define (test-dst time->date date->time) |
| 72 |
(pass-if (format #f "~A respects local DST if no TZ-OFFSET given" |
| 73 |
time->date) |
| 74 |
(let ((time (date->time (make-date 0 0 0 12 1 6 2001 0)))) |
| 75 |
;; on 2001-06-01, there should be 4 hours zone offset |
| 76 |
;; between EST (EDT) and GMT |
| 77 |
(= (date-zone-offset |
| 78 |
(with-tz "EST5EDT" |
| 79 |
(time->date time))) |
| 80 |
-14400)))) |
| 81 |
|
| 82 |
(define-macro (test-time-conversion a b) |
| 83 |
(let* ((a->b-sym (symbol-append a '-> b)) |
| 84 |
(b->a-sym (symbol-append b '-> a))) |
| 85 |
`(pass-if (format #f "~A and ~A work and are inverses of each other" |
| 86 |
',a->b-sym ',b->a-sym) |
| 87 |
(let ((time (make-time ,a 12345 67890123))) |
| 88 |
(time=? time (,b->a-sym (,a->b-sym time))))))) |
| 89 |
|
| 90 |
(define (test-time-comparison cmp a b) |
| 91 |
(pass-if (format #f "~A works" cmp) |
| 92 |
(cmp a b))) |
| 93 |
|
| 94 |
(define (test-time-arithmetic op a b res) |
| 95 |
(pass-if (format #f "~A works" op) |
| 96 |
(time=? (op a b) res))) |
| 97 |
|
| 98 |
;; return true if time objects X and Y are equal |
| 99 |
(define (time-equal? x y) |
| 100 |
(and (eq? (time-type x) (time-type y)) |
| 101 |
(eqv? (time-second x) (time-second y)) |
| 102 |
(eqv? (time-nanosecond x) (time-nanosecond y)))) |
| 103 |
|
| 104 |
(with-test-prefix "SRFI date/time library" |
| 105 |
;; check for typos and silly errors |
| 106 |
(pass-if "date-zone-offset is defined" |
| 107 |
(and (defined? 'date-zone-offset) |
| 108 |
date-zone-offset |
| 109 |
#t)) |
| 110 |
(pass-if "add-duration is defined" |
| 111 |
(and (defined? 'add-duration) |
| 112 |
add-duration |
| 113 |
#t)) |
| 114 |
(pass-if "(current-time time-tai) works" |
| 115 |
(time? (current-time time-tai))) |
| 116 |
(pass-if "(current-time time-process) works" |
| 117 |
(time? (current-time time-process))) |
| 118 |
(test-time-conversion time-utc time-tai) |
| 119 |
(test-time-conversion time-utc time-monotonic) |
| 120 |
(test-time-conversion time-tai time-monotonic) |
| 121 |
(pass-if "string->date works" |
| 122 |
(begin (string->date "2001-06-01@14:00" "~Y-~m-~d@~H:~M") |
| 123 |
#t)) |
| 124 |
(pass-if "string->date accepts ISO 8601 zones with a colon" |
| 125 |
(begin (string->date "2024-12-31T23:59:59+01:00" "~Y-~m-~dT~H:~M:~S~z") |
| 126 |
#t)) |
| 127 |
;; check for code paths where reals were passed to quotient, which |
| 128 |
;; doesn't work in Guile (and is unspecified in R5RS) |
| 129 |
(test-time->date time-utc->date date->time-utc) |
| 130 |
(test-time->date time-tai->date date->time-tai) |
| 131 |
(test-time->date time-monotonic->date date->time-monotonic) |
| 132 |
(pass-if "Fractional nanoseconds are handled" |
| 133 |
(begin (make-time time-duration 1000000000.5 0) #t)) |
| 134 |
;; the seconds in a time shall be maintained as integers, or |
| 135 |
;; precision may silently go away |
| 136 |
(test-integral-time-structure date->time-utc) |
| 137 |
(test-integral-time-structure date->time-tai) |
| 138 |
(test-integral-time-structure date->time-monotonic) |
| 139 |
;; check for DST and zone related problems |
| 140 |
(pass-if "date->time-utc is the inverse of time-utc->date" |
| 141 |
(let ((time (date->time-utc |
| 142 |
(make-date 0 0 0 14 1 6 2001 7200)))) |
| 143 |
(time=? time |
| 144 |
(date->time-utc (time-utc->date time 7200))))) |
| 145 |
(test-dst time-utc->date date->time-utc) |
| 146 |
(test-dst time-tai->date date->time-tai) |
| 147 |
(test-dst time-monotonic->date date->time-monotonic) |
| 148 |
(test-dst julian-day->date date->julian-day) |
| 149 |
(test-dst modified-julian-day->date date->modified-julian-day) |
| 150 |
|
| 151 |
(pass-if "`date->julian-day' honors timezone" |
| 152 |
(let ((now (current-date -14400))) |
| 153 |
(time=? (date->time-utc (julian-day->date (date->julian-day now))) |
| 154 |
(date->time-utc now)))) |
| 155 |
|
| 156 |
(pass-if "string->date respects local DST if no time zone is read" |
| 157 |
(time=? (date->time-utc |
| 158 |
(with-tz "EST5EDT" |
| 159 |
(string->date "2001-06-01@08:00" "~Y-~m-~d@~H:~M"))) |
| 160 |
(date->time-utc |
| 161 |
(make-date 0 0 0 12 1 6 2001 0)))) |
| 162 |
(pass-if "string->date understands days and months" |
| 163 |
(time=? (let ((d (string->date "Saturday, December 9, 2006" |
| 164 |
"~A, ~B ~d, ~Y"))) |
| 165 |
(date->time-utc (make-date (date-nanosecond d) |
| 166 |
(date-second d) |
| 167 |
(date-minute d) |
| 168 |
(date-hour d) |
| 169 |
(date-day d) |
| 170 |
(date-month d) |
| 171 |
(date-year d) |
| 172 |
0))) |
| 173 |
(date->time-utc |
| 174 |
(make-date 0 0 0 0 9 12 2006 0)))) |
| 175 |
|
| 176 |
(pass-if "string->date works on Sunday" |
| 177 |
;; `string->date' never rests! |
| 178 |
(let* ((str "Sun, 05 Jun 2005 18:33:00 +0200") |
| 179 |
(date (string->date str "~a, ~d ~b ~Y ~H:~M:~S ~z"))) |
| 180 |
(equal? "Sun Jun 05 18:33:00+0200 2005" |
| 181 |
(date->string date)))) |
| 182 |
|
| 183 |
(pass-if "string->date understands nanoseconds (1)" |
| 184 |
(let ((date (string->date "2018-12-10 10:53:24.189" |
| 185 |
"~Y-~m-~d ~H:~M:~S.~N"))) |
| 186 |
(time=? (date->time-utc date) |
| 187 |
(date->time-utc (make-date 189000000 24 53 10 10 12 2018 |
| 188 |
(date-zone-offset date)))))) |
| 189 |
|
| 190 |
(pass-if "string->date understands nanoseconds (2)" |
| 191 |
(let ((date (string->date "2018-12-10 10:53:24.189654321" |
| 192 |
"~Y-~m-~d ~H:~M:~S.~N"))) |
| 193 |
(time=? (date->time-utc date) |
| 194 |
(date->time-utc (make-date 189654321 24 53 10 10 12 2018 |
| 195 |
(date-zone-offset date)))))) |
| 196 |
|
| 197 |
(pass-if "date->string pads small nanoseconds values correctly" |
| 198 |
(let* ((date (make-date 99999999 5 34 12 26 3 2017 0))) |
| 199 |
(equal? "099999999" |
| 200 |
(date->string date "~N")))) |
| 201 |
|
| 202 |
(pass-if "date->string ~f without leading zeroes" |
| 203 |
(let ((date (make-date 200000000 5 34 12 26 3 2017 0))) |
| 204 |
(equal? "5.2" (date->string date "~f")))) |
| 205 |
|
| 206 |
(pass-if "date->string ~f proper fractional part" |
| 207 |
(let ((date (make-date 550000 56 34 12 26 3 2017 0))) |
| 208 |
(equal? "56.00055" (date->string date "~f")))) |
| 209 |
|
| 210 |
;; check time comparison procedures |
| 211 |
(let* ((time1 (make-time time-monotonic 0 0)) |
| 212 |
(time2 (make-time time-monotonic 0 0)) |
| 213 |
(time3 (make-time time-monotonic 385907 998360432)) |
| 214 |
(time4 (make-time time-monotonic 385907 998360432))) |
| 215 |
(test-time-comparison time<=? time1 time3) |
| 216 |
(test-time-comparison time<? time1 time3) |
| 217 |
(test-time-comparison time=? time1 time2) |
| 218 |
(test-time-comparison time>=? time3 time3) |
| 219 |
(test-time-comparison time>? time3 time2)) |
| 220 |
;; check time arithmetic procedures |
| 221 |
(let* ((time1 (make-time time-monotonic 0 0)) |
| 222 |
(time2 (make-time time-monotonic 385907 998360432)) |
| 223 |
(diff (time-difference time2 time1))) |
| 224 |
(test-time-arithmetic add-duration time1 diff time2) |
| 225 |
(test-time-arithmetic subtract-duration time2 diff time1)) |
| 226 |
|
| 227 |
(with-test-prefix "nanosecond normalization" |
| 228 |
(pass-if "small positive duration" |
| 229 |
(time-equal? (make-time time-duration 999999000 0) |
| 230 |
(time-difference (make-time time-tai 0 1) (make-time time-tai 1000 0)))) |
| 231 |
(pass-if "small negative duration" |
| 232 |
(time-equal? (make-time time-duration -999999000 0) |
| 233 |
(time-difference (make-time time-tai 1000 0) (make-time time-tai 0 1))))) |
| 234 |
|
| 235 |
(with-test-prefix "date->time-tai" |
| 236 |
;; leap second 1 Jan 1999, 1 second of UTC in make-date is out as 2 |
| 237 |
;; seconds of TAI in date->time-tai |
| 238 |
(pass-if "31dec98 23:59:59" |
| 239 |
(time-equal? (make-time time-tai 0 915148830) |
| 240 |
(date->time-tai (make-date 0 59 59 23 31 12 1998 0)))) |
| 241 |
(pass-if "31dec98 23:59:60" |
| 242 |
(time-equal? (make-time time-tai 0 915148831) |
| 243 |
(date->time-tai (make-date 0 60 59 23 31 12 1998 0)))) |
| 244 |
(pass-if "1jan99 0:00:00" |
| 245 |
(time-equal? (make-time time-tai 0 915148832) |
| 246 |
(date->time-tai (make-date 0 0 0 0 1 1 1999 0)))) |
| 247 |
|
| 248 |
;; leap second 1 Jan 2006, 1 second of UTC in make-date is out as 2 |
| 249 |
;; seconds of TAI in date->time-tai |
| 250 |
(pass-if "31dec05 23:59:59" |
| 251 |
(time-equal? (make-time time-tai 0 1136073631) |
| 252 |
(date->time-tai (make-date 0 59 59 23 31 12 2005 0)))) |
| 253 |
(pass-if "31dec05 23:59:60" |
| 254 |
(time-equal? (make-time time-tai 0 1136073632) |
| 255 |
(date->time-tai (make-date 0 60 59 23 31 12 2005 0)))) |
| 256 |
(pass-if "1jan06 0:00:00" |
| 257 |
(time-equal? (make-time time-tai 0 1136073633) |
| 258 |
(date->time-tai (make-date 0 0 0 0 1 1 2006 0))))) |
| 259 |
|
| 260 |
(with-test-prefix "date->time-monotonic" |
| 261 |
;; leap second 1 Jan 1999, 1 second of UTC in make-date is out as 2 |
| 262 |
;; seconds of MONOTONIC in date->time-monotonic |
| 263 |
(pass-if "31dec98 23:59:59" |
| 264 |
(time-equal? (make-time time-monotonic 0 915148830) |
| 265 |
(date->time-monotonic (make-date 0 59 59 23 31 12 1998 0)))) |
| 266 |
(pass-if "31dec98 23:59:60" |
| 267 |
(time-equal? (make-time time-monotonic 0 915148831) |
| 268 |
(date->time-monotonic (make-date 0 60 59 23 31 12 1998 0)))) |
| 269 |
(pass-if "1jan99 0:00:00" |
| 270 |
(time-equal? (make-time time-monotonic 0 915148832) |
| 271 |
(date->time-monotonic (make-date 0 0 0 0 1 1 1999 0)))) |
| 272 |
|
| 273 |
;; leap second 1 Jan 2006, 1 second of UTC in make-date is out as 2 |
| 274 |
;; seconds of MONOTONIC in date->time-monotonic |
| 275 |
(pass-if "31dec05 23:59:59" |
| 276 |
(time-equal? (make-time time-monotonic 0 1136073631) |
| 277 |
(date->time-monotonic (make-date 0 59 59 23 31 12 2005 0)))) |
| 278 |
(pass-if "31dec05 23:59:60" |
| 279 |
(time-equal? (make-time time-monotonic 0 1136073632) |
| 280 |
(date->time-monotonic (make-date 0 60 59 23 31 12 2005 0)))) |
| 281 |
(pass-if "1jan06 0:00:00" |
| 282 |
(time-equal? (make-time time-monotonic 0 1136073633) |
| 283 |
(date->time-monotonic (make-date 0 0 0 0 1 1 2006 0))))) |
| 284 |
|
| 285 |
(with-test-prefix "julian-day->date" |
| 286 |
(pass-if-equal "0002-07-29T12:00:00Z" "0002-07-29T12:00:00Z" |
| 287 |
(date->string (julian-day->date 1722000 0) "~4")) |
| 288 |
(pass-if-equal "0024-06-23T12:00:00Z" "0024-06-23T12:00:00Z" |
| 289 |
(date->string (julian-day->date 1730000 0) "~4")) |
| 290 |
(pass-if-equal "2000-01-01T00:00:00Z" "2000-01-01T00:00:00Z" |
| 291 |
(date->string (julian-day->date 4903089/2 0) "~4")) |
| 292 |
(pass-if-equal "9999-12-31T12:00:00Z" "9999-12-31T12:00:00Z" |
| 293 |
(date->string (julian-day->date 5373484 0) "~4")) |
| 294 |
(pass-if-equal "+10000-01-01T12:00:00Z" "+10000-01-01T12:00:00Z" |
| 295 |
(date->string (julian-day->date 5373485 0) "~4")) |
| 296 |
(pass-if-equal "negative julian days" |
| 297 |
'((-2000000 . "-10188-02-01T14:24:00Z wk=04 dow=6 doy=032") |
| 298 |
(-20000 . "-4767-02-20T14:24:00Z wk=08 dow=0 doy=051") |
| 299 |
(-10 . "-4713-11-14T14:24:00Z wk=45 dow=5 doy=318") |
| 300 |
(-9 . "-4713-11-15T14:24:00Z wk=45 dow=6 doy=319") |
| 301 |
(-8 . "-4713-11-16T14:24:00Z wk=46 dow=0 doy=320") |
| 302 |
(-7 . "-4713-11-17T14:24:00Z wk=46 dow=1 doy=321") |
| 303 |
(-6 . "-4713-11-18T14:24:00Z wk=46 dow=2 doy=322") |
| 304 |
(-5 . "-4713-11-19T14:24:00Z wk=46 dow=3 doy=323") |
| 305 |
(-4 . "-4713-11-20T14:24:00Z wk=46 dow=4 doy=324") |
| 306 |
(-3 . "-4713-11-21T14:24:00Z wk=46 dow=5 doy=325") |
| 307 |
(-2 . "-4713-11-22T14:24:00Z wk=46 dow=6 doy=326") |
| 308 |
(-1 . "-4713-11-23T14:24:00Z wk=47 dow=0 doy=327") |
| 309 |
(0 . "-4713-11-24T14:24:00Z wk=47 dow=1 doy=328") |
| 310 |
(1 . "-4713-11-25T14:24:00Z wk=47 dow=2 doy=329") |
| 311 |
(2 . "-4713-11-26T14:24:00Z wk=47 dow=3 doy=330") |
| 312 |
(3 . "-4713-11-27T14:24:00Z wk=47 dow=4 doy=331") |
| 313 |
(4 . "-4713-11-28T14:24:00Z wk=47 dow=5 doy=332") |
| 314 |
(5 . "-4713-11-29T14:24:00Z wk=47 dow=6 doy=333") |
| 315 |
(6 . "-4713-11-30T14:24:00Z wk=48 dow=0 doy=334") |
| 316 |
(7 . "-4713-12-01T14:24:00Z wk=48 dow=1 doy=335") |
| 317 |
(8 . "-4713-12-02T14:24:00Z wk=48 dow=2 doy=336") |
| 318 |
(9 . "-4713-12-03T14:24:00Z wk=48 dow=3 doy=337")) |
| 319 |
(map (lambda (n) |
| 320 |
(cons n (date->string (julian-day->date (+ n 1/10) 0) |
| 321 |
"~4 wk=~U dow=~w doy=~j"))) |
| 322 |
(cons* -2000000 -20000 (iota 20 -10)))) |
| 323 |
(pass-if-equal "negative year numbers" |
| 324 |
'((1721055 . "-0001-12-27T14:24:00Z wk=52 dow=1 doy=361") |
| 325 |
(1721056 . "-0001-12-28T14:24:00Z wk=52 dow=2 doy=362") |
| 326 |
(1721057 . "-0001-12-29T14:24:00Z wk=52 dow=3 doy=363") |
| 327 |
(1721058 . "-0001-12-30T14:24:00Z wk=52 dow=4 doy=364") |
| 328 |
(1721059 . "-0001-12-31T14:24:00Z wk=52 dow=5 doy=365") |
| 329 |
(1721060 . "0000-01-01T14:24:00Z wk=00 dow=6 doy=001") |
| 330 |
(1721061 . "0000-01-02T14:24:00Z wk=01 dow=0 doy=002") |
| 331 |
(1721062 . "0000-01-03T14:24:00Z wk=01 dow=1 doy=003") |
| 332 |
(1721063 . "0000-01-04T14:24:00Z wk=01 dow=2 doy=004") |
| 333 |
(1721064 . "0000-01-05T14:24:00Z wk=01 dow=3 doy=005")) |
| 334 |
(map (lambda (n) |
| 335 |
(cons n (date->string (julian-day->date (+ n 1/10) 0) |
| 336 |
"~4 wk=~U dow=~w doy=~j"))) |
| 337 |
(iota 10 1721055)))) |
| 338 |
|
| 339 |
(with-test-prefix "time-utc->date" |
| 340 |
(pass-if-equal "2012-07-01T00:59:59+0100" "2012-07-01T00:59:59+0100" |
| 341 |
(date->string (time-utc->date (make-time time-utc 0 1341100799) |
| 342 |
3600) |
| 343 |
"~4")) |
| 344 |
(pass-if-equal "2012-07-01T01:00:00+0100" "2012-07-01T01:00:00+0100" |
| 345 |
(date->string (time-utc->date (make-time time-utc 0 1341100800) |
| 346 |
3600) |
| 347 |
"~4")) |
| 348 |
(pass-if-equal "2012-07-01T01:00:01+0100" "2012-07-01T01:00:01+0100" |
| 349 |
(date->string (time-utc->date (make-time time-utc 0 1341100801) |
| 350 |
3600) |
| 351 |
"~4"))) |
| 352 |
|
| 353 |
(with-test-prefix "time-tai->date" |
| 354 |
(pass-if-equal "2012-07-01T00:59:59+0100" "2012-07-01T00:59:59+0100" |
| 355 |
(date->string (time-tai->date (make-time time-tai 0 1341100833) |
| 356 |
3600) |
| 357 |
"~4")) |
| 358 |
(pass-if-equal "2012-07-01T00:59:60+0100" "2012-07-01T00:59:60+0100" |
| 359 |
(date->string (time-tai->date (make-time time-tai 0 1341100834) |
| 360 |
3600) |
| 361 |
"~4")) |
| 362 |
(pass-if-equal "2012-07-01T01:00:00+0100" "2012-07-01T01:00:00+0100" |
| 363 |
(date->string (time-tai->date (make-time time-tai 0 1341100835) |
| 364 |
3600) |
| 365 |
"~4")) |
| 366 |
(pass-if-equal "2012-07-01T01:00:01+0100" "2012-07-01T01:00:01+0100" |
| 367 |
(date->string (time-tai->date (make-time time-tai 0 1341100836) |
| 368 |
3600) |
| 369 |
"~4"))) |
| 370 |
|
| 371 |
(with-test-prefix "time-monotonic->date" |
| 372 |
(pass-if-equal "2012-07-01T00:59:59+0100" "2012-07-01T00:59:59+0100" |
| 373 |
(date->string (time-monotonic->date (make-time time-monotonic |
| 374 |
0 1341100833) |
| 375 |
3600) |
| 376 |
"~4")) |
| 377 |
(pass-if-equal "2012-07-01T00:59:60+0100" "2012-07-01T00:59:60+0100" |
| 378 |
(date->string (time-monotonic->date (make-time time-monotonic |
| 379 |
0 1341100834) |
| 380 |
3600) |
| 381 |
"~4")) |
| 382 |
(pass-if-equal "2012-07-01T01:00:00+0100" "2012-07-01T01:00:00+0100" |
| 383 |
(date->string (time-monotonic->date (make-time time-monotonic |
| 384 |
0 1341100835) |
| 385 |
3600) |
| 386 |
"~4")) |
| 387 |
(pass-if-equal "2012-07-01T01:00:01+0100" "2012-07-01T01:00:01+0100" |
| 388 |
(date->string (time-monotonic->date (make-time time-monotonic |
| 389 |
0 1341100836) |
| 390 |
3600) |
| 391 |
"~4"))) |
| 392 |
|
| 393 |
(with-test-prefix "time-tai->julian-day" |
| 394 |
(pass-if-equal "2012-07-01T00:59:59+0100" 212207860799/86400 |
| 395 |
(time-tai->julian-day (make-time time-tai 0 1341100833))) |
| 396 |
(pass-if-equal "2012-07-01T00:59:60+0100" 4912219/2 |
| 397 |
(time-tai->julian-day (make-time time-tai 0 1341100834))) |
| 398 |
(pass-if-equal "2012-07-01T01:00:00+0100" 4912219/2 |
| 399 |
(time-tai->julian-day (make-time time-tai 0 1341100835))) |
| 400 |
(pass-if-equal "2012-07-01T01:00:01+0100" 212207860801/86400 |
| 401 |
(time-tai->julian-day (make-time time-tai 0 1341100836)))) |
| 402 |
|
| 403 |
(with-test-prefix "time-monotonic->julian-day" |
| 404 |
(pass-if-equal "2012-07-01T00:59:59+0100" 212207860799/86400 |
| 405 |
(time-monotonic->julian-day (make-time time-monotonic 0 1341100833))) |
| 406 |
(pass-if-equal "2012-07-01T00:59:60+0100" 4912219/2 |
| 407 |
(time-monotonic->julian-day (make-time time-monotonic 0 1341100834))) |
| 408 |
(pass-if-equal "2012-07-01T01:00:00+0100" 4912219/2 |
| 409 |
(time-monotonic->julian-day (make-time time-monotonic 0 1341100835))) |
| 410 |
(pass-if-equal "2012-07-01T01:00:01+0100" 212207860801/86400 |
| 411 |
(time-monotonic->julian-day (make-time time-monotonic 0 1341100836)))) |
| 412 |
|
| 413 |
(with-test-prefix "date-week-number" |
| 414 |
(pass-if (= 0 (date-week-number (make-date 0 0 0 0 1 1 1984 0) 0))) |
| 415 |
(pass-if (= 0 (date-week-number (make-date 0 0 0 0 7 1 1984 0) 0))) |
| 416 |
(pass-if (= 1 (date-week-number (make-date 0 0 0 0 8 1 1984 0) 0)))) |
| 417 |
|
| 418 |
(let ((convert (match-lambda |
| 419 |
((y m d) |
| 420 |
(date->string (make-date 0 0 0 0 d m y 0) |
| 421 |
"~V"))))) |
| 422 |
;; Taken from the test suite for the reference implementation. |
| 423 |
(with-test-prefix "date->string ~V" |
| 424 |
(pass-if-equal "Thursday, week 53" "53" |
| 425 |
(convert '(2020 12 31))) |
| 426 |
(pass-if-equal "Friday, week 53 (previous year)" "53" |
| 427 |
(convert '(2021 1 1))) |
| 428 |
(pass-if-equal "Sunday, week 53 (previous year)" "53" |
| 429 |
(convert '(2021 1 3))) |
| 430 |
(pass-if-equal "Monday, week 1" "01" |
| 431 |
(convert '(2021 1 4))) |
| 432 |
|
| 433 |
(pass-if-equal "Sunday, week 52" "52" |
| 434 |
(convert '(2019 12 29))) |
| 435 |
(pass-if-equal "Monday, week 1 (next year)" "01" |
| 436 |
(convert '(2019 12 30))) |
| 437 |
(pass-if-equal "Tuesday, week 1 (next year)" "01" |
| 438 |
(convert '(2019 12 31))) |
| 439 |
(pass-if-equal "Wednesday, week 1" "01" |
| 440 |
(convert '(2020 1 1))) |
| 441 |
|
| 442 |
(pass-if-equal "Saturday, week 52" "52" |
| 443 |
(convert '(2016 12 31))) |
| 444 |
(pass-if-equal "Sunday, week 52 (previous year)" "52" |
| 445 |
(convert '(2017 1 1))) |
| 446 |
(pass-if-equal "Monday, week 1" "01" |
| 447 |
(convert '(2017 1 2))) |
| 448 |
(pass-if-equal "Sunday, week 1" "01" |
| 449 |
(convert '(2017 1 8))) |
| 450 |
(pass-if-equal "Monday, week 2" "02" |
| 451 |
(convert '(2017 1 9))) |
| 452 |
|
| 453 |
(pass-if-equal "Sunday, week 52" "52" |
| 454 |
(convert '(2014 12 28))) |
| 455 |
(pass-if-equal "Monday, week 1 (next year)" "01" |
| 456 |
(convert '(2014 12 29))) |
| 457 |
(pass-if-equal "Tuesday, week 1 (next year)" "01" |
| 458 |
(convert '(2014 12 30))) |
| 459 |
(pass-if-equal "Wednesday, week 1 (next year)" "01" |
| 460 |
(convert '(2014 12 31))) |
| 461 |
(pass-if-equal "Thursday, week 1" "01" |
| 462 |
(convert '(2015 1 1))) |
| 463 |
(pass-if-equal "Friday, week 1" "01" |
| 464 |
(convert '(2015 1 2))) |
| 465 |
(pass-if-equal "Saturday, week 1" "01" |
| 466 |
(convert '(2015 1 3))) |
| 467 |
(pass-if-equal "Sunday, week 1" "01" |
| 468 |
(convert '(2015 1 4))) |
| 469 |
(pass-if-equal "Monday, week 2" "02" |
| 470 |
(convert '(2015 1 5)))))) |
| 471 |
|
| 472 |
|
| 473 |
;; Local Variables: |
| 474 |
;; eval: (put 'with-tz 'scheme-indent-function 1) |
| 475 |
;; End: |