On Sat, Aug 22, 2015 at 4:36 PM, George Neuner <gneun...@comcast.net> wrote:
>
> The latter code using date works properly (modulo the time zone field) and
> gives consistent results, but the former using date* gives inconsistent
> results.
>
>  E.g.,: with timezone = -5
>
> => expires #(struct:sql-timestamp 2015 8 22 21 56 33 805346000 0)
> => expires #(struct:date* 33 56 21 22 8 2015 6 233 #f 0 805346000 "")
> => expires #(struct:date* 58 9 17 22 8 2015 6 233 #f 0 346000000 "UTC")
>
> => expires #(struct:sql-timestamp 2015 8 22 22 23 45 95751000 0)
> => expires #(struct:date* 45 23 22 22 8 2015 6 233 #f 0 95751000 "")
> => expires #(struct:date* 20 25 17 22 8 2015 6 233 #f 0 751000000 "UTC")
>

These both look wrong to me. Maybe I'm confused, but my understanding
is that the database timestamp is in UTC, and you want a date*
representing the same point in time, but in specified UTC offset. In
other words, Your first example here starts with
2015-08-22T21:56:33.805346Z. Your end result is
2015-08-22T17:09:58.346, which is clearly not exactly 5 hours offset.

In the second example, you start with 2015-08-22T22:23:45.95751000Z
and wind up with 2015-08-22T17:25:20.751, which is also wrong, but by
a considerably smaller margin. I actually can't reproduce the problem
in the second example, but I'm also running 6.2.0.2. It looks to me
like date->seconds roundtrips correctly w.r.t. seconds->date but
date*->seconds does not:
```
> d
(date* 33 56 21 22 8 2015 6 233 #f 0 805346000 "")
> (seconds->date (+ (* -5 60 60) (date->seconds d #f)) #f)
(date* 33 56 16 22 8 2015 6 233 #f 0 0 "UTC") ;; correct, modulo nanoseconds
> (seconds->date (+ (* -5 60 60) (date*->seconds d #f)) #f)
(date* 58 9 17 22 8 2015 6 233 #f 0 346000000 "UTC") ;; incorrect
```

So, yeah, I'd say that there's a bug in date*->seconds:
```
> (date->seconds d #f)
1440280593
> (date*->seconds d #f)
1440281398 173/500
```

Let's see what this looks like in gregor's terms:
```
> (define d (moment 2015 8 22 21 56 33 805346000 #:tz "UTC"))
> d
#<moment 2015-08-22T21:56:33.805346Z[UTC]>
> (adjust-timezone d (* -5 60 60))
#<moment 2015-08-22T16:56:33.805346-05:00>
> (->posix d)
1440280593 402673/500000
```

-Jon

-- 
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