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

does not work on YYYY-MM-DD #11

Closed
angelxmoreno opened this issue May 12, 2024 · 4 comments · Fixed by #13
Closed

does not work on YYYY-MM-DD #11

angelxmoreno opened this issue May 12, 2024 · 4 comments · Fixed by #13
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@angelxmoreno
Copy link
Owner

the regex seems to only match full date strings (YYYY-MM-DDTHH:mm:ss) and not dates (YYYY-MM-DD).

this could lead to breaking changes for users that found this to be expected. That being said, we should add a flag to trea date strings as Date objects.

@angelxmoreno angelxmoreno added enhancement New feature or request help wanted Extra attention is needed labels May 12, 2024
@angelxmoreno angelxmoreno changed the title does not work on YYY-MM-DD does not work on YYYY-MM-DD May 12, 2024
@angelxmoreno
Copy link
Owner Author

this regex seems a bit more inclusive:

const dateRegex = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?)?$/;

@OlliL
Copy link

OlliL commented Sep 4, 2024

You'll always end up with a solution where you can't guarantee that someone indeed wanted to have '2023-12-31' as a string instead of a date because its for example just a reference to whatever. The root cause is, that the response transformers have no idea about the object declaration they are about to create. So they never will have the chance to check the expected target type of each key but have to guess based on data. This will always lead to produce errors - unfortunately - with user input data.
I'm also eagerly looking for a clean solution to that problem - but I guess none exists unfortunately.

@angelxmoreno
Copy link
Owner Author

To clarify, what @OlliL is referring to is an example where a user chooses to name themself 1980-01-01. when a json with a key containing their name is parsed, the name field which is expected to be a string is now a Date object.

This is indeed a real issue @OlliL . I will made a separate issue to try to address it #12

@angelxmoreno
Copy link
Owner Author

released in v1.10.0 as a minor instead of a patch since existing users would now have date strings converted to date objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants