Month formatting.
This commit is contained in:
parent
194615aa1d
commit
a05a7c24d8
1 changed files with 17 additions and 4 deletions
|
@ -115,8 +115,19 @@
|
||||||
(define (string->month s)
|
(define (string->month s)
|
||||||
(list 2023 1))
|
(list 2023 1))
|
||||||
|
|
||||||
(define (month->string m)
|
;; Formats (valid) month as YYYY-MM string
|
||||||
"2023-01")
|
(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)
|
||||||
|
(sprintf "~A-~A~A"
|
||||||
|
y
|
||||||
|
(if (< m 10) " " "")
|
||||||
|
m))))
|
||||||
|
|
||||||
(define (month=? m n)
|
(define (month=? m n)
|
||||||
#f)
|
#f)
|
||||||
|
@ -125,13 +136,15 @@
|
||||||
#f)
|
#f)
|
||||||
|
|
||||||
(define (month-diff m n)
|
(define (month-diff m n)
|
||||||
; Inclusive?
|
; Exclusive
|
||||||
1)
|
1)
|
||||||
|
|
||||||
(define (month-tests!)
|
(define (month-tests!)
|
||||||
(display "[test] month ")
|
(display "[test] month ")
|
||||||
;; Parsing
|
;; Parsing
|
||||||
;; Formatting
|
(unit-test 'month->string (equal? (month->string '(2023 1)) "2023-01"))
|
||||||
|
(unit-test 'month->string-bad-year (with-handler (lambda (x) #t) (month->string '(999 12)) #f))
|
||||||
|
(unit-test 'month->string-bad-month (with-handler (lambda (x) #t) (month->string '(2023 13)) #f))
|
||||||
;; Comparison less
|
;; Comparison less
|
||||||
;; Comparison equal
|
;; Comparison equal
|
||||||
;; Comparison greater
|
;; Comparison greater
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue