Skip to content

test(duration): expand RFC 3339 grammar coverage for duration format#868

Open
Vaibhav701161 wants to merge 2 commits intojson-schema-org:mainfrom
Vaibhav701161:test-suite/duration-format-grammar-coverage
Open

test(duration): expand RFC 3339 grammar coverage for duration format#868
Vaibhav701161 wants to merge 2 commits intojson-schema-org:mainfrom
Vaibhav701161:test-suite/duration-format-grammar-coverage

Conversation

@Vaibhav701161
Copy link

This PR adds a few additional tests for the duration format based on the ABNF grammar in RFC 3339 Appendix A, which is referenced by the JSON Schema specification.

The goal is to improve coverage of grammar paths that were not clearly exercised by the existing tests. The new cases cover:

  • full date component chains (Y → M → D)
  • full time component chains (H → M → S)
  • the standalone time form (PT...)
  • optional combinations like H → M without seconds
  • multi-digit numeric values allowed by 1*DIGIT
  • simple whitespace edge cases that fall outside the grammar

All tests are derived directly from the RFC grammar structure rather than adding new interpretation rules.

One case that is intentionally not included is fractional durations (for example PT0.5S). The JSON Schema spec defines the format as “the ISO 8601 ABNF as given in Appendix A of RFC 3339”. The ABNF grammar in that appendix only allows digits (1*DIGIT), while ISO-8601 itself allows fractional values. Because of this, different implementations currently behave differently:

  • AJV (ajv-formats) rejects fractional values
  • Hyperjump also rejects them
  • python-jsonschema accepts them through the isoduration library

Since the specification wording leaves this ambiguous, this PR avoids adding tests that would enforce either interpretation.

The same changes are applied consistently to the draft2020-12, draft2019-09, and v1 test files, with only the $schema value differing between them.

Before submitting the PR I validated the files using the repository tools (python3 bin/jsonschema_suite check) and verified JSON syntax with python3 -m json.tool. All checks passed.

@Vaibhav701161 Vaibhav701161 requested a review from a team as a code owner March 7, 2026 20:03
@jviotti
Copy link
Member

jviotti commented Mar 9, 2026

@jviotti
Copy link
Member

jviotti commented Mar 9, 2026

One case that is intentionally not included is fractional durations (for example PT0.5S). The JSON Schema spec defines the format as “the ISO 8601 ABNF as given in Appendix A of RFC 3339”. The ABNF grammar in that appendix only allows digits (1*DIGIT), while ISO-8601 itself allows fractional values. Because of this, different implementations currently behave differently:

I think its important to add test cases proving you reject the ones with fractional durations if the Appendix doesn't allow them

@jviotti
Copy link
Member

jviotti commented Mar 9, 2026

Other than that the new ones you added seem correct

…rmat

Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
Signed-off-by: Vaibhav mittal <vaibhavmittal929@gmail.com>
@Vaibhav701161 Vaibhav701161 force-pushed the test-suite/duration-format-grammar-coverage branch from 989f7e7 to 5489c49 Compare March 9, 2026 13:26
@Vaibhav701161
Copy link
Author

Thanks for the clarification and the reference @jviotti .

I’ve added a test case rejecting fractional duration components (PT0.5S) based on the RFC 3339 Appendix A ABNF grammar.

Copy link
Member

@jviotti jviotti left a comment

Choose a reason for hiding this comment

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

It looks correct to me!

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.

2 participants