aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/datetime/datetime.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-10-02 19:26:40 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-10-02 19:28:44 +0200
commit712654d4c023a2ab13190c6905d313e0ba897965 (patch)
treeb8505b420d6621022fa6a46271340071d8881322 /tests/unit/datetime/datetime.scm
parentMade displayln into a library export. (diff)
downloadcalp-712654d4c023a2ab13190c6905d313e0ba897965.tar.gz
calp-712654d4c023a2ab13190c6905d313e0ba897965.tar.xz
Rewrite test running system.
Diffstat (limited to '')
-rw-r--r--tests/unit/datetime/datetime.scm (renamed from tests/test/datetime.scm)212
1 files changed, 107 insertions, 105 deletions
diff --git a/tests/test/datetime.scm b/tests/unit/datetime/datetime.scm
index f73a0ad2..9f32d4a1 100644
--- a/tests/test/datetime.scm
+++ b/tests/unit/datetime/datetime.scm
@@ -362,22 +362,22 @@
(test-equal "Datetime->unix-time"
- 1656005146 (datetime->unix-time #2022-06-23T17:25:46Z))
+ 1656005146 (datetime->unix-time (datetime year: 2022 month: 06 day: 23 hour: 17 minute: 25 second: 46 tz: "UTC")))
(test-equal "Datetime->unix-time before epoch"
-62167219200
- (datetime->unix-time #0000-01-01T00:00:00Z))
+ (datetime->unix-time (datetime year: 0000 month: 01 day: 01 hour: 00 minute: 00 second: 00 tz: "UTC")))
-(test-equal "unix-time->datetime" #2020-09-13T12:26:40Z
+(test-equal "unix-time->datetime" (datetime year: 2020 month: 09 day: 13 hour: 12 minute: 26 second: 40 tz: "UTC")
(unix-time->datetime 1600000000))
-(test-equal "unix-time->datetime on epoch" #1970-01-01T00:00:00Z
+(test-equal "unix-time->datetime on epoch" (datetime year: 1970 month: 01 day: 01 hour: 00 minute: 00 second: 00 tz: "UTC")
(unix-time->datetime 0))
-(test-equal "unix-time->datetime before epoch" #1919-04-20T11:33:20Z
+(test-equal "unix-time->datetime before epoch" (datetime year: 1919 month: 04 day: 20 hour: 11 minute: 33 second: 20 tz: "UTC")
(unix-time->datetime -1600000000))
-;; (unix-time->datetime (expt 2 31)) ; => #2038-01-19T03:14:08Z
-;; (unix-time->datetime (1+ (expt 2 31))) ; => #2038-01-19T03:14:09Z
-;; (unix-time->datetime (- (expt 2 31))) ; => #1901-12-13T20:45:52Z
+;; (unix-time->datetime (expt 2 31)) ; => (datetime year: 2038 month: 01 day: 19 hour: 03 minute: 14 second: 08 tz: "UTC")
+;; (unix-time->datetime (1+ (expt 2 31))) ; => (datetime year: 2038 month: 01 day: 19 hour: 03 minute: 14 second: 09 tz: "UTC")
+;; (unix-time->datetime (- (expt 2 31))) ; => (datetime year: 1901 month: 12 day: 13 hour: 20 minute: 45 second: 52 tz: "UTC")
(test-assert "Current datetime returns a datetime"
@@ -412,50 +412,50 @@ as-datetime
(test-equal "365 days in regular year" 365 (days-in-year (date year: 2022)))
(test-equal "366 days in leap year" 366 (days-in-year (date year: 2000)))
-(test-equal "Start of month" #2020-01-01 (start-of-month #2020-01-15))
-(test-equal "End of month" #2000-02-29 (end-of-month #2000-02-01))
+(test-equal "Start of month" (date year: 2020 month: 01 day: 01) (start-of-month (date year: 2020 month: 01 day: 15)))
+(test-equal "End of month" (date year: 2000 month: 02 day: 29) (end-of-month (date year: 2000 month: 02 day: 01)))
-(test-equal "Start of year" #2020-01-01 (start-of-year #2020-12-31))
+(test-equal "Start of year" (date year: 2020 month: 01 day: 01) (start-of-year (date year: 2020 month: 12 day: 31)))
;; Note that end-of-year (apparently) doesn't exist
(test-group "Date streams"
(test-equal "Day stream"
- (list #2020-01-01 #2020-01-02 #2020-01-03 #2020-01-04 #2020-01-05)
- (stream->list 5 (day-stream #2020-01-01)))
+ (list (date year: 2020 month: 01 day: 01) (date year: 2020 month: 01 day: 02) (date year: 2020 month: 01 day: 03) (date year: 2020 month: 01 day: 04) (date year: 2020 month: 01 day: 05))
+ (stream->list 5 (day-stream (date year: 2020 month: 01 day: 01))))
(test-equal "Week stream"
- (list #2020-01-01 #2020-02-01 #2020-03-01 #2020-04-01 #2020-05-01)
- (stream->list 5 (month-stream #2020-01-01)))
+ (list (date year: 2020 month: 01 day: 01) (date year: 2020 month: 02 day: 01) (date year: 2020 month: 03 day: 01) (date year: 2020 month: 04 day: 01) (date year: 2020 month: 05 day: 01))
+ (stream->list 5 (month-stream (date year: 2020 month: 01 day: 01))))
(test-equal "Month stream"
- (list #2020-01-01 #2020-01-08 #2020-01-15 #2020-01-22 #2020-01-29)
- (stream->list 5 (week-stream #2020-01-01))))
+ (list (date year: 2020 month: 01 day: 01) (date year: 2020 month: 01 day: 08) (date year: 2020 month: 01 day: 15) (date year: 2020 month: 01 day: 22) (date year: 2020 month: 01 day: 29))
+ (stream->list 5 (week-stream (date year: 2020 month: 01 day: 01)))))
;; See time< tests for more context
(test-group "Min/max"
(test-equal "Time min"
- #07:40:50 (time-min #10:20:30 #07:40:50))
+ (time hour: 07 minute: 40 second: 50) (time-min (time hour: 10 minute: 20 second: 30) (time hour: 07 minute: 40 second: 50)))
(test-equal "Time max"
- #10:20:30 (time-max #10:20:30 #07:40:50))
+ (time hour: 10 minute: 20 second: 30) (time-max (time hour: 10 minute: 20 second: 30) (time hour: 07 minute: 40 second: 50)))
(test-equal "Date min"
- #2020-02-02 (date-min #2020-02-02 #2020-03-01))
+ (date year: 2020 month: 02 day: 02) (date-min (date year: 2020 month: 02 day: 02) (date year: 2020 month: 03 day: 01)))
(test-equal "Date max"
- #2020-03-01 (date-max #2020-02-02 #2020-03-01))
+ (date year: 2020 month: 03 day: 01) (date-max (date year: 2020 month: 02 day: 02) (date year: 2020 month: 03 day: 01)))
(test-equal "Datetime min"
- #2020-02-02T10:20:30 (datetime-min #2020-02-02T10:20:30 #2020-03-01T07:40:50))
+ (datetime year: 2020 month: 02 day: 02 hour: 10 minute: 20 second: 30) (datetime-min (datetime year: 2020 month: 02 day: 02 hour: 10 minute: 20 second: 30) (datetime year: 2020 month: 03 day: 01 hour: 07 minute: 40 second: 50)))
(test-equal "Datetime max"
- #2020-03-01T07:40:50 (datetime-max #2020-02-02T10:20:30 #2020-03-01T07:40:50)))
+ (datetime year: 2020 month: 03 day: 01 hour: 07 minute: 40 second: 50) (datetime-max (datetime year: 2020 month: 02 day: 02 hour: 10 minute: 20 second: 30) (datetime year: 2020 month: 03 day: 01 hour: 07 minute: 40 second: 50))))
-(test-equal "Week day" thu (week-day #2022-06-23))
+(test-equal "Week day" thu (week-day (date year: 2022 month: 06 day: 23)))
-(test-equal "week-1-start" #2019-12-30 (week-1-start #2020-01-01 mon))
+(test-equal "week-1-start" (date year: 2019 month: 12 day: 30) (week-1-start (date year: 2020 month: 01 day: 01) mon))
;; Possibly add case where the end of the year uses next years week numbers
-(test-equal "Week number at end of year" 53 (week-number #2008-12-31 sun))
-(test-equal "Week number at start of year" 53 (week-number #2009-01-01 sun))
+(test-equal "Week number at end of year" 53 (week-number (date year: 2008 month: 12 day: 31) sun))
+(test-equal "Week number at start of year" 53 (week-number (date year: 2009 month: 01 day: 01) sun))
-(test-equal #2008-12-28 (date-starting-week 53 (date year: 2008) sun))
-(test-equal #2007-12-30 (date-starting-week 1 (date year: 2008) sun))
+(test-equal (date year: 2008 month: 12 day: 28) (date-starting-week 53 (date year: 2008) sun))
+(test-equal (date year: 2007 month: 12 day: 30) (date-starting-week 1 (date year: 2008) sun))
(test-group "Week day name"
(test-equal "Simple" "Saturday" (week-day-name sat locale: en_US))
@@ -473,68 +473,68 @@ as-datetime
;; | | : | | : | || | : | || | : | || | : |s2|
;; | | : | | : | | : | | : : | |
(test-assert "End of S1 overlaps start of S2"
- (timespan-overlaps? #10:00:00 #12:00:00
- #11:00:00 #13:00:00))
+ (timespan-overlaps? (time hour: 10 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)
+ (time hour: 11 minute: 00 second: 00) (time hour: 13 minute: 00 second: 00)))
(test-assert "Start of S1 overlaps end of S2"
- (timespan-overlaps? #11:00:00 #13:00:00
- #10:00:00 #12:00:00))
+ (timespan-overlaps? (time hour: 11 minute: 00 second: 00) (time hour: 13 minute: 00 second: 00)
+ (time hour: 10 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)))
(test-assert "S1 complete encompasses S2"
- (timespan-overlaps? #10:00:00 #13:00:00
- #11:00:00 #12:00:00))
+ (timespan-overlaps? (time hour: 10 minute: 00 second: 00) (time hour: 13 minute: 00 second: 00)
+ (time hour: 11 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)))
(test-assert "S2 complete encompasses S1"
- (timespan-overlaps? #11:00:00 #12:00:00
- #10:00:00 #13:00:00))
+ (timespan-overlaps? (time hour: 11 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)
+ (time hour: 10 minute: 00 second: 00) (time hour: 13 minute: 00 second: 00)))
(test-assert "S1 is equal to S2"
- (timespan-overlaps? #11:00:00 #12:00:00
- #11:00:00 #12:00:00))
+ (timespan-overlaps? (time hour: 11 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)
+ (time hour: 11 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)))
(test-assert "S1 dosesn't overlap S2"
(not
- (timespan-overlaps? #10:00:00 #11:00:00
- #12:00:00 #13:00:00)))
+ (timespan-overlaps? (time hour: 10 minute: 00 second: 00) (time hour: 11 minute: 00 second: 00)
+ (time hour: 12 minute: 00 second: 00) (time hour: 13 minute: 00 second: 00))))
(test-assert "If the events only share an instant they don't overlap"
(not
- (timespan-overlaps? #10:00:00 #12:00:00
- #12:00:00 #14:00:00))))
+ (timespan-overlaps? (time hour: 10 minute: 00 second: 00) (time hour: 12 minute: 00 second: 00)
+ (time hour: 12 minute: 00 second: 00) (time hour: 14 minute: 00 second: 00)))))
-(test-equal #2022-06-25 (find-first-week-day sat #2022-06-23))
+(test-equal (date year: 2022 month: 06 day: 25) (find-first-week-day sat (date year: 2022 month: 06 day: 23)))
(test-group "All weekdays in <>"
(test-equal "month, if starting from beginning of month"
- (list #2022-06-03 #2022-06-10 #2022-06-17 #2022-06-24)
- (all-wday-in-month fri #2022-06-01))
+ (list (date year: 2022 month: 06 day: 03) (date year: 2022 month: 06 day: 10) (date year: 2022 month: 06 day: 17) (date year: 2022 month: 06 day: 24))
+ (all-wday-in-month fri (date year: 2022 month: 06 day: 01)))
(test-equal "month, if starting from the middle"
- (list #2022-06-24)
- (all-wday-in-month fri #2022-06-23))
+ (list (date year: 2022 month: 06 day: 24))
+ (all-wday-in-month fri (date year: 2022 month: 06 day: 23)))
(test-equal "year, if starting from the beggining"
- (list #2022-01-07 #2022-01-14 #2022-01-21 #2022-01-28 #2022-02-04 #2022-02-11 #2022-02-18 #2022-02-25 #2022-03-04 #2022-03-11 #2022-03-18 #2022-03-25 #2022-04-01 #2022-04-08 #2022-04-15 #2022-04-22 #2022-04-29 #2022-05-06 #2022-05-13 #2022-05-20 #2022-05-27 #2022-06-03 #2022-06-10 #2022-06-17 #2022-06-24 #2022-07-01 #2022-07-08 #2022-07-15 #2022-07-22 #2022-07-29 #2022-08-05 #2022-08-12 #2022-08-19 #2022-08-26 #2022-09-02 #2022-09-09 #2022-09-16 #2022-09-23 #2022-09-30 #2022-10-07 #2022-10-14 #2022-10-21 #2022-10-28 #2022-11-04 #2022-11-11 #2022-11-18 #2022-11-25 #2022-12-02 #2022-12-09 #2022-12-16 #2022-12-23 #2022-12-30)
- (all-wday-in-year fri #2022-01-01))
+ (list (date year: 2022 month: 01 day: 07) (date year: 2022 month: 01 day: 14) (date year: 2022 month: 01 day: 21) (date year: 2022 month: 01 day: 28) (date year: 2022 month: 02 day: 04) (date year: 2022 month: 02 day: 11) (date year: 2022 month: 02 day: 18) (date year: 2022 month: 02 day: 25) (date year: 2022 month: 03 day: 04) (date year: 2022 month: 03 day: 11) (date year: 2022 month: 03 day: 18) (date year: 2022 month: 03 day: 25) (date year: 2022 month: 04 day: 01) (date year: 2022 month: 04 day: 08) (date year: 2022 month: 04 day: 15) (date year: 2022 month: 04 day: 22) (date year: 2022 month: 04 day: 29) (date year: 2022 month: 05 day: 06) (date year: 2022 month: 05 day: 13) (date year: 2022 month: 05 day: 20) (date year: 2022 month: 05 day: 27) (date year: 2022 month: 06 day: 03) (date year: 2022 month: 06 day: 10) (date year: 2022 month: 06 day: 17) (date year: 2022 month: 06 day: 24) (date year: 2022 month: 07 day: 01) (date year: 2022 month: 07 day: 08) (date year: 2022 month: 07 day: 15) (date year: 2022 month: 07 day: 22) (date year: 2022 month: 07 day: 29) (date year: 2022 month: 08 day: 05) (date year: 2022 month: 08 day: 12) (date year: 2022 month: 08 day: 19) (date year: 2022 month: 08 day: 26) (date year: 2022 month: 09 day: 02) (date year: 2022 month: 09 day: 09) (date year: 2022 month: 09 day: 16) (date year: 2022 month: 09 day: 23) (date year: 2022 month: 09 day: 30) (date year: 2022 month: 10 day: 07) (date year: 2022 month: 10 day: 14) (date year: 2022 month: 10 day: 21) (date year: 2022 month: 10 day: 28) (date year: 2022 month: 11 day: 04) (date year: 2022 month: 11 day: 11) (date year: 2022 month: 11 day: 18) (date year: 2022 month: 11 day: 25) (date year: 2022 month: 12 day: 02) (date year: 2022 month: 12 day: 09) (date year: 2022 month: 12 day: 16) (date year: 2022 month: 12 day: 23) (date year: 2022 month: 12 day: 30))
+ (all-wday-in-year fri (date year: 2022 month: 01 day: 01)))
(test-equal "year, if starting from the middle"
- (list #2022-06-03 #2022-06-10 #2022-06-17 #2022-06-24 #2022-07-01 #2022-07-08 #2022-07-15 #2022-07-22 #2022-07-29 #2022-08-05 #2022-08-12 #2022-08-19 #2022-08-26 #2022-09-02 #2022-09-09 #2022-09-16 #2022-09-23 #2022-09-30 #2022-10-07 #2022-10-14 #2022-10-21 #2022-10-28 #2022-11-04 #2022-11-11 #2022-11-18 #2022-11-25 #2022-12-02 #2022-12-09 #2022-12-16 #2022-12-23 #2022-12-30)
- (all-wday-in-year fri #2022-06-01)))
+ (list (date year: 2022 month: 06 day: 03) (date year: 2022 month: 06 day: 10) (date year: 2022 month: 06 day: 17) (date year: 2022 month: 06 day: 24) (date year: 2022 month: 07 day: 01) (date year: 2022 month: 07 day: 08) (date year: 2022 month: 07 day: 15) (date year: 2022 month: 07 day: 22) (date year: 2022 month: 07 day: 29) (date year: 2022 month: 08 day: 05) (date year: 2022 month: 08 day: 12) (date year: 2022 month: 08 day: 19) (date year: 2022 month: 08 day: 26) (date year: 2022 month: 09 day: 02) (date year: 2022 month: 09 day: 09) (date year: 2022 month: 09 day: 16) (date year: 2022 month: 09 day: 23) (date year: 2022 month: 09 day: 30) (date year: 2022 month: 10 day: 07) (date year: 2022 month: 10 day: 14) (date year: 2022 month: 10 day: 21) (date year: 2022 month: 10 day: 28) (date year: 2022 month: 11 day: 04) (date year: 2022 month: 11 day: 11) (date year: 2022 month: 11 day: 18) (date year: 2022 month: 11 day: 25) (date year: 2022 month: 12 day: 02) (date year: 2022 month: 12 day: 09) (date year: 2022 month: 12 day: 16) (date year: 2022 month: 12 day: 23) (date year: 2022 month: 12 day: 30))
+ (all-wday-in-year fri (date year: 2022 month: 06 day: 01))))
;; TODO
in-date-range?
(test-equal "weekday-list" (list wed thu fri sat sun mon tue) (weekday-list wed))
-(test-equal "start of week" #2022-06-20 (start-of-week #2022-06-23 mon))
-(test-equal "end of week" #2022-06-26 (end-of-week #2022-06-23 mon))
+(test-equal "start of week" (date year: 2022 month: 06 day: 20) (start-of-week (date year: 2022 month: 06 day: 23) mon))
+(test-equal "end of week" (date year: 2022 month: 06 day: 26) (end-of-week (date year: 2022 month: 06 day: 23) mon))
(test-group "month-days"
- (call-with-values (lambda () (month-days #2022-06-01 mon))
+ (call-with-values (lambda () (month-days (date year: 2022 month: 06 day: 01) mon))
(lambda (before actual after)
- (test-equal "before" (list #2022-05-30 #2022-05-31) before)
- (test-equal "actual" (stream->list 30 (day-stream #2022-06-01)) actual)
- (test-equal "after" (list #2022-07-01 #2022-07-02 #2022-07-03) after))))
+ (test-equal "before" (list (date year: 2022 month: 05 day: 30) (date year: 2022 month: 05 day: 31)) before)
+ (test-equal "actual" (stream->list 30 (day-stream (date year: 2022 month: 06 day: 01))) actual)
+ (test-equal "after" (list (date year: 2022 month: 07 day: 01) (date year: 2022 month: 07 day: 02) (date year: 2022 month: 07 day: 03)) after))))
(test-group "Days in interval"
- (test-equal "Steps from start to end of month" 31 (days-in-interval #2022-01-01 #2022-01-31))
- (test-error "Negative intervals should fail" 'misc-error (days-in-interval #2022-01-01 #2020-01-31)))
+ (test-equal "Steps from start to end of month" 31 (days-in-interval (date year: 2022 month: 01 day: 01) (date year: 2022 month: 01 day: 31)))
+ (test-error "Negative intervals should fail" 'misc-error (days-in-interval (date year: 2022 month: 01 day: 01) (date year: 2020 month: 01 day: 31))))
-(test-equal "Year day" 191 (year-day #2020-07-09))
+(test-equal "Year day" 191 (year-day (date year: 2020 month: 07 day: 09)))
(test-group "Convertions to decimal time"
(test-group "Time->decimal-hour"
@@ -550,7 +550,7 @@ in-date-range?
(test-error "Can't get length of month without information about which month"
'misc-error (datetime->decimal-hour (datetime month: 1)))
(test-equal "Can get length of month if we have a month"
- (* 31 24.0) (datetime->decimal-hour (datetime month: 1) #2020-01-01))))
+ (* 31 24.0) (datetime->decimal-hour (datetime month: 1) (date year: 2020 month: 01 day: 01)))))
;; TODO
date-range
@@ -569,20 +569,20 @@ date-range
(test-equal "02" (datetime->string (datetime month: 2) "~m"))
(test-equal "04" (datetime->string (datetime day: 4) "~d"))
(test-equal " 4" (datetime->string (datetime day: 4) "~e"))
- (test-equal "1600000000" (datetime->string #2020-09-13T12:26:40Z "~s"))
+ (test-equal "1600000000" (datetime->string (datetime year: 2020 month: 09 day: 13 hour: 12 minute: 26 second: 40 tz: "UTC") "~s"))
- (test-equal "2022-10-20" (datetime->string (datetime date: #2022-10-20) "~1"))
- (test-equal "10:20:30" (datetime->string (datetime time: #10:20:30) "~3"))
+ (test-equal "2022-10-20" (datetime->string (datetime date: (date year: 2022 month: 10 day: 20)) "~1"))
+ (test-equal "10:20:30" (datetime->string (datetime time: (time hour: 10 minute: 20 second: 30)) "~3"))
(test-group "Locale dependant (en_US)"
- (test-equal "Saturday" (datetime->string (datetime date: (find-first-week-day sat #2020-01-01)) "~A" en_US))
- (test-equal "Sat" (datetime->string (datetime date: (find-first-week-day sat #2020-01-01)) "~a" en_US))
+ (test-equal "Saturday" (datetime->string (datetime date: (find-first-week-day sat (date year: 2020 month: 01 day: 01))) "~A" en_US))
+ (test-equal "Sat" (datetime->string (datetime date: (find-first-week-day sat (date year: 2020 month: 01 day: 01))) "~a" en_US))
(test-equal "January" (datetime->string (datetime date: (date month: 1)) "~B" en_US))
(test-equal "Jan" (datetime->string (datetime date: (date month: 1)) "~b" en_US)))
(test-group "Locale dependant (sv_SE)"
- (test-equal "lördag" (datetime->string (datetime date: (find-first-week-day sat #2020-01-01)) "~A" sv_SE))
- (test-equal "lör" (datetime->string (datetime date: (find-first-week-day sat #2020-01-01)) "~a" sv_SE))
+ (test-equal "lördag" (datetime->string (datetime date: (find-first-week-day sat (date year: 2020 month: 01 day: 01))) "~A" sv_SE))
+ (test-equal "lör" (datetime->string (datetime date: (find-first-week-day sat (date year: 2020 month: 01 day: 01))) "~a" sv_SE))
(test-equal "januari" (datetime->string (datetime date: (date month: 1)) "~B" sv_SE))
(test-equal "jan" (datetime->string (datetime date: (date month: 1)) "~b" sv_SE)))
@@ -593,17 +593,17 @@ date-range
(test-equal "Default fomat specifier gives ISO-formatted date"
- "2006-01-02T15:04:05" (datetime->string #2006-01-02T15:04:05))
+ "2006-01-02T15:04:05" (datetime->string (datetime year: 2006 month: 01 day: 02 hour: 15 minute: 04 second: 05)))
(test-group "Invalid specifiers"
(test-equal "" (datetime->string (datetime) "~x" allow-unknown?: #t))
(test-error 'misc-error (datetime->string (datetime) "~x")))
(test-group "Print syntax for datatypes"
- (test-equal "Date writer" "#2020-01-02" (with-output-to-string (lambda () (write #2020-01-02))))
- (test-equal "Time writer" "#20:30:40" (with-output-to-string (lambda () (write #20:30:40))))
- (test-equal "Datetime writer" "#2020-01-02T20:30:40" (with-output-to-string (lambda () (write #2020-01-02T20:30:40))))
- (test-equal "Datetime writer (with tz)" "#2020-01-02T20:30:40Z" (with-output-to-string (lambda () (write #2020-01-02T20:30:40Z))))))
+ (test-equal "Date writer" "#2020-01-02" (with-output-to-string (lambda () (write (date year: 2020 month: 01 day: 02)))))
+ (test-equal "Time writer" "#20:30:40" (with-output-to-string (lambda () (write (time hour: 20 minute: 30 second: 40)))))
+ (test-equal "Datetime writer" "#2020-01-02T20:30:40" (with-output-to-string (lambda () (write (datetime year: 2020 month: 01 day: 02 hour: 20 minute: 30 second: 40)))))
+ (test-equal "Datetime writer (with tz)" "#2020-01-02T20:30:40Z" (with-output-to-string (lambda () (write (datetime year: 2020 month: 01 day: 02 hour: 20 minute: 30 second: 40 tz: "UTC")))))))
;; Really basic tests, since these are rather thin wrappers
(test-equal "date->string" "0000-00-00" (date->string (date)))
@@ -616,25 +616,25 @@ date-range
(test-assert "Zero dates are all equal"
(date=))
(test-assert "A single date is equal to itself"
- (date=? #2020-10-20))
+ (date=? (date year: 2020 month: 10 day: 20)))
(test-assert "Two dates are equal to each other"
- (date= #2020-10-20 #2020-10-20))
+ (date= (date year: 2020 month: 10 day: 20) (date year: 2020 month: 10 day: 20)))
(test-assert "Two dates which are NOT equal to each other"
- (not (date= #2020-10-20 #2020-10-21)))
+ (not (date= (date year: 2020 month: 10 day: 20) (date year: 2020 month: 10 day: 21))))
(test-assert "More than two dates which are all equal"
- (date=? #2020-10-20 #2020-10-20 #2020-10-20)))
+ (date=? (date year: 2020 month: 10 day: 20) (date year: 2020 month: 10 day: 20) (date year: 2020 month: 10 day: 20))))
(test-group "time"
(test-assert "Zero times are all equal"
(time=))
(test-assert "A single time is equal to itself"
- (time=? #20:30:40))
+ (time=? (time hour: 20 minute: 30 second: 40)))
(test-assert "Two times are equal to each other"
- (time= #20:30:40 #20:30:40))
+ (time= (time hour: 20 minute: 30 second: 40) (time hour: 20 minute: 30 second: 40)))
(test-assert "Two times which are NOT equal to each other"
- (not (time= #20:30:40 #10:30:40)))
+ (not (time= (time hour: 20 minute: 30 second: 40) (time hour: 10 minute: 30 second: 40))))
(test-assert "More than two times which are all equal"
- (time=? #20:30:40 #20:30:40 #20:30:40)))
+ (time=? (time hour: 20 minute: 30 second: 40) (time hour: 20 minute: 30 second: 40) (time hour: 20 minute: 30 second: 40))))
(test-group "Datetime"
(test-assert "Zero datetimes \"all\" are equal"
@@ -722,30 +722,30 @@ date/-time> date/-time>? date/-time>= date/-time>=?
(test-group "Simple cases"
(test-group "Days"
- (test-equal "Add" #2020-01-06 (date+ #2020-01-01 (date day: 5)))
- (test-equal "Remove" #2020-01-01 (date- #2020-01-06 (date day: 5))))
+ (test-equal "Add" (date year: 2020 month: 01 day: 06) (date+ (date year: 2020 month: 01 day: 01) (date day: 5)))
+ (test-equal "Remove" (date year: 2020 month: 01 day: 01) (date- (date year: 2020 month: 01 day: 06) (date day: 5))))
(test-group "Months"
- (test-equal "Add" #2020-06-01 (date+ #2020-01-01 (date month: 5)))
- (test-equal "Remove" #2020-01-01 (date- #2020-06-01 (date month: 5))))
+ (test-equal "Add" (date year: 2020 month: 06 day: 01) (date+ (date year: 2020 month: 01 day: 01) (date month: 5)))
+ (test-equal "Remove" (date year: 2020 month: 01 day: 01) (date- (date year: 2020 month: 06 day: 01) (date month: 5))))
(test-group "Years"
- (test-equal "Add" #2022-01-01 (date+ #2020-01-01 (date year: 2)))
- (test-equal "Remove" #2020-01-01 (date- #2022-01-01 (date year: 2)))))
+ (test-equal "Add" (date year: 2022 month: 01 day: 01) (date+ (date year: 2020 month: 01 day: 01) (date year: 2)))
+ (test-equal "Remove" (date year: 2020 month: 01 day: 01) (date- (date year: 2022 month: 01 day: 01) (date year: 2)))))
(test-group "Many operands"
- (test-equal #2021-02-02
- (date+ #2020-01-01
+ (test-equal (date year: 2021 month: 02 day: 02)
+ (date+ (date year: 2020 month: 01 day: 01)
(date day: 1)
(date month: 1)
(date year: 1))))
(test-group "Overflow"
;; Years don't overflow, so no need to test
- (test-equal "Day overflow" #2022-02-01 (date+ #2022-01-31 (date day: 1)))
- (test-equal "Month overflow" #2023-01-01 (date+ #2022-12-01 (date month: 1)))
- (test-equal "Date+Month overflow" #2023-01-01 (date+ #2022-12-31 (date day: 1))))
+ (test-equal "Day overflow" (date year: 2022 month: 02 day: 01) (date+ (date year: 2022 month: 01 day: 31) (date day: 1)))
+ (test-equal "Month overflow" (date year: 2023 month: 01 day: 01) (date+ (date year: 2022 month: 12 day: 01) (date month: 1)))
+ (test-equal "Date+Month overflow" (date year: 2023 month: 01 day: 01) (date+ (date year: 2022 month: 12 day: 31) (date day: 1))))
;; NOTE
- (test-equal #2020-02-31 (date+ #2020-01-31 (date month: 1)))
+ (test-equal (date year: 2020 month: 02 day: 31) (date+ (date year: 2020 month: 01 day: 31) (date month: 1)))
)
(test-group "Time"
@@ -755,31 +755,31 @@ date/-time> date/-time>? date/-time>= date/-time>=?
(test-group "Simple cases"
(test-group "Seconds"
- (test-equal "Add" #20:00:40 (time+ #20:00:00 (time second: 40)))
- (test-equal "Remove" #20:00:00 (time- #20:00:40 (time second: 40))))
+ (test-equal "Add" (time hour: 20 minute: 00 second: 40) (time+ (time hour: 20 minute: 00 second: 00) (time second: 40)))
+ (test-equal "Remove" (time hour: 20 minute: 00 second: 00) (time- (time hour: 20 minute: 00 second: 40) (time second: 40))))
(test-group "Minutes"
- (test-equal "Add" #20:10:00 (time+ #20:00:00 (time minute: 10)))
- (test-equal "Remove" #20:00:00 (time- #20:10:00 (time minute: 10))))
+ (test-equal "Add" (time hour: 20 minute: 10 second: 00) (time+ (time hour: 20 minute: 00 second: 00) (time minute: 10)))
+ (test-equal "Remove" (time hour: 20 minute: 00 second: 00) (time- (time hour: 20 minute: 10 second: 00) (time minute: 10))))
(test-group "Hours"
- (test-equal "Add" #22:00:00 (time+ #20:00:00 (time hour: 2)))
- (test-equal "Remove" #20:00:00 (time- #22:00:00 (time hour: 2)))))
+ (test-equal "Add" (time hour: 22 minute: 00 second: 00) (time+ (time hour: 20 minute: 00 second: 00) (time hour: 2)))
+ (test-equal "Remove" (time hour: 20 minute: 00 second: 00) (time- (time hour: 22 minute: 00 second: 00) (time hour: 2)))))
(test-group "Overflowing cases"
(test-group "Addition"
(test-group "Single overflow"
- (call-with-values (lambda () (time+ #20:00:00 (time hour: 5)))
+ (call-with-values (lambda () (time+ (time hour: 20 minute: 00 second: 00) (time hour: 5)))
(lambda (result overflow)
(test-equal "Time" (time hour: 1) result)
(test-equal "Overflow" 1 overflow))))
(test-group "Mulitple overflows"
- (call-with-values (lambda () (time+ #20:00:00 (time hour: 5) (time hour: 24)))
+ (call-with-values (lambda () (time+ (time hour: 20 minute: 00 second: 00) (time hour: 5) (time hour: 24)))
(lambda (result overflow)
(test-equal "Time" (time hour: 1) result)
(test-equal "Overflow" 2 overflow)))))
(test-group "Subtraction"
(test-group "Single overflow"
- (call-with-values (lambda () (time- #20:00:00 (time hour: 25)))
+ (call-with-values (lambda () (time- (time hour: 20 minute: 00 second: 00) (time hour: 25)))
(lambda (result overflow)
(test-equal "Time" (time hour: 19) result)
(test-equal "Overflow" 1 overflow))))
@@ -794,10 +794,10 @@ datetime+ datetime-
(test-group "Date difference"
(test-assert "The differente between a date and itself is zero"
- (date-zero? (date-difference #2022-02-02 #2022-02-02)))
+ (date-zero? (date-difference (date year: 2022 month: 02 day: 02) (date year: 2022 month: 02 day: 02))))
(test-error "Later date must be first" 'misc-error
- (date-difference #2020-01-01 #2021-01-01))
+ (date-difference (date year: 2020 month: 01 day: 01) (date year: 2021 month: 01 day: 01)))
(test-error "Negative months are invalid" 'misc-error
(date-difference (date) (date month: -1)))
@@ -808,3 +808,5 @@ datetime+ datetime-
;; TODO
datetime-difference
+
+'((datetime))