Timezone with Gorm

Hi, I’m using Gorm and I’m doing this test where i insert a record, then I retrieve it, and finally I compare both of them using reflect.DeepEqual.
I get differences in the created_at field (TIMESTAMP WITH TIME ZONE) because when I retrieve it, I get the time in UTC, while when the struct is created i get the local timezone.
I’ve been doing some research and I found that CockroachDB has a SET TIME ZONE command, but I couldn’t find what are the implications of using one or another.

  1. Should I always use UTC in the database or my local timezone? (I’m not working globally, one timezone should be ok)
  2. Can I change the timezone settings if the database already has data?
  3. I tried to change CockroachDB time zone, but I couldn’t find the Argentina’s timezone (tried ART and UTC-03).
  4. I’ve found that gorm has a setting “loc=Local”, I used but nothing changed… Is it implemented in CockroachDB?

Thanks!

Our docs for the WITH TIME ZONE type are incorrect (see https://github.com/cockroachdb/docs/issues/685). Both the WITH and WITHOUT types of TIMESTAMP are stored as UTC without any timezone info. The only difference is that the WITH TIME ZONE variety will send back data in whatever time zone your SQL session is using. (And I’m not sure if it defaults to UTC or the system’s time zone.)

Our recommendation is to never ever use the WITH TIME ZONE type, but always use just TIMESTAMP, which does everything in UTC.

a little late but I stumbled here looking for info

I had a similar issue with GORM and Postgress.

it is due do missing of Localization information in the timestamp and a missmatch of resolution between time.Time and postgress timezone .

I fixed it by wrapping the type time.Time so it conforms to the db specs
see https://github.com/SamuelTissot/sqltime

now I can use reflect.DeepEqual on my retreive models

I hope it helps