;; Selector procedures for the components of a date. (define (month-name date) (first date)) (define (date-in-month date) (first (butfirst date))) ;; Return the number of days from January 1 to the first day ;; of the month named month. (define (days-preceding month) (cond ((equal? month 'january) 0) ((equal? month 'february) 31) ((equal? month 'march) 59) ((equal? month 'april) 90) ((equal? month 'may) 120) ((equal? month 'june) 151) ((equal? month 'july) 181) ((equal? month 'august) 212) ((equal? month 'september) 243) ((equal? month 'october) 273) ((equal? month 'november) 304) ((equal? month 'december) 334) ) ) ;; Return the number of days from January 1 to the given ;; date, inclusive. Date represents a date in 2002. (define (day-of-year date) (+ (days-preceding (month-name date)) (date-in-month date)) ) ;; Return the difference in days between earlier-date and ;; later-date. Earlier-date and later-date both represent ;; dates in 2002, with earlier-date being the earlier of ;; the two. (define (day-span earlier-date later-date) (+ 1 (- (day-of-year later-date) (day-of-year earlier-date) ) ) )