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

Support for date-time, time string format. #337

Open
DonVietnam opened this issue Sep 19, 2023 · 5 comments
Open

Support for date-time, time string format. #337

DonVietnam opened this issue Sep 19, 2023 · 5 comments

Comments

@DonVietnam
Copy link

Quite often, when developing an API, there is a need to work with time, the most popular input data format with this approach is ISO 8601 ( 2018-11-13T20:20:39+00:00), it would be great to add validation support for this format out of the box. This format supports the JSON Schema specifications and is called 'date-time', there are also two additional formats for 'time' and 'date', since in this case 'date' is already occupied, we can use the 'date-time' type, under which all three JSON Schema formats will fit, or call type 'date' as 'date-string'.
If support for this format has already been implemented and I just haven't found it, I apologize.

@thib3113
Copy link
Collaborator

thib3113 commented Oct 8, 2023

@DonVietnam it's already done by "date" ?

date with convert will just handled all the format from the Date constructor : MDN .

So, ISO 8601 is already supported . with +00:00 (2018-11-13T20:20:39+00:00) timezone, or Z (2018-11-13T20:20:39Z) . Ou can also pass only date 2018-11-13 and so it will output the date to midnight .

Or I missunderstand ?

@DonVietnam
Copy link
Author

@DonVietnam it's already done by "date" ?

date with convert will just handled all the format from the Date constructor : MDN .

So, ISO 8601 is already supported . with +00:00 (2018-11-13T20:20:39+00:00) timezone, or Z (2018-11-13T20:20:39Z) . Ou can also pass only date 2018-11-13 and so it will output the date to midnight .

Or I missunderstand ?

No, I mean, exactly check if string contains date in ISO 8601 format, not any date string. Date constructor can accept many formats.

@thib3113
Copy link
Collaborator

thib3113 commented Oct 9, 2023

Oh ! ok, you want to be precise on the check ? not "all what can be a date" ? ( did you have any use case ? ) . Else, you can maybe do it with a string, and a regex pattern ?

@DonVietnam
Copy link
Author

Oh ! ok, you want to be precise on the check ? not "all what can be a date" ? ( did you have any use case ? ) . Else, you can maybe do it with a string, and a regex pattern ?

Yes, I want to check the date for exact compliance with the format, the essence of such a check is to use the validation library, specifying the desired format to it, and then just put the incoming data in the database. Why do I need a data validation library if I'm going to write regular expressions for data validation myself or translate everything into a Date object, and then drag out the desired format from there myself.
Why this particular format? As I have already written, this is the most commonly used format in the API. For example, it is recommended in the Postgresql DBMS, and it is also checked in the JSONSchema standard for a reason.

@thib3113
Copy link
Collaborator

thib3113 commented Oct 9, 2023

Why do I need a data validation library if I'm going to write regular expressions for data validation myself or translate everything into a Date object, and then drag out the desired format from there myself.

it can handle more than that . it can check multiples properties and return the object . ( and so "date" can be only one of the properties ), if you need it only for date validation, it's maybe not needed ?

About your use case, ok ... but so, you just need to do date.toISOString() ? or, converting to json will already handle a date and convert it to ISO ... And I'm pretty sure your library will already handle it too .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants