diff --git a/brmsaptool.scm b/brmsaptool.scm index 9b88a29..06f8bfb 100644 --- a/brmsaptool.scm +++ b/brmsaptool.scm @@ -115,8 +115,19 @@ (define (string->month s) (list 2023 1)) -(define (month->string m) - "2023-01") +;; 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) + (sprintf "~A-~A~A" + y + (if (< m 10) " " "") + m)))) (define (month=? m n) #f) @@ -125,13 +136,15 @@ #f) (define (month-diff m n) - ; Inclusive? + ; Exclusive 1) (define (month-tests!) (display "[test] month ") ;; 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 equal ;; Comparison greater