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.180 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.179 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.178 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.177 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.176 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.175 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.174 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.173 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.172 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.171 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.170 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.169 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.167 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.166 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.165 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.164 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.163 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.162 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.161 tracks/racket/exercises/meetup/example.rkt
trackler-2.2.1.160 tracks/racket/exercises/meetup/example.rkt