aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-03-01 02:47:11 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-03-01 02:47:11 +0100
commit114f3fa2f633c2ab72362daf9da319dbc82fdac5 (patch)
tree7b1a20552bf923cf2dafe3c005f58f7311643a79
parentResolve remaining TODO:s in config.scm. (diff)
downloadcalp-114f3fa2f633c2ab72362daf9da319dbc82fdac5.tar.gz
calp-114f3fa2f633c2ab72362daf9da319dbc82fdac5.tar.xz
Add unit test for days-in-interval.
-rw-r--r--module/datetime.scm1
-rw-r--r--tests/datetime.scm5
2 files changed, 6 insertions, 0 deletions
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))