Skip to content

time: Add is_datetime() for RFC 3339 Internet Date/Time Format#2345

Merged
jviotti merged 3 commits intosourcemeta:mainfrom
vtushar06:add-datetime-validation
Apr 15, 2026
Merged

time: Add is_datetime() for RFC 3339 Internet Date/Time Format#2345
jviotti merged 3 commits intosourcemeta:mainfrom
vtushar06:add-datetime-validation

Conversation

@vtushar06
Copy link
Copy Markdown
Contributor

Body

Adds sourcemeta::core::is_datetime() to src/core/time following the same pattern as is_ipv4() and is_ipv6() in src/core/ip.

This is a building block for format-assertion support in Blaze for Draft 4 and Draft 6.

Function signature:

auto is_datetime(std::string_view value) -> bool;

Pure string_view state machine. No heap allocations. No external dependencies.

RFC 3339 §5.6 compliance:

  • full-date "T" full-time production rule
  • Leap year per Appendix C formula
  • Accepts second=60 (leap seconds) per §5.7
  • Case-insensitive T and Z per §5.6 NOTE
  • Rejects colonless offsets (+0530)
  • Rejects space separator
  • Rejects missing timezone
  • Year range 0000-9999 per §1

Tests: 40 cases (17 valid, 23 invalid)

Files changed:

File Action
src/core/time/include/sourcemeta/core/time.h Add is_datetime() declaration
src/core/time/datetime.cc New — implementation
src/core/time/CMakeLists.txt Add datetime.cc to SOURCES
test/time/datetime_test.cc New — 40 unit tests
test/time/CMakeLists.txt Add datetime_test.cc to SOURCES

Out of scope for this PR:

Blaze integration - is_datetime() is the building block. Hooking it into format-assertion in the Blaze compiler is a separate PR once this is reviewed.

Copilot AI review requested due to automatic review settings April 11, 2026 02:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds sourcemeta::core::is_datetime(std::string_view) -> bool to validate RFC 3339 date-time strings (Section 5.6) using a pure string_view state machine, and introduces a dedicated unit test suite.

Changes:

  • Add is_datetime() public API to sourcemeta::core::time.
  • Implement RFC 3339 date-time validation (including leap-year rules, leap seconds, and required timezone).
  • Add comprehensive unit tests and wire new sources into the build.

Reviewed changes

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

Show a summary per file
File Description
src/core/time/include/sourcemeta/core/time.h Declares is_datetime() and documents RFC 3339 expectations/usage.
src/core/time/datetime.cc Implements the RFC 3339 date-time validator as a zero-allocation parser.
src/core/time/CMakeLists.txt Adds datetime.cc to the time library build.
test/time/datetime_test.cc Adds 40 unit tests covering valid/invalid RFC 3339 date-time cases.
test/time/CMakeLists.txt Adds datetime_test.cc to the time unit test target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/core/time/datetime.cc">

<violation number="1" location="src/core/time/datetime.cc:128">
P2: `is_datetime` accepts `:60` unconditionally, making RFC 3339 validation too permissive for leap-second semantics.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread src/core/time/rfc3339_datetime.cc
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/time/datetime_test.cc Outdated
Implements sourcemeta::core::is_datetime() in src/core/time following
the same pattern as is_ipv4() and is_ipv6() in src/core/ip.

- Pure string_view state machine, no heap allocations
- Validates full date-time production from RFC 3339 §5.6
- Leap year per RFC 3339 Appendix C formula
- Accepts leap seconds (second=60) for any date per §5.7
- Case-insensitive T/Z separators per §5.6 NOTE
- Rejects colonless offsets, space separators, missing timezone
- 40 unit tests covering valid and invalid inputs

Relates to format-assertion support for Draft 4 and Draft 6.

Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
@vtushar06 vtushar06 force-pushed the add-datetime-validation branch from cf89346 to 00ba70a Compare April 11, 2026 02:56
@vtushar06
Copy link
Copy Markdown
Contributor Author

hey @jviotti, PR is ready for review, let me know if any further tweaks are needed :)

Comment thread test/time/datetime_test.cc Outdated
Comment thread src/core/time/include/sourcemeta/core/time.h Outdated
Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
@vtushar06
Copy link
Copy Markdown
Contributor Author

vtushar06 commented Apr 15, 2026

Thanks for the feedback, Juan

Renamed is_datetime() to is_rfc3339_datetime() and updated the filename accordingly (datetime.cc to rfc3339_datetime.cc, same for the test file). Also cleaned up the section/inline comments from the test to match the style in the IP tests.

And going forward I'll use the RFC-prefixed name pattern for any new format validators to keep things unambiguous from the start.

Comment thread src/core/time/include/sourcemeta/core/time.h Outdated
@jviotti
Copy link
Copy Markdown
Member

jviotti commented Apr 15, 2026

I left a tiny comment, but also the formatting is broken? Make sure to run make compile, which will call clang-format

Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
@vtushar06
Copy link
Copy Markdown
Contributor Author

hey Juan, Fixed both, added const to the declaration to match the implementation.

@vtushar06 vtushar06 requested a review from jviotti April 15, 2026 17:14
Copy link
Copy Markdown
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.

Super!

@jviotti jviotti merged commit 7002da1 into sourcemeta:main Apr 15, 2026
13 checks passed
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