-
-
Notifications
You must be signed in to change notification settings - Fork 366
feat: RFC 3339 time Validator #1556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './rfc3339Time.ts'; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,90 @@ | ||||||||||||||||
| import type { | ||||||||||||||||
| BaseIssue, | ||||||||||||||||
| BaseValidation, | ||||||||||||||||
| ErrorMessage, | ||||||||||||||||
| } from '../../types/index.ts'; | ||||||||||||||||
| import { _addIssue } from '../../utils/index.ts'; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * The [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) time regex. Matches | ||||||||||||||||
| * `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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The RFC_3339_TIME_REGEX is defined locally in this file instead of in the shared Prompt for AI agents |
||||||||||||||||
| /^([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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Valid RFC 3339 leap-second times such as Prompt for AI agents
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * RFC 3339 time issue interface. | ||||||||||||||||
| */ | ||||||||||||||||
| export interface Rfc3339TimeIssue<TInput extends string> | ||||||||||||||||
| extends BaseIssue<TInput> { | ||||||||||||||||
| readonly kind: 'validation'; | ||||||||||||||||
| readonly type: 'rfc3339_time'; | ||||||||||||||||
| readonly expected: null; | ||||||||||||||||
| readonly received: `"${string}"`; | ||||||||||||||||
| readonly requirement: RegExp; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * RFC 3339 time action interface. | ||||||||||||||||
| */ | ||||||||||||||||
| export interface Rfc3339TimeAction< | ||||||||||||||||
| TInput extends string, | ||||||||||||||||
| TMessage extends ErrorMessage<Rfc3339TimeIssue<TInput>> | undefined, | ||||||||||||||||
| > extends BaseValidation<TInput, TInput, Rfc3339TimeIssue<TInput>> { | ||||||||||||||||
| readonly type: 'rfc3339_time'; | ||||||||||||||||
| readonly reference: typeof rfc3339Time; | ||||||||||||||||
| readonly expects: null; | ||||||||||||||||
| readonly requirement: RegExp; | ||||||||||||||||
| readonly message: TMessage; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Creates an [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) time validation | ||||||||||||||||
| * action. | ||||||||||||||||
| * | ||||||||||||||||
| * Format: `HH:MM:SS` with optional fractional seconds and an optional UTC or | ||||||||||||||||
| * numeric offset (`Z` or `+/-HH:MM`), e.g. `14:30:00`, `14:30:00Z`, | ||||||||||||||||
| * `14:30:00.123-05:00`. Unlike {@link isoTime} (`HH:MM`) and | ||||||||||||||||
| * {@link isoTimeSecond} (`HH:MM:SS`), this accepts the RFC 3339 offset and | ||||||||||||||||
| * fractional-seconds forms needed for OpenAPI `format: time`. See issue #1496. | ||||||||||||||||
| * | ||||||||||||||||
| * @returns An RFC 3339 time action. | ||||||||||||||||
| */ | ||||||||||||||||
| export function rfc3339Time<TInput extends string>(): Rfc3339TimeAction< | ||||||||||||||||
| TInput, | ||||||||||||||||
| undefined | ||||||||||||||||
| >; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Creates an RFC 3339 time validation action. | ||||||||||||||||
| * | ||||||||||||||||
| * @param message The error message. | ||||||||||||||||
| * | ||||||||||||||||
| * @returns An RFC 3339 time action. | ||||||||||||||||
| */ | ||||||||||||||||
|
Comment on lines
+59
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 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
Suggested change
🤖 Prompt for AI AgentsSource: Coding guidelines |
||||||||||||||||
| export function rfc3339Time< | ||||||||||||||||
| TInput extends string, | ||||||||||||||||
| const TMessage extends ErrorMessage<Rfc3339TimeIssue<TInput>> | undefined, | ||||||||||||||||
| >(message: TMessage): Rfc3339TimeAction<TInput, TMessage>; | ||||||||||||||||
|
|
||||||||||||||||
| // @__NO_SIDE_EFFECTS__ | ||||||||||||||||
| export function rfc3339Time( | ||||||||||||||||
| message?: ErrorMessage<Rfc3339TimeIssue<string>>, | ||||||||||||||||
| ): Rfc3339TimeAction<string, ErrorMessage<Rfc3339TimeIssue<string>> | undefined> { | ||||||||||||||||
| return { | ||||||||||||||||
| kind: 'validation', | ||||||||||||||||
| type: 'rfc3339_time', | ||||||||||||||||
| reference: rfc3339Time, | ||||||||||||||||
| async: false, | ||||||||||||||||
| expects: null, | ||||||||||||||||
| requirement: RFC_3339_TIME_REGEX, | ||||||||||||||||
| message, | ||||||||||||||||
| '~run'(dataset, config) { | ||||||||||||||||
| if (dataset.typed && !this.requirement.test(dataset.value)) { | ||||||||||||||||
| _addIssue(this, 'time', dataset, config); | ||||||||||||||||
| } | ||||||||||||||||
| return dataset; | ||||||||||||||||
| }, | ||||||||||||||||
| }; | ||||||||||||||||
| } | ||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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