-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add fraction date constants #4934
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
Conversation
The test failure is legit; could you please fix it? |
Sure. Will do ASAP |
After a twitter-exchange with Dries Vints (https://twitter.com/driesvints/status/1196780528302776320) it looked like there should be a way to easily handle ISO8601- and RFC3339-related datetimes containing fractions. And after a bit of digging I realized that there already was a change done for RFC3339 by adding the microseconds. But the milliseconds where not yet part of the constants. This commit fixes that by adding new constants: * DATE_ATOM_FRACTION * DATE_RFC3339_FRACTION * DATE_ISO8601_FRACTION * DateTimeInterface::ATOM_FRACTION * DateTimeInterface::RFC3339_FRACTION * DateTimeInterface::ISO8601_FRACTION All these are based on their fraction-less counterparts and have added the ".u" modifier after the "s" and before the offset-notation
e2f6dc5
to
d9679fc
Compare
Fractions are part of the original RFC3339, and are optional. Why does there need to be a separate constant for this? Also, see bug report. |
@XedinUnknown because the new constants will provide the greatest datetime precision that's possible with ISO 8601. The current ones lack fractions. The new constant's value is one that's used regularly in, for example, api responses with datetime values. |
@XedinUnknown Because otherwise it will be a BC break. |
What's breaking about fixing support broken support for a format? |
@XedinUnknown an API may extract the result produced by your constant with some RegExp: |
You won't believe it but people are using those constants for some time now and wrote code that expects the output to be of a certain format. By modifying the existing constant this expectation is broken and therefore the code is not working anymore. So changing that constant is breaking backward compatibility. That the current constant is not doing what you expect might be due to the fact that you expect something from the constant that is not even described by the standard. The ISO standard says that you can add fractions, but you do not have to add them. So the current constant does exactly that. And if you want to use fractions you can use the new constant. |
The fact that you can add fractions means that the standard supports fractions. And PHP claims to support the standard. In practice, however, an RFC3339-compliant timestamp that contains a fraction (i.e. is standards-compliant) cannot be parsed by PHP using the |
It means your implementation is broken if you relly on the DATE_ATOM constant. Passing an ATOM-Timestamp with fractions into |
@XedinUnknown the fact it fixes a bug (which I disagree anyway) does not mean it's not a breaking change. Applications that properly work relying the current constant format will stop working on update. That's an obvious BC. |
It does not, as I demonstrated in the bug report.
An RFC3339 timestamp with a fraction and without a fraction is the same format: the RFC3339 format. |
Thanks everyone, further input will not be needed at this point in time. Please let @derickr review this change. |
@heiglandreas, could you please rebase onto master and force-push, so we get the full CI runs? @derickr, what do you think about these new constants? |
I am closing this, as there are now too many little function additions to ext/date. Instead, the API should be better thought out and designed, and I'm collecting information at https://docs.google.com/document/d/1pxPSRbfATKE4TFWw72K3p7ir-02YQbTf3S3SIxOKWsk/edit?usp=sharing |
After a twitter-exchange with Dries Vints it looked like there should be a way to easily handle ISO8601- and RFC3339-related datetimes containing fractions.
And after a bit of digging I realized that there already was a change done for RFC3339 by adding the microseconds. But the milliseconds where not yet part of the constants.
This PR tries to fix that by adding new constants:
All these are based on their fraction-less counterparts and have added the ".u" modifier after the "s" and before the offset-notation