Repository navigation
fix: Evaluate before and after clauses on timestamps with up to nine fractional digits - #308
Merged
keelerm84 merged 3 commits intoNov 30, 2026
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.
Member
|
Thanks for this, @zigzagdev. This is a real gap and the approach is right. We pushed two small adjustments to your branch so we can get it into the next release:
|
kinyoklion
approved these changes
Nov 30, 2026
keelerm84
pushed a commit
that referenced
this pull request
Nov 30, 2026
🤖 I have created a release *beep* *boop* --- ## [6.13.2](6.13.1...6.13.2) (2026-11-30) ### Bug Fixes * Escape attribute names that look like references in redactedAttributes ([#309](#309)) ([d59cb4b](d59cb4b)) * Evaluate before and after clauses on timestamps with up to nine fractional digits ([#308](#308)) ([a174822](a174822)) * Redact nested private attributes in associative arrays that have ([1c5dba7](1c5dba7)) * Redact nested private attributes when attribute values are `stdClass` objects ([#306](#306)) ([1c5dba7](1c5dba7)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Member
|
Thank you again @zigzagdev! This has been released in 6.13.2 |
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
Cause
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.Solution
So, 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.
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
Fixes a gap where timestamp attributes with more than three fractional seconds (common micro/nanosecond forms) failed
parseTime, sobefore/afterflag rules never matched.parseTimenow adds a third parse attempt: if standard RFC3339 formats fail, it strips extra fractional digits (up to nine, beyond PHP’s six) with a regex and parses via the existing microsecond format (self::RFC3339). Values with more than nine fraction digits or otherwise malformed strings still returnnull.Tests cover accepted 4–9 digit fractions (with offsets), rejected malformed inputs, and microsecond-level
before/aftercomparisons.Reviewed by Cursor Bugbot for commit 378f930. Bugbot is set up for automated code reviews on this repo. Configure here.