Fork me on GitHub
#sql
<
2017-03-13
>
grav19:03:26

i have some cross clj-cljs code, which accesses a mysql db. If i select a date out using cljs (nodejs), it’s two hours off the clj version.

grav19:03:03

I use jdbc from clj, and mysql’s official npm from cljs

grav19:03:54

If I do SELECT @@system_time_zone;, it returns UTC from both

grav19:03:07

So what other options do I have for debugging?

hiredman19:03:53

which has the correct time?

hiredman19:03:09

my guess would be you are storing time without a timezone in mysql, and the timezone on you machine is 2 hours off from utc

grav19:03:17

That’s a good question 🙂 If I query the db via squirrelsql, it matches the clj version, but that doesn’t mean it’s true

grav19:03:58

Yes, it’s a TIMESTAMP, no timezone info. My machine is actually 1 hour off UTC (eg CET+1, no DST), so the difference puzzles me

hiredman19:03:05

I would check the date objects or whatever before you insert them into mysql

grav20:03:39

Well it’s not totally important for my use-case whether one or the other value is returned, the important part is that they should be equal. So I’m wondering if there’s something different in the way i connect to the db from clj and cljs.

grav20:03:47

I’m just wondering, if there are any other queries I can throw at the db from both clients, in order to debug

hiredman20:03:19

the timestamps are likely the same, but being turned in to date objects with whatever timezone

hiredman20:03:35

I doubt it is a db issue

hiredman20:03:54

well, you could call it a db issue, because you really should be storing a timezone

grav20:03:16

They’re js/Date and java.util.Date. None of those should have tz info, but they’re still different

hiredman20:03:17

I think it is, uh, a marshalling or serialization issue

hiredman20:03:31

they definitely do both have timezone info

grav20:03:12

Well, they’re UTC according to the docs I’ve read

hiredman20:03:20

clojure's prn prints Dates by converting them to utc, which could be deceptive here

hiredman20:03:02

grav: Date definitely does not default to utc, it defaults to whatever the system timezone is

hiredman20:03:10

if you prn out a Date object, and it shows a utc time, then call .getTime on that Date object, the getTime will be in the timezone of the Date object, not utc

grav20:03:27

Okay, I’ll try that

hiredman20:03:12

(println (str date-object)) will print out the timezoned date

hiredman20:03:21

oh, whoops, actually getTime is always gmt

grav20:03:23

Well, it seems the cljs instance of the date is off. Which puzzles me since it’s the official mysql npm

grav20:03:16

Ah, needed to supply :timezone “utc” to my connection map. Apparently SELECT @@system_time_zone; wasn’t telling the truth

grav20:03:32

Funny, also UTC+2. Seems like a bug.

grav20:03:06

@hiredman anyway, thanks for the pointers 🙂