Hi Ryan,
On 11/9/2016 2:18 AM, Ryan Culpepper wrote:
Does the following do what you want?
(require srfi/19)
;; date-at-tz : Date Integer -> Date
;; Returns date of equivalent instant in given timezone.
(define (date-at-tz d tz)
(let ([t (date->time-utc d)])
(time-utc->date t tz)))
(define fmt "~Y-~m-~d ~H:~M:~S~z")
(define s1 "2016-11-09 01:12:00Z")
(define d1 (string->date s1 fmt))
(define d2 (date-at-tz d1 (* -5 60 60)))
(date->string d1 fmt)
;; => "2016-11-09 01:23:00Z"
(date->string d2 fmt)
;; => "2016-11-08 20:23:00-0500"
(equal? (date->time-utc d1) (date->time-utc d2))
;; => #t
Yes this works, thank you! I think I goofed in starting down the road
of add-duration ... which may have been a carry over from fighting with
seconds->date.
Another option is to let PostgreSQL do it for you using AT TIME ZONE
(or the timezone function):
select ('2016-11-09 01:23:00Z'::timestamptz)
at time zone 'us/eastern';
=> 2016-11-08 20:23:00
But beware that PostgreSQL interprets numerical timezones backwards
(sometimes?) (see
https://www.postgresql.org/message-id/20151021034109.3017....@wrigleys.postgresql.org).
I've read that thread and the docs and I still can't make sense of it.
I can use Postgresql also - but only if I return the time as text.
Returning it as a timestamptz gives me the right time, but in UTC.
Either way it's inconvenient. As text, I have to convert it again to
use it in a new query. As timestamptz the value is immediately usable,
but not suited for viewing. 6 of one, 1/2 dozen of the other.
But none of this solves the problem of timestamps that span daylight
saving. No matter which TZ you pick, some of the conversions will be
wrong. Obviously such a query can be split at the time change, but then
you have to know when daylight saving starts and stops. Which means
checking the TZ database. Sigh.
George
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.