On 11/08/2016 11:24 PM, George Neuner wrote:
[...]
- I need to turn the UTC datetimes on all the results back into local
times with the right time zone
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
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.
Ryan
--
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.