Hi Jon,

On 11/8/2016 6:28 PM, Jon Zeppieri wrote:

    George, these are not correct results. The UTC offset is correct,
    but the time fields are not -- under the assumption that you're
    trying to round-trip them unchanged. (But maybe that's not a
    correct assumption.) At any rate, I think your original example
    demonstrates a problem with seconds->date on Windows.


Sorry, that was confusing. What I meant to say was: the results are correct (given the treatment of the original date fields as UTC and the treatment of the resulting seconds as local), but based on your original post, I don't think they're the results you were after. But I'm not certain of that.

- Jon

What I'm trying to do is the following:

- I'm given 2 datetimes as iso8601 YYYY-MM-DD HH:MM strings, and a time zone offset
- create UTC datetimes from the strings and tz
- query a database returning records between the 2 UTC datetimes

OK that was pretty easy. I believe I need to get [or look up somehow] a separate tz for each date string because the range may span both standard and daylight time, but at least I can get this far.

Now the hard part:

- I need to turn the UTC datetimes on all the results back into local times with the right time zone

This part is driving me nuts. Nothing seems to work exactly right. (seconds->date ... #T) seems to get the numbers right, but not always the timezone, and in any case it is limited to the local timezone of the machine - useless if local *is* UTC, and since I can't specify an arbitrary timezone, I can't use it in a server side application.

What I have tried so far amounts to:  [reformatted a bit]

    (let* [
           (tz      -4)

           (offset  (* 60 60 tz))
           (d       (make-time 'time-duration 0 offset))
           (date-in (sql-datetime->srfi-date ... ));; date comes in here

           (t1        (date->time-utc date-in))
           (t2        (add-duration t1 d))
           (date1-lcl (time-utc->date t2 offset))
           (date1-utc (time-utc->date t2 0     ))

           (t3        (date->seconds date-in))
           (t4        (+ t3 offset))
           (date2-lcl (seconds->date t4 #t))
           (date2-utc (seconds->date t4 #f))

           (date3-lcl (date* (date-second date-in)
                             (date-minute date-in)
                             (date-hour   date-in)
                             (date-day    date-in)
                             (date-month  date-in)
                             (date-year   date-in)
                             0
                             0
                             #f
                             offset
                             0
                             "LCL" ))
           (date3-utc (date* (date-second date-in)
                             (date-minute date-in)
                             (date-hour   date-in)
                             (date-day    date-in)
                             (date-month  date-in)
                             (date-year   date-in)
                             0
                             0
                             #f
                             0
                             0
                             "UTC"
                             ))

          ]
(printf "UTC input : ~s ~s~n" date-in (date->string date-in "~1 ~2"))
      (printf "~n")
(printf "srfi tz : ~s ~s~n" date1-lcl (date->string date1-lcl "~1 ~2")) (printf "srfi 0 : ~s ~s~n" date1-utc (date->string date1-utc "~1 ~2"))
      (printf "~n")
(printf "s->d #t : ~s ~s~n" date2-lcl (date->string date2-lcl "~1 ~2")) (printf "s->d #f : ~s ~s~n" date2-utc (date->string date2-utc "~1 ~2"))
      (printf "~n")
(printf "date* ofst: ~s ~s~n" date3-lcl (date->string date3-lcl "~1 ~2")) (printf "date* 0 : ~s ~s~n" date3-utc (date->string date3-utc "~1 ~2"))

      )


=>

UTC input : #(struct:date* 0 0 4 12 11 2016 6 316 #f 0 0 "") "2016-11-12 04:00:00Z"

srfi tz : #(struct:date* 0 0 20 11 11 2016 5 315 #f -14400 0 "") "2016-11-11 20:00:00-0400" srfi 0 : #(struct:date* 0 0 0 12 11 2016 6 316 #f 0 0 "") "2016-11-12 00:00:00Z"

s->d #t : #(struct:date* 0 0 0 12 11 2016 6 316 #t -14400 0 "Eastern Daylight Time") "2016-11-12 00:00:00-0400" s->d #f : #(struct:date* 0 0 5 12 11 2016 6 316 #f 0 0 "UTC") "2016-11-12 05:00:00Z"

date* ofst: #(struct:date* 0 0 4 12 11 2016 0 0 #f -14400 0 "LCL") "2016-11-12 04:00:00-0400" date* 0 : #(struct:date* 0 0 4 12 11 2016 0 0 #f 0 0 "UTC") "2016-11-12 04:00:00Z"



I've been thinking I should look into Gregor, but a brief skimming of its docs was daunting.

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