On 11/06/2016 09:42 PM, George Neuner wrote:
[...]

The following in Racket gets it wrong.
e.g.,
[...]

=>
#(struct:sql-timestamp 2016 5 1 5 0 0 0 0) -> "2016-05-01 05:00:00Z"
"2016-05-01 00:00:00-05" -> #(struct:sql-timestamp 2016 5 1 0 0 0 0
-18000)
#(struct:sql-timestamp 2016 6 12 5 0 0 0 0) -> "2016-06-12 05:00:00Z"
"2016-06-12 00:00:00-05" -> #(struct:sql-timestamp 2016 6 12 0 0 0 0
-18000)


I've converted the output in both directions to show the difference.
As you can see, the date returned as text is correct, but the date
returned as a sql-timestamp value is wrong.

I believe the db library is correct: "2016-05-01 05:00:00Z" and "2016-05-01 00:00:00-05" refer to the same point in time.

  > (require srfi/19)
  > (define (string->utc x)
      (date->time-utc (string->date x "~Y~m~d ~H~M~S~z")))
  > (string->utc "2016-05-01 05:00:00Z")
  (tm:time 'time-utc 0 1462078800)
  > (string->utc "2016-05-01 00:00:00-05")
  (tm:time 'time-utc 0 1462078800)

Similarly, the two sql-timestamp values refer to the same point in time as above:

  > (define (sql->utc x) (date->time-utc (sql-datetime->srfi-date x)))
  > (sql->utc (sql-timestamp 2016 5 1 5 0 0 0 0))
  (tm:time 'time-utc 0 1462078800)
  > (sql->utc (sql-timestamp 2016 5 1 0 0 0 0 -18000))
  (tm:time 'time-utc 0 1462078800)

See also the notes on PostgreSQL timestamptz here: http://docs.racket-lang.org/db/notes.html#%28part._postgresql-timestamp-tz%29

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.

Reply via email to