Month formatting.

This commit is contained in:
Dominik Pantůček 2023-03-11 08:24:02 +01:00
parent a05a7c24d8
commit 9c2bafe279

View file

@ -112,22 +112,34 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Months support
;; Returns true if this is a valid month representation - a list with
;; two integer elements within the allowed range.
(define (month-valid? m)
(and (list? m)
(car m)
(cdr m)
(cadr m)
(nil? (cddr m))
(integer? (car m))
(integer? (cadr m))
(>= (car m 1000))
(<= (car m 9999))
(>= (cadr m 1))
(<= (cadr m 12))))
(define (string->month s)
(list 2023 1))
;; Formats (valid) month as YYYY-MM string
(define (month->string M)
(let ((y (car s))
(m (cadr s)))
(if (or (< y 1000)
(> y 9999)
(< m 1)
(> m 12))
(error 'string->month "Invalid month" M)
(if (month-valid? M)
(let ((y (car s))
(m (cadr s)))
(sprintf "~A-~A~A"
y
(if (< m 10) " " "")
m))))
m))
(error 'string->month "Invalid month" M)))
(define (month=? m n)
#f)