Skip to content

fix: Drop only the analytics events that cannot be encoded as JSON - #308

Open
zigzagdev wants to merge 2 commits into
launchdarkly:mainfrom
zigzagdev:fix/parse-rfc3339-any-fraction-digits
Open

zigzagdev wants to merge 2 commits into
launchdarkly:mainfrom
zigzagdev:fix/parse-rfc3339-any-fraction-digits

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Nov 23, 2026 •

Copy link
Copy Markdown

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

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.

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 +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
Operators::parseTime now accepts RFC 3339 strings with more than three fractional digits (micro/nano precision) by truncating the fraction to six digits and parsing with Operators::RFC3339 when the existing extended/standard formats fail.

That unblocks before and after rule 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.

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

This branch has not been deployed

No deployments
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.

1 participant