Skip to content

fix: Evaluate before and after clauses on timestamps with up to nine fractional digits - #308

Merged
keelerm84 merged 3 commits into
launchdarkly:mainfrom
zigzagdev:fix/parse-rfc3339-any-fraction-digits
Nov 30, 2026
Merged

keelerm84 merged 3 commits into
launchdarkly:mainfrom
zigzagdev:fix/parse-rfc3339-any-fraction-digits

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

N/A

Describe the solution you've provided

Cause

The before and after operators 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 as 2020-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 +0900 and UTC, 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 of T) still return null.
  • testDateOperatorsCompareTimestampsWithMicroseconds: the before and after operators compare timestamps with microsecond precision correctly.
$ ./vendor/bin/phpunit
PHP 8.2.36 (latest / lowest)  OK (Tests: 571, Assertions: 1513, Skipped: 21)
PHP 8.3.37 (latest / lowest)  OK (Tests: 571, Assertions: 1513, Skipped: 21)
PHP 8.4.28 (latest / lowest)  OK (Tests: 571, Assertions: 1513, Skipped: 21)
PHP 8.5.9  (latest)           OK (Tests: 571, Assertions: 1513, Skipped: 21, Risky: 5)

Note

Overview
Fixes a gap where timestamp attributes with more than three fractional seconds (common micro/nanosecond forms) failed parseTime, so before/after flag rules never matched.

parseTime now 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 return null.

Tests cover accepted 4–9 digit fractions (with offsets), rejected malformed inputs, and microsecond-level before/after comparisons.

Reviewed by Cursor Bugbot for commit 378f930. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
@zigzagdev
zigzagdev requested a review from a team as a code owner November 23, 2026 23:29
@zigzagdev zigzagdev changed the title fix: Drop only the analytics events that cannot be encoded as JSON fix: Parse RFC 3339 timestamps with more than three fractional digits Nov 28, 2026
@keelerm84

Copy link
Copy Markdown
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:

  • LaunchDarkly's evaluation spec limits date strings to at most 9 fractional digits, and our other SDKs (Go, for example) reject longer fractions. The regex is now bounded to 7-9 extra digits, so a 10+ digit fraction still fails to parse, and the before/after operators behave the same across SDKs. The 13-digit test case moved to the reject test, with a 10-digit boundary case added.
  • We added a 7-digit case (the .NET round-trip format) and a negative-offset case, and updated the comments to give the 9-digit limit.

@keelerm84 keelerm84 changed the title fix: Parse RFC 3339 timestamps with more than three fractional digits fix: Evaluate before and after clauses on timestamps with up to nine fractional digits Nov 30, 2026
@keelerm84
keelerm84 merged commit a174822 into launchdarkly:main Nov 30, 2026
15 checks passed
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>
@keelerm84

Copy link
Copy Markdown
Member

Thank you again @zigzagdev! This has been released in 6.13.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants