[racket] Library for date arithmetic?

From: Ismael Figueroa (ifigueroap at gmail.com)
Date: Tue Mar 11 15:32:18 EDT 2014

Working with a custom handin-server, I have a date value which represents a
deadline, but I also want to allow late submission up to 3 days later than
that (well, an arbitrary number of days). Hence, I need to check whether
the current date is at most 3 days later than the first one.

In the configuration file I read a custom entry for the deadline,
indicating year, month, day, hours, minutes and seconds. Then I guess I
could do:

(define d      (seconds->date (find-seconds seconds minutes hours day month
year)))
(define d+1 (seconds->date (find-seconds seconds minutes hours (+ day 1)
month year))
(define d+2 (seconds->date (find-seconds seconds minutes hours (+ day 2)
month year))
(define d+3 (seconds->date (find-seconds seconds minutes hours (+ day 3)
month year))

And then do a comparison, like

(let ([now (current-seconds)])
   (or (> now (date->seconds d)) (> now (date->seconds d+1) ...))

But this looks too low level to me, and surprisingly the utilities provided
by racket/date are somewhat sparse.

Does anyone know about a higher-level library for manipulating dates, and
performing arithmetic comparisons and operations?

Ideally I'd imagine something like:

(let ([now (current-date)])
   (cond
      [(date< now d) ...] ;; ok
      [(date< now (date-add-day d 1)) ... ] ;; warning 1 day   late
      [(date< now (date-add-day d 2)) ... ] ;; warning 2 days late
      ....
      [else ...] ;; submission rejected because it is past deadline + extra
days
)

Thanks!
-- 
Ismael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140311/4f8fea66/attachment.html>

Posted on the users mailing list.