Skip to content
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

[Suggest] typia date format follow RFC3339 #1059

Closed
rojiwon123 opened this issue May 22, 2024 · 1 comment
Closed

[Suggest] typia date format follow RFC3339 #1059

rojiwon123 opened this issue May 22, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Projects

Comments

@rojiwon123
Copy link
Contributor

rojiwon123 commented May 22, 2024

Summary

suggest that the typia.tags.Format > "date-time" | "date" | "time" format follow RFC3339.

Problem

The current typia.tags.Format<'date-time'> format follows just ISO8601. it allows time and timezone to be omitted. And the type is represented as date-time in swagger when building swagger documentation.
However, the date-time format in swagger is defined by the date-time format in the RFC3339 standard, which requires the time and timezone to be indicated.

In conclusion, the current typia definition of date-time leads to inaccuracies in documentation and confusion of terms.

Therefore, I suggest the following

Suggest

format

  • RFC3339 standard full-date format is define typia.tags.Format<'date'>
  • RFC3339 standard full-time format is define typia.tags.Format<'time'>
  • RFC3339 standard date-time format is define typia.tags.Format<'date-time'>

code

export const FormatCheatSheet = {
// ...
"date-time": RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])(T|\\s)([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`),
"date": RegexCall(`/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/`),
"time": RegexCall(`/^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](?:\\.[0-9]{1,9})?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])$/i`),
// ...
};

Example

// before
import typia from "typia"
typia.is<string & typia.tags.Format<"date-time">>("2024-05-23"); // true
typia.is<string & typia.tags.Format<"date-time">>("2024-05-23T23:59:59Z"); // true
// after
import typia from "typia"
typia.is<string & typia.tags.Format<"date-time">>("2024-05-23"); // false
typia.is<string & typia.tags.Format<"date-time">>("2024-05-23T23:59:59Z"); // true

Reference

@samchon
Copy link
Owner

samchon commented May 25, 2024

Of course, why not

@samchon samchon assigned samchon and rojiwon123 and unassigned samchon May 25, 2024
@samchon samchon added enhancement New feature or request good first issue Good for newcomers labels May 25, 2024
@samchon samchon added this to To do in v6 Update via automation May 25, 2024
v6 Update automation moved this from To do to Done May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Development

No branches or pull requests

2 participants