Sha256: 49a333b7a4d9af4f721df10c25f5ae9a0d9a6f592eec2ff53b97b55cba90e825

Contents?: true

Size: 1.28 KB

Versions: 130

Compression:

Stored size: 1.28 KB

Contents

#lang racket

(require racket/date)

(define (leap-year? year)
  (or (and (zero? (modulo year 4))
           (not (zero? (modulo year 100))))
      (zero? (modulo year 400))))

(define (days-in-month year month)
  (case month
    [(1 3 5 7 8 10 12) 31]
    [(4 6 9 11) 30]
    [(2) (if (leap-year? year) 29 28)]))

(define (make-date year month day)
  (seconds->date (find-seconds 0 0 0 day month year #f) #f))

(define (meetup-day year month weekday week)
  (let ([first-of-week
          (case week
            [(first) 1]
            [(second) 8]
            [(teenth) 13]
            [(third) 15]
            [(fourth) 22]
            [(last) (- (days-in-month year month) 6)]
            [else (raise-argument-error 'meetup-day "week" 3 year month weekday week)])]
        [weekday
          (case weekday
            [(Sunday) 0]
            [(Monday) 1]
            [(Tuesday) 2]
            [(Wednesday) 3]
            [(Thursday) 4]
            [(Friday) 5]
            [(Saturday) 6]
            [else (raise-argument-error 'meetup-day "weekday" 3 year month weekday week)])])
    (make-date year month
               (+ first-of-week
                    (modulo
                      (- weekday
                       (date-week-day (make-date year month first-of-week))) 7)))))

(provide meetup-day)

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.138 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.137 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.136 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.135 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.134 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.133 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.132 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.131 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.130 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.129 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.128 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.127 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.126 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.125 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.124 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.123 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.122 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.121 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.120 tracks/racket/exercises/meetup/example.rkt