-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Bad date calculations #53
Comments
I just found this
I'm sure that's what's making it die. Obviously that's corrupt data in my database that I need to fix. |
If it crashes Vapor, we should probably look into fixing it anyway. Do you have a reproducible case? Also, why is using seconds for date calculations bad? |
https://developer.apple.com/videos/play/wwdc2011/117/ talks all about why it's bad. But at the end of the day, no pun intended, there aren't always 24 * 60 * 60 seconds in a day. I think it's reproducible by just setting the date to what I showed above. |
That's a different use case. For timestamps, "number of seconds since some reference date" is the standard way of doing things as far as I know. IIRC this is actually how Postgres stores timestamps internally. |
The issue was integer overflow. Fixed by using |
https://github.com/vapor/postgresql/blob/388346471c6a89c2695235d8ffff43c5941283af/Sources/PostgreSQL/Data/PostgreSQLData%2BDate.swift#L32
You're doing date calculations by using seconds, which is always a bad thing to begin with.
However, I'm hitting a case where the app crashes with
I believe it's because the days is coming through as a negative number.
The text was updated successfully, but these errors were encountered: