-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timezones aren't persisted to the database (or rendered in hashes, json, etc) #225
Comments
The issue might be that Time objects do not support Timezones. Timezone support is coming in crystal 0.25.0 |
@Blacksmoke16 interesting. I followed that pull for a while several months ago but gave up on it. If that’s true, why are there time zones on the timestamps in the output above? There’s some subtlety about the implementation Or details I think I’m missing. |
Adding a little note here about something to consider when implementing this: converting to UTC will solve a bunch of the use cases here, but not all of them. http://www.creativedeletion.com/2015/03/19/persisting_future_datetimes.html |
@robacarp I was looking into this a bit more. From what i can tell (at least related to PG), is that PG doesnt support timezone specific datetime with timezone columns. For example using the t = Test.new
t.datetime = Time.now(Time::Location.load("America/New_York"))
pp t
t.save
pp Test.first! Which prints (with extraneous fields removed):
PG will take the given date and store it as is, but when returning it, no TZ data is given so crystal assumes its UTC. There is the tl;dr it looks like only way to store a datetime with a specific tz is to use a string field and just parse that into a datetime obj. Or use the |
Interesting. I wonder what other frameworks do. |
The other ORM i was using, just auto converts everything to UTC and stores/returns that. |
At a minimum timezones should be persisted to the database, but they should also be emitted into json in the right string format for javascript.
I'm not sure that Time objects should be stringified when a model is converted to a hash at all.
The text was updated successfully, but these errors were encountered: