RE: Doing date arithmetic with SRFI-19
"Anton van Straaten" <[email protected]>
| Newsgroups | gmane.lisp.scheme.plt.schematics |
|---|---|
| Message-ID | <[email protected]> |
> This may be a fairly evil thing to be doing in the first place,
> but I've been doing date arithmetic using SRFI-19 like so:
It's not SRFI-19, but FWIW, I've used something even more evil (no
guarantees, it's not being used in anything mission-critical):
;; routines to support calendar dates with no time info
(require (lib "date.ss"))
;; adds support for (make-date year month day)
(define make-date
(let ((sys-make-date make-date))
(lambda args
(if (= (length args) 3)
(seconds->date (apply find-seconds 0 0 0 (reverse args)))
(apply sys-make-date args)))))
(define (date->seconds date)
(find-seconds 0 0 0 (date-day date) (date-month date) (date-year date)))
(define (days-between first-date last-date)
(/ (- (date->seconds last-date) (date->seconds first-date)) 24 60 60))
(define (date+ date days)
(seconds->date (+ (date->seconds date) (* days 24 60 60))))
-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com