Repository navigation
Conversation
The before and after operators parsed timestamps with at most three fractional digits, so a timestamp with microsecond or nanosecond precision, such as 2020-01-01T00:00:00.123456Z, did not match any clause. When the existing formats fail, the fraction is now truncated to six digits and the timestamp is parsed with microseconds. Digits below milliseconds are truncated, as before. Timestamps that the existing formats accept are parsed as before.
Add cases for timestamps with 4 to 13 fractional digits and an offset, for malformed timestamps that must still be rejected, and for the before and after operators with microsecond timestamps.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirements
Related issues
N/A
Describe the solution you've provided
The
beforeandafteroperators parse RFC 3339 timestamps only when they have at most three fractional digits. RFC 3339 does not limit the number of fractional digits, but a value such as2020-01-01T00:00:00.123456Z, with microsecond or nanosecond precision, fails to parse.So, only when both existing formats (three fractional digits, and no fractional digits) fail, the fraction is now truncated to six digits and the timestamp is parsed again with microseconds, using the previously unused constant
Operators::RFC3339.Describe alternatives you've considered
Validating the timestamp as RFC 3339 with a regular expression, then parsing it with
new DateTimeImmutable($in). However, the current implementation also accepts forms outside RFC 3339, such as+0900andUTC, so I did not use that approach here.Additional context
New tests in
tests/Impl/Evaluation/OperatorsTest.php:testParseTimeWithMoreThanThreeFractionDigits: timestamps with 4, 5, 6, 9, and 13 fractional digits, and one with an offset (+09:00), are parsed.testParseTimeRejectsMalformedTimestampWithFraction: malformed timestamps (.Z, no time zone, no seconds, a space instead ofT) still returnnull.testDateOperatorsCompareTimestampsWithMicroseconds: thebeforeandafteroperators compare timestamps with microsecond precision correctly.Note
Overview
Operators::parseTimenow accepts RFC 3339 strings with more than three fractional digits (micro/nano precision) by truncating the fraction to six digits and parsing withOperators::RFC3339when the existing extended/standard formats fail.That unblocks
beforeandafterrule comparisons on high-precision timestamps instead of treating them as unparseable. New tests cover varied fraction lengths, malformed inputs, and microsecond-level comparisons.Reviewed by Cursor Bugbot for commit 85dcf2b. Bugbot is set up for automated code reviews on this repo. Configure here.