-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
DATE columns set values with timezone offsets, producing conflicts when db server is on a different timezone. #462
Comments
I believe this is ultimately a side effect of your use of In short, Fluent and PostgresNIO both act, of necessity, on the assumption that Note If you really do need a
If none of those works for you, I'm afraid you're out of luck - we can't even look into changing Fluent's existing behavior in this respect unless we can also figure out a way to handle it better in PostgresNIO first (and even then the changes would end up happening in Fluent 5). |
Thank you for lightning-fast response. I now better understand where the issue is, and also recognize that changing Fluent 4 to make As to why the importance of In any case, I appreciate your very detailed reply. You have given me many options to work with! Thank you! 😀 |
Let's just say that this sort of issue, and the difficulty in addressing it in any helpful fashion even if Fluent 4's API could be more freely changed, is a notable entry on the long list of reasons that the very preliminary design work I've finally started for Fluent 5 centers around a much more SQLKit-like API than what we have now 😅. Oh, and I forgot - there is one other option you could go with:
(Or, you know, just use |
(At the end of the day, it's just another "ORMs are the reason anyone who doesn't work with either audio equipment or electronics has ever even heard of an impedance mismatch" thing, and the last-second choice to shoehorn support for MongoDB into Fluent 4 immediately before the GM release elevated the mismatch to what I'd call almost a flat-out incompatibility after 3 or 4 years of fighting with it 😆. At least I can blame that particular call on @tanner0101, I was against it at the time 🤣.) |
I really like this new option. Probably too much for my project, because I can really go with |
Problem description
First I should say that I read issue #453, although I think this one is slightly different.
When saving a date to a
DATE
column, theINSERT
specifies a timezone offset. This is not usually a problem, if we are in the same timezone as the db server. But working with a server on America/New_York, inserting2000-01-01 00:00:00+00:00
will actually insert1999-12-31
(as in New York, it is not 2000-01-01 yet).This behaviour differs from MySQL, which handles (to my understanding) this case correctly. Inspecting the statement logs in both servers, there is a clear difference in the statement they produce (bindings where substituted by their values for clarity):
In MySQL, we can ignore the server timezone, and simply use UTC. This guarantees the date stored is the one we will fetch. With Postgres however, we need to be aware of the server timezone at all times, in order to create the
Date
objects to be inserted, using the server's timezone.I cannot see the reasoning behind this (I'm sure there's one, I just don't see it).
To Reproduce
A clear example for using the
DATE
column type, is for storing birthday dates. The time is completely irrelevant and even less is its timezone.For this to work correctly on Postgres, we need to know the server's timezone and use it to create the
Date
object.Expected behavior
I would think that the result should be the same, no matter which database we are connecting to. I absolutely prefer MySQL's behavior.
If for any reason this is not possible, would it be too crazy/weird to ask that defining the
Model
property as String (instead of Date) would work withDATE
column types too? That way we could do:and that would translate into:
Another and better solution could be having a different swift type altogether (e.g., DateWithoutTime) and get rid of all ambiguity.
In my case, I can afford to do
ALTER DATABASE SET TIMEZONE to 'UTC'
and forget about it... but that may not always be possible.Environment
framework: 4.77.0
toolbox: 18.7.4
postgres-nio: 1.17.0
The text was updated successfully, but these errors were encountered: