Finish period conversion.

This commit is contained in:
Dominik Pantůček 2023-03-27 17:26:58 +02:00
parent d2ad2fdebb
commit ae8b994a39

View file

@ -125,9 +125,9 @@
(let ((m (if (null? ml)
(*current-month*)
(car ml))))
(and (or (not (cdr p))
(month<? m (cdr p)))
(not (month<? m (car p))))))
(and (or (not (period-before p))
(month<? m (period-before p)))
(not (month<? m (period-since p))))))
;; Returns true if given month is in at least one of the periods
;; given. Defaults to current month.
@ -145,8 +145,8 @@
;; Returns string representing a month period with possibly open end.
(define (period->string p)
(sprintf "~A..~A"
(month->string (car p))
(month->string (cdr p))))
(month->string (period-since p))
(month->string (period-before p))))
;; Returns a string representing a list of periods.
(define (periods->string ps)
@ -199,35 +199,35 @@
((2023 1) (2023 4) #f #f)))
10)
(test-true month-in-period?
(month-in-period? '((2022 1) . (2022 4)) '(2022 3)))
(month-in-period? '((2022 1) (2022 4) #f #f) '(2022 3)))
(test-false month-in-period?
(month-in-period? '((2022 1) . (2022 4)) '(2022 5)))
(month-in-period? '((2022 1) (2022 4) #f #f) '(2022 5)))
(test-true month-in-periods?
(month-in-periods? '(((2022 1) . (2022 4))
((2023 5) . (2023 10)))
(month-in-periods? '(((2022 1) (2022 4) #f #f)
((2023 5) (2023 10) #f #f))
'(2022 3)))
(test-true month-in-periods?
(month-in-periods? '(((2022 1) . (2022 4))
((2023 5) . (2023 10)))
(month-in-periods? '(((2022 1) (2022 4) #f #f)
((2023 5) (2023 10) #f #f))
'(2023 7)))
(test-false month-in-periods?
(month-in-periods? '(((2022 1) . (2022 4))
((2023 5) . (2023 10)))
(month-in-periods? '(((2022 1) (2022 4) #f #f)
((2023 5) (2023 10) #f #f))
'(2022 10)))
(test-equal? period->string
(period->string '((2022 1) . (2022 4)))
(period->string '((2022 1) (2022 4) #f #f))
"2022-01..2022-04")
(test-equal? periods->string
(periods->string '(((2022 1) . (2022 4))
((2022 12). (2023 2))))
(periods->string '(((2022 1) (2022 4) #f #f)
((2022 12) (2023 2) #f #f)))
"2022-01..2022-04, 2022-12..2023-02")
(test-false periods-match (periods-match '(((2022 1) . (2022 4))
((2022 12). (2023 2)))
(test-false periods-match (periods-match '(((2022 1) (2022 4) #f #f)
((2022 12) (2023 2) #f #f))
'(2022 5)))
(test-equal? periods-match (periods-match '(((2022 1) . (2022 4))
((2022 12). (2023 2)))
(test-equal? periods-match (periods-match '(((2022 1) (2022 4) #f #f)
((2022 12) (2023 2) #f #f))
'(2022 2))
'((2022 1) . (2022 4)))
'((2022 1) (2022 4) #f #f))
))
)