feat: RFC 3339 time Validator#1556
Conversation
Closes open-circle#1496. Add an `rfc3339Time(message?)` action that validates `HH:MM:SS` with optional fractional seconds (`.\d+`) and an optional offset (`Z` or `+/ HH:MM`), e.g. `14:30:00`, `14:30:00Z`, `14:30:00.123 05:00`. Unlike isoTime it requires seconds; unlike isoTimeSecond it accepts offsets and fractional seconds.
WalkthroughAdds an RFC 3339 time validation action supporting fractional seconds and UTC or offset time zones. The action defines validation issue and action contracts, provides overloads for optional custom messages, performs synchronous validation of typed values, and records mismatches. New barrel exports expose the action through its entrypoint and the main actions index. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@library/src/actions/rfc3339Time/rfc3339Time.ts`:
- Around line 59-65: Remove the JSDoc comment immediately preceding the overload
in the RFC 3339 time action declarations, while preserving the documentation on
the first overload and leaving the overload signatures unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: abb3777a-f9c0-4d61-9a5a-467dd8d70b3a
📒 Files selected for processing (3)
library/src/actions/index.tslibrary/src/actions/rfc3339Time/index.tslibrary/src/actions/rfc3339Time/rfc3339Time.ts
| /** | ||
| * Creates an RFC 3339 time validation action. | ||
| * | ||
| * @param message The error message. | ||
| * | ||
| * @returns An RFC 3339 time action. | ||
| */ |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Remove the JSDoc comment for this overload.
As per coding guidelines, JSDoc should only be provided on the first overload for overload sets.
♻️ Proposed fix
-/**
- * Creates an RFC 3339 time validation action.
- *
- * `@param` message The error message.
- *
- * `@returns` An RFC 3339 time action.
- */📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /** | |
| * Creates an RFC 3339 time validation action. | |
| * | |
| * @param message The error message. | |
| * | |
| * @returns An RFC 3339 time action. | |
| */ |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@library/src/actions/rfc3339Time/rfc3339Time.ts` around lines 59 - 65, Remove
the JSDoc comment immediately preceding the overload in the RFC 3339 time action
declarations, while preserving the documentation on the first overload and
leaving the overload signatures unchanged.
Source: Coding guidelines
There was a problem hiding this comment.
3 issues found across 3 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="library/src/actions/rfc3339Time/rfc3339Time.ts">
<violation number="1" location="library/src/actions/rfc3339Time/rfc3339Time.ts:13">
P2: The RFC_3339_TIME_REGEX is defined locally in this file instead of in the shared `src/regex.ts` module. Every other validation regex in this codebase (ISO_TIME_REGEX, ISO_TIME_SECOND_REGEX, UUID_REGEX, ULID_REGEX, SLUG_REGEX, etc.) is defined in `src/regex.ts` and imported by the action file. Defining it here instead of in `regex.ts` breaks the project convention, makes the regex harder to reuse (e.g. in a future `rfc3339DateTime` action), and is inconsistent with how `isoTime` and `isoTimeSecond` handle their regex patterns.</violation>
<violation number="2" location="library/src/actions/rfc3339Time/rfc3339Time.ts:14">
P2: Valid RFC 3339 leap-second times such as `23:59:60Z` are rejected because the seconds group only permits `00`–`59`. Accept the `60` form (or explicitly document and test an intentional non-RFC restriction).</violation>
</file>
<file name="library/src/actions/index.ts">
<violation number="1" location="library/src/actions/index.ts:94">
P3: The new public action is exported without runtime or type tests, leaving valid offsets/fractions, invalid values, and overload typing unverified before publication. Adding the matching test files would keep this action aligned with the existing validator coverage convention.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| * offset (`Z` or `+/-HH:MM`). See issue #1496. | ||
| */ | ||
| const RFC_3339_TIME_REGEX: RegExp = | ||
| /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$/u; |
There was a problem hiding this comment.
P2: Valid RFC 3339 leap-second times such as 23:59:60Z are rejected because the seconds group only permits 00–59. Accept the 60 form (or explicitly document and test an intentional non-RFC restriction).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/rfc3339Time/rfc3339Time.ts, line 14:
<comment>Valid RFC 3339 leap-second times such as `23:59:60Z` are rejected because the seconds group only permits `00`–`59`. Accept the `60` form (or explicitly document and test an intentional non-RFC restriction).</comment>
<file context>
@@ -0,0 +1,90 @@
+ * offset (`Z` or `+/-HH:MM`). See issue #1496.
+ */
+const RFC_3339_TIME_REGEX: RegExp =
+ /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$/u;
+
+/**
</file context>
| /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$/u; | |
| /^([01]\d|2[0-3]):[0-5]\d:(?:[0-5]\d|60)(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$/u; |
| * `HH:MM:SS` with optional fractional seconds and an optional UTC or numeric | ||
| * offset (`Z` or `+/-HH:MM`). See issue #1496. | ||
| */ | ||
| const RFC_3339_TIME_REGEX: RegExp = |
There was a problem hiding this comment.
P2: The RFC_3339_TIME_REGEX is defined locally in this file instead of in the shared src/regex.ts module. Every other validation regex in this codebase (ISO_TIME_REGEX, ISO_TIME_SECOND_REGEX, UUID_REGEX, ULID_REGEX, SLUG_REGEX, etc.) is defined in src/regex.ts and imported by the action file. Defining it here instead of in regex.ts breaks the project convention, makes the regex harder to reuse (e.g. in a future rfc3339DateTime action), and is inconsistent with how isoTime and isoTimeSecond handle their regex patterns.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/rfc3339Time/rfc3339Time.ts, line 13:
<comment>The RFC_3339_TIME_REGEX is defined locally in this file instead of in the shared `src/regex.ts` module. Every other validation regex in this codebase (ISO_TIME_REGEX, ISO_TIME_SECOND_REGEX, UUID_REGEX, ULID_REGEX, SLUG_REGEX, etc.) is defined in `src/regex.ts` and imported by the action file. Defining it here instead of in `regex.ts` breaks the project convention, makes the regex harder to reuse (e.g. in a future `rfc3339DateTime` action), and is inconsistent with how `isoTime` and `isoTimeSecond` handle their regex patterns.</comment>
<file context>
@@ -0,0 +1,90 @@
+ * `HH:MM:SS` with optional fractional seconds and an optional UTC or numeric
+ * offset (`Z` or `+/-HH:MM`). See issue #1496.
+ */
+const RFC_3339_TIME_REGEX: RegExp =
+ /^([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]([01]\d|2[0-3]):[0-5]\d)?$/u;
+
</file context>
| export * from './regex/index.ts'; | ||
| export * from './returns/index.ts'; | ||
| export * from './rfcEmail/index.ts'; | ||
| export * from './rfc3339Time/index.ts'; |
There was a problem hiding this comment.
P3: The new public action is exported without runtime or type tests, leaving valid offsets/fractions, invalid values, and overload typing unverified before publication. Adding the matching test files would keep this action aligned with the existing validator coverage convention.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At library/src/actions/index.ts, line 94:
<comment>The new public action is exported without runtime or type tests, leaving valid offsets/fractions, invalid values, and overload typing unverified before publication. Adding the matching test files would keep this action aligned with the existing validator coverage convention.</comment>
<file context>
@@ -91,6 +91,7 @@ export * from './reduceItems/index.ts';
export * from './regex/index.ts';
export * from './returns/index.ts';
export * from './rfcEmail/index.ts';
+export * from './rfc3339Time/index.ts';
export * from './safeInteger/index.ts';
export * from './size/index.ts';
</file context>
Closes #1496.
Add an
rfc3339Time(message?)action that validatesHH:MM:SSwith optional fractional seconds (.\d+) and an optional offset (Zor+/ HH:MM), e.g.14:30:00,14:30:00Z,14:30:00.123 05:00. Unlike isoTime it requires seconds; unlike isoTimeSecond it accepts offsets and fractional seconds.Summary by CodeRabbit
HH:MM:SS, with optional fractional seconds and timezone information.