From 114f3fa2f633c2ab72362daf9da319dbc82fdac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 1 Mar 2022 02:47:11 +0100 Subject: Add unit test for days-in-interval. --- module/datetime.scm | 1 + tests/datetime.scm | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/module/datetime.scm b/module/datetime.scm index 3b03bf53..9657a803 100644 --- a/module/datetime.scm +++ b/module/datetime.scm @@ -535,6 +535,7 @@ (iota (modulo (- (* 7 5) month-len month-start) 7) 1))))) +;; The amount of days in the given interval, both end pointts inclusive (define-public (days-in-interval start-date end-date) (let ((diff (date-difference (date+ end-date (date day: 1)) start-date))) (with-streams diff --git a/tests/datetime.scm b/tests/datetime.scm index eb9c02b6..6da385e2 100644 --- a/tests/datetime.scm +++ b/tests/datetime.scm @@ -15,6 +15,7 @@ leap-year? string->date string->time string->datetime parse-month + days-in-interval ) ((ice-9 format) format) ((hnh util) let*) @@ -239,3 +240,7 @@ (test-equal -1 (parse-month "inv" en_US)) (test-equal 5 (parse-month "mAJ" sv_SE)) + + +(test-equal "Days in regular year" 365 (days-in-interval #2021-01-01 #2021-12-31)) +(test-equal "Days in leap year" 366 (days-in-interval #2020-01-01 #2020-12-31)) -- cgit v1.2.3