-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Some date strings are silently parsed to wrong dates #124
Comments
This is possibly a floating point rounding issue:
These two are expected outcomes:
The parser only understands 4 digit years. I don't understand (yet) why it does not also produces a warning for the "odd" prefixed numbers. |
For the record, there is a way to fool the parser and bypass the 4-digit year restriction (which gives hope that it might not be too much trouble to tweak the parser to support > 4-digit years?): var_dump((new DateTime('292277026596-12-04 15:30:07 UTC'))->getTimestamp());
var_dump((new DateTime('+292277026596-12-04 15:30:07 UTC'))->getTimestamp());
echo (new DateTime('2512370164-01-01 00:00:00Z'))->format(DATE_RFC3339_EXTENDED), "\n";
echo (new DateTime('+2512370164-01-01 00:00:00Z'))->format(DATE_RFC3339_EXTENDED);
|
I've made a PR to fix the For parsing dates with a large year, I can't change the year size to larger than 4 digits without breaking other features. The "workaround" by using a + or - sign is the right approach. |
While working on an implementation of the MessagePack Timestamp extension, I encountered some unexpected issues with parsing string dates with
DateTime
. The lowest timestamp the extension can store is-292277022657-01-27 08:29:52 UTC
, and the highest is292277026596-12-04 15:30:07.999999999 UTC
. When I feed these dates into theDataTime
constructor, I get:I understand that these can be hard to fix problems, but maybe it would at least be possible to detect such cases and throw an exception "
Failed to parse time string
" (as is done, for example, for15121370164-01-01 00:00:00Z
) instead of silently returning a wrong date? Now the user doesn't even know if they sent or received the wrong date.The text was updated successfully, but these errors were encountered: