diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2020-01-13 00:21:54 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2020-01-13 00:21:54 +0100 |
commit | 79792b0777483b449630f264d7784db18a6a501c (patch) | |
tree | 7e8354f12db6c831b3802c56bb1ed4bcef64c8db /module | |
parent | Fix HTML preview prev month. (diff) | |
download | calp-79792b0777483b449630f264d7784db18a6a501c.tar.gz calp-79792b0777483b449630f264d7784db18a6a501c.tar.xz |
Better leap year support.
Diffstat (limited to 'module')
-rw-r--r-- | module/output/html.scm | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/module/output/html.scm b/module/output/html.scm index 4531964e..d444155a 100644 --- a/module/output/html.scm +++ b/module/output/html.scm @@ -208,11 +208,18 @@ (attr ev 'DTSTART))) events)))))) -(define (days-in-month n) - (cond ((memv n '(1 3 5 7 8 10 12)) 31) - ((memv n '(4 6 9 11)) 30) - ;; TODO leap years - (else 28))) +(define (days-in-month date) + (define rem=0? (compose zero? remainder)) + (let ((m (date-month date))) + (cond ((memv m '(1 3 5 7 8 10 12)) 31) + ((memv m '(4 6 9 11)) 30) + (else + ;; Please don't mention non-gregorian calendars. + (let ((y (date-year date))) + (if (and (rem=0? y 4) + (or (not (rem=0? y 100)) + (rem=0? y 400))) + 29 28)))))) (define (previous-month n) (1+ (modulo (- n 2) 12))) @@ -251,8 +258,9 @@ (thead (tr ,@(map (lambda (d) `(td ,d)) '(MÅ TI ON TO FR LÖ SÖ)))) (tbody ,@(let recur ((lst (let* ((month (date-month date)) - (month-len (days-in-month month)) - (prev-month-len (days-in-month (previous-month month))) + (month-len (days-in-month date)) + (prev-month-len (days-in-month (month- date) #; (previous-month month) + )) (month-start (week-day date))) (append (map (td '(class "prev") (month- date)) (iota month-start (1+ (- prev-month-len month-start)))) |