-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Allow the time zone to be overridden via ENV var #74
base: master
Are you sure you want to change the base?
Conversation
I don't know the specifics of time zone handling in MySQL. Maybe changing the constant might have some undesired side effects. Anyway, it needs to be tested with different timezones. Could you explain a specific example (in code) which details the issues you experienced? |
Let's say we have inserted a column using When reading this from the database using this library, With this PR reading the column from MySQL with your timezone set as an ENV var, will result in the correct time object of: The need for this change comes after the changes around the Time object and how it stores its location. This issue does not exist in other langs (python, go) as the Time object does not have a location built in. @straight-shoota please let me know if you follow the above Thanks |
MySQL has |
Also, I can't see how this patch fixes things, because the time value returned from MySQL depends on the server time zone. Simply assigning some time zone in the client doesn't help because it can't be ensured to be in sync with the server's time zone. |
I am using In the example I gave above, that is happening in my local code after applying the patch. Regardless, I still think there should still be a way to tell this library what timezone to use when reading timestamps as it is causing issues. |
But time zone values will be incorrect again in case |
This is why it should be an ENV var, so the dev/ops can add it to a .env file, currently I have no way of returning a non-UTC Time object from the DB, which is not what we want. Maybe a better way to do this is to allow the rs.read(Time) to return a .to_local version? |
If a server's timezone is already UTC, there is no need to overwrite the current behaviour, so the env var need not be set. This only applies when the machine you are running the code on is not UTC (we should presume the MySQL timezone and the server's timezone match) |
Is there no way to store the server's timezone and represent times correctly? Times coming from mysql shouldn't need configuration to be correct, is this a problem encountered by other libraries? |
I agree that there needs to be an option to specify the timezone of the time values in the DB when those do not have TZ info. That TZ configuration can also be used to indicate to which TZ translate all time if wanted although this list might be more in the responsibility of the ORM in use. I'm not sure. But what I would like is that to be a configuration of the database connection. If there is a fallback to an env variable it's another story. This should be handled in crystal-db directly. The current TZ support was the minimum to keep all db shards compatible with the time changes in the stdlib. @ochran are you interested in pushing this story in crystal-db directly? If so we can discuss there the design. |
@RX14 It isn't a problem in any other lib I've come across, but I think that may be down to the fact that most languages don't have a Time object with a built in location, or the db drivers don't return one at least. @bcardiff yeah can do, not sure where I would make this code change as I can't see anywhere in crystal-db that handles location. I'll push to crystal-db Cheers |
When living in a timezone that does not always match UTC, there needs to be an option to be able to set a location, as you will have difficulties during daylight saving or a season that changes the time diff.
Seems like an ENV var is the best way to achieve this and preserve current behaviour if one hasn't been supplied.
Cheers