|
;; Copyright (c) <2014> <eval> |
|
;; |
|
;; Permission is hereby granted, free of charge, to any person obtaining a copy |
|
;; of this software and associated documentation files (the Software), to deal |
|
;; in the Software without restriction, including without limitation the rights |
|
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
;; copies of the Software, and to permit persons to whom the Software is |
|
;; furnished to do so, subject to the following conditions: |
|
;; |
|
;; The above copyright notice and this permission notice shall be included in |
|
;; all copies or substantial portions of the Software. |
|
;; |
|
;; THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
;; THE SOFTWARE. |
|
|
|
#lang racket |
|
(require racket/date srfi/1) |
|
(define (is-leap-year? y) |
|
(let ([t(map (λ(y t)(zero?(remainder y t))) (list y y y) '(400 100 4))]) |
|
(and (boolean=? (car t)(cadr t)) (caddr t)))) |
|
(define (make-dates-list y m) |
|
(case m |
|
[(1 3 5 7 8 10 12)(iota 31 1)] |
|
[(4 6 9 11)(iota 30 1)] |
|
[else (iota(if(is-leap-year? y) 29 28)1)])) |
|
(define (zeller year month day) |
|
(let* ((a (quotient (- 14 month) 12)) |
|
(y (- year a)) |
|
(m (+ month (* 12 a) -2))) |
|
(modulo (+ day y (quotient y 4) (- (quotient y 100)) |
|
(quotient y 400) (quotient (* 31 m) 12))7))) |
|
(define (make-cal-list y m) |
|
(let ([dates(map (λ(n)(string-append (if (> n 9) " " " ")(number->string n)))(make-dates-list y m))] |
|
[blank (make-list (modulo(zeller y m 1)7)" ")]) |
|
(append blank dates))) |
|
(define (cal-disp ls) |
|
(if (< (length ls)7) |
|
(begin(for-each display ls)(newline)) |
|
(begin |
|
(for-each display (take ls 7))(newline) |
|
(cal-disp (list-tail ls 7))))) |
|
(define main |
|
(let ([now (current-date)]) |
|
(cal-disp(make-cal-list (date-year now)(date-month now))))) |