<br><div class="gmail_quote">On Tue, May 19, 2009 at 11:04 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On May 19, Paul Graham wrote:<br>
> I'd appreciate it if anyone can tell me if this is the standard way<br>
> to get a GMT time from Mzscheme:<br>
><br>
> (define (gmt-date sec)<br>
> (let ((offset (date-time-zone-offset (seconds->date sec))))<br>
> (seconds->date (- sec offset))))<br>
><br>
> It seems ugly to have to call seconds->date twice.<br>
<br>
</div>I think that this is the only way to do this now, but the resulting<br>
`date' is going to be broken with respect to its time zone offset...<br>
But -- the `seconds->date' function uses the system to get the time,<br>
so you can hack around this by setting your desired TZ environment<br>
variable, for example:<br>
<br>
(define (current-gmt-date tz)<br>
(putenv "TZ" ":GMT")<br>
(seconds->date (current-seconds)))<br>
<br>
or more generally<br>
<br>
(define (current-date/tz tz)<br>
(putenv "TZ" tz)<br>
(seconds->date (current-seconds)))<br>
(current-date/tz ":US/Eastern")<br></blockquote><div><br>SRFI 19 makes things a bit easier if you are okay with using a different date struct.<br><br>(require srfi/19)<br>(current-date 0) ;; for current time in GMT.<br>
<br>;; And for any second<br>(define (seconds->date/offset sec (offset 0))<br> (julian-day->date (time-utc->julian-day (make-time 'time-utc 0 sec)) offset))<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><div>> Also, is the offset always going to get me back to GMT, or do I have<br>
> to consider daylight savings time?<br>
</div></blockquote><div><br>Daylight saving depends on the timezone (e.g. America/New_York or America/Los_Angeles), not offset. Eli's solution might work for you, or you might have to parse the timezone database to determine the offset by timezone and date if you need other than GMT.<br>
<br>Cheers,<br>yc<br></div></div><br>