Hi all,

Got a wierd problem handling dates. I am retrieving a UTC timestamp from a Postgresql (9.3.9) database, converting it to a date* and then offsetting to a (variable) time zone.


eliding a lot of unrelated code:

        :
        (require (only-in  srfi/19  date->string)
                 (except-in racket/date date->string))
        :
        (set! result (query-row db sql-cmd  userid ))
        :
        (set! expires (vector-ref result 1))
   (eprintf "=> expires ~s~n" expires)
        (set! expires (sql-datetime->srfi-date expires))
   (eprintf "=> expires ~s~n" expires)
        :
        (let* [
               ; convert UTC expire time to user's timezone
               (expires (seconds->date (date*->seconds expires #f)
                                        timezone))
               :
              ]
   (eprintf "=> expires ~s~n" expires)
            :

with 'timezone'  =  -4  (EDT)  this produces:

=> expires #(struct:sql-timestamp 2015 8 22 20 26 49585512000 0)
=> expires #(struct:date* 49 26 2022 8 2015 6 233 #f 0 585512000 "")
=> expires #(struct:date* 34 36 1622 8 2015 6 233 #t -14400 512000000 "Eastern Daylight Time")


The results are NOT repeatable ... e.g., another run produces:

=> expires #(struct:sql-timestamp 2015 8 22 20 57 40 483091000 0)
=> expires #(struct:date* 40 57 20 22 8 2015 6 233 #f 0 483091000 "")
=> expires #(struct:date* 43 5 17 22 8 2015 6 233 #t -14400 91000000 "Eastern Daylight Time")

and yet another run:

=> expires #(struct:sql-timestamp 2015 8 22 21 1 21 729173000 0)
=> expires #(struct:date* 21 1 21 22 8 2015 6 233 #f 0 729173000 "")
=> expires #(struct:date* 30 13 17 22 8 2015 6 233 #t -14400 173000000 "Eastern Daylight Time")

As you can see, it seems that *sql-timestamp->srfi-date* sometimes botches the conversion, and it seems that (seconds->date (date*->seconds)) sometimes is not symmetric. BIG BUT ... this ONLY happens when the sql-timestamp comes from an actual database. This simple test program :

   (require
      racket/date
      db
      db/util/datetime
      )

   (define  db-time  (sql-timestamp 2015 8 22 18 48 12 0 #f))
   (define  rkt-time (sql-datetime->srfi-date db-time))

   (define timezone -4)
   (define lcl-time (seconds->date (date*->seconds rkt-time #f) timezone))

   (printf "DB : ~s~n" db-time )
   (printf "RKT: ~s~n" rkt-time )
   (printf "LCL: ~s~n" lcl-time )

correctly produces

DB : #(struct:sql-timestamp 2015 8 22 18 48 12 0 #f)
RKT: #(struct:date* 12 48 18 22 8 2015 6 233 #f 0 0 "")
LCL: #(struct:date* 12 48 14 22 8 2015 6 233 #t -14400 0 "Eastern Daylight Time")


Can anyone shed light on what's happening? I really need these copnverted timestamps to be correct.

Thanks,
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.

Reply via email to