;;; ;;; Difference between dates addition ;;; to handle date formats of the form ;;; 2/15 for february 15th ;;; ;;; this file needs to be loaded after difference between dates ;;; ;; tests ;; returns #t if the date is a full-date (rather than a short date) (define (full-date? date) (if (sentence? date) #t #f)) ;; returns #t if date is a short-date (define (short-date? date) (word? date)) ;;; selectors ;month-name (define (month-name date) (if (full-date? date) (first date) (sd-month-name date) )) (define (sd-month-name sd) (cond ((equal? (sd-month-number sd) 1) 'january) ((equal? (sd-month-number sd) 2) 'february) ((equal? (sd-month-number sd) 3) 'march) ((equal? (sd-month-number sd) 4) 'april) ((equal? (sd-month-number sd) 5) 'may) ((equal? (sd-month-number sd) 6) 'june) ((equal? (sd-month-number sd) 7) 'july) ((equal? (sd-month-number sd) 8) 'august) ((equal? (sd-month-number sd) 9) 'september) ((equal? (sd-month-number sd) 10) 'october) ((equal? (sd-month-number sd) 11) 'november) ((equal? (sd-month-number sd) 12) 'december) )) ;; return the month number of the short date (define (sd-month-number sd) (if (equal? "/" (second sd)) (first sd) (word (first sd) (first (bf sd))) )) #| ;; tests for month-name (month-name '(january 3)) (month-name '1/3) (month-name '1/15) (month-name '11/2) (month-name '11/25) |# (define (second wd) (first (bf wd))) (define (second-last wd) (last (bl wd))) ;;;;; ;date-in-month (define (date-in-month date) (if (full-date? date) (last date) (part-after-slash date))) (define (part-after-slash sd) (word (if (equal? (last (butlast sd)) "/") "" (last (butlast sd))) (last sd) )) #| ;; date-in-month tests (date-in-month '(january 3)) (date-in-month '1/3) (date-in-month '12/3) (date-in-month '1/15) (date-in-month '12/25) |#