Implement ISO date to month conversion.

This commit is contained in:
Dominik Pantůček 2023-04-03 20:54:10 +02:00
parent 0586bb4cfc
commit c175dc2ae4

View file

@ -153,6 +153,14 @@
(list (quotient mi 12)
(+ (remainder mi 12) 1))))
;; Converts ISO date to single month
(define (iso-date->month str)
(let* ((lst (string-split str "-"))
(year (car lst))
(mon (cadr lst)))
(make-month (string->number year)
(string->number mon))))
;; Performs self-tests of the month module.
(define (month-tests!)
(run-tests
@ -177,6 +185,7 @@
(test-eq? month-diff (month-diff '(2023 1) '(2023 12)) 11)
(test-eq? month-diff (month-diff '(2023 1) '(2022 2)) -11)
(test-eq? month-add (month-add '(2023 1) 2) '(2023 3))
(test-equal? iso-date->month (iso-date->month "2023-04-03") '(2023 4))
))
)