Start using new period representation.

This commit is contained in:
Dominik Pantůček 2023-03-27 17:23:12 +02:00
parent ae0c00da50
commit d2ad2fdebb

View file

@ -79,7 +79,7 @@
(if (null? l)
(list #t
(if cb
(reverse (cons (cons cb #f) ps))
(reverse (cons (make-period cb #f) ps))
(reverse ps))
""
-1)
@ -97,7 +97,7 @@
(if (eq? mtype rmt)
(if cb
(loop (cdr l)
(cons (cons cb month) ps)
(cons (make-period cb month) ps)
#f)
(loop (cdr l)
ps
@ -110,8 +110,8 @@
;; Returns duration of period in months. Start is included, end is
;; not. The period contains the month just before the specified end.
(define (period->duration p)
(let* ((b (car p))
(e (cdr p))
(let* ((b (period-since p))
(e (period-before p))
(e- (if e e (*current-month*))))
(month-diff b e-)))
@ -176,27 +176,27 @@
(period-markers->periods
'((start (2022 3)) (stop (2022 10)) (start (2023 1)) (stop (2023 4))))
'(#t
(((2022 3) . (2022 10))
((2023 1) . (2023 4)))
(((2022 3) (2022 10) #f #f)
((2023 1) (2023 4) #f #f))
""
-1))
(test-equal? period-markers->periods-open
(period-markers->periods
'((start (2022 3)) (stop (2022 10)) (start (2023 1)) (stop (2023 4)) (start (2023 5))))
'(#t
(((2022 3) . (2022 10))
((2023 1) . (2023 4))
((2023 5) . #f))
(((2022 3) (2022 10) #f #f)
((2023 1) (2023 4) #f #f)
((2023 5) #f #f #f))
""
-1))
(test-eq? period-duration
(period->duration '((2023 1) . (2023 4))) 3)
(period->duration '((2023 1) (2023 4) #f #f)) 3)
(parameterize ((*current-month* (list 2023 4)))
(test-eq? period-duration
(period->duration '((2023 1) . #f)) 3))
(period->duration '((2023 1) #f #f #f)) 3))
(test-eq? periods-duration
(periods-duration '(((2022 3) . (2022 10))
((2023 1) . (2023 4))))
(periods-duration '(((2022 3) (2022 10) #f #f)
((2023 1) (2023 4) #f #f)))
10)
(test-true month-in-period?
(month-in-period? '((2022 1) . (2022 4)) '(2022 3)))