Skip to content

Fix RFC 3339 date-time validation with high-precision fractional seconds - #940

Merged
DannyvdSluijs merged 2 commits into
jsonrainbow:mainfrom
UmairRathore:fix/929-rfc3339-fractional-seconds
Sep 4, 2026
Merged

Fix RFC 3339 date-time validation with high-precision fractional seconds#940
DannyvdSluijs merged 2 commits into
jsonrainbow:mainfrom
UmairRathore:fix/929-rfc3339-fractional-seconds

Conversation

@UmairRathore

Copy link
Copy Markdown
Contributor

Description

Fix RFC 3339 date-time validation for timestamps containing more than six fractional-second digits.

RFC 3339 allows one or more digits in the fractional-second component, but PHP's DateTimeImmutable::createFromFormat() only accepts up to six microsecond digits.

The full input continues to be validated by the existing RFC 3339 pattern. Only the fractional component passed internally to DateTimeImmutable is truncated to six digits, avoiding PHP's parser limitation without rejecting otherwise valid RFC 3339 timestamps.

Regression tests have been added for fractional seconds beyond six digits, including timezone offsets.

Related Issue

Fixes #929

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional Notes

Tested with:

  • Targeted RFC 3339 tests: 16 tests, 26 assertions
  • Targeted format constraint tests: 162 tests, 180 assertions
  • Full test suite: 3165 tests, 9808 assertions, 1 existing warning, 11 skipped
  • PHPStan: 157/157 files, no errors

The existing PHPUnit warning is unchanged from the pre-change baseline.

@UmairRathore UmairRathore changed the title Fix date-time validation for fractional seconds beyond microseconds Fix RFC 3339 date-time validation with high-precision fractional seconds Aug 22, 2026
@DannyvdSluijs
DannyvdSluijs requested a lite review from Copilot September 1, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes RFC 3339 date-time validation for inputs that include more than six fractional-second digits by truncating the fractional component to six digits before passing it to PHP’s DateTimeImmutable::createFromFormat(), while still validating the full original input against the existing RFC 3339 regex.

Changes:

  • Truncate the parsed fractional-seconds component to six digits (microseconds) before PHP date parsing to avoid parser limitations.
  • Add regression tests covering fractional seconds longer than six digits (including timezone offsets) and an invalid non-digit fractional case.
  • Extend date-time format-constraint tests to accept high-precision fractional seconds.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/JsonSchema/Rfc3339.php Truncates matched fractional seconds to six digits before calling DateTimeImmutable::createFromFormat().
tests/Rfc3339Test.php Adds valid cases for 7+ fractional digits (Zulu and offset) and an invalid non-digit fractional case.
tests/Constraints/FormatConstraintTest.php Adds a date-time valid format case for 7 fractional digits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@DannyvdSluijs
DannyvdSluijs merged commit f47d1b4 into jsonrainbow:main Sep 4, 2026
18 checks passed
DannyvdSluijs added a commit that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date-time validation fails if more than 6 fractional second digits supplied

3 participants