Skip to content

Instantly share code, notes, and snippets.

@ebal5
Last active August 29, 2015 14:08
Show Gist options
  • Save ebal5/fffd38830703cad8f37b to your computer and use it in GitHub Desktop.
Save ebal5/fffd38830703cad8f37b to your computer and use it in GitHub Desktop.
make-calendar

make-calendar

This program is made for calendar-programming. I want to lean Racket(not Tennis ,or Badminton ,and any other sports) language. So this program is wrriten in Racket.

How to use

I'll tell you how to use it.

1.check for the racket. if you don't install yet, this program won't work Please install racket! 2.Run put "racket calendar.rkt" to shell or command-prompt(win) to run this program. Or you can make executable by using "raco exe calendar.rkt" command. Of course you can use DrRacket to run this program.

Contact me

If you want to ask me ,then please leave a comment ,or reply to @muminn4 on Twitter.

Thank you for reading and visiting here!!

;; 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)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment