[racket] Converting a date to seconds

From: Tony Garnock-Jones (tonyg at ccs.neu.edu)
Date: Mon Aug 1 11:47:50 EDT 2011

On 2011-07-31 6:47 AM, Mark Carter wrote:
> The alternative would be to use srfi/19, which has a usable make-date
> function, but doesn't seem to be able to convert that to seconds.

This will work, but it suffers from the problems of Unix's time_t (which
I hope aren't a problem for you, since you're interested in year

#lang racket
(require srfi/19)
(define (date->seconds date epoch-date)
    (time-difference (date->time-utc date)
                     (date->time-utc epoch-date))))
(date->seconds (current-date)
               (make-date 0 0 0 0 1 1 1970 0))

It gives the same answers as time(3).


Posted on the users mailing list.