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

date and date-time do not support formatMaximum validation for years >=10000 🤷‍♂️ #61

Open
robertrossmann opened this issue Mar 21, 2018 · 3 comments

Comments

@robertrossmann
Copy link

When you create a Date object in UTC timezone in JavaScript as follows

new Date(10000, null)

and convert it to ISO string, you get +010000-01-01T00:00:00.000Z (notice the leading +0 string).

This seems to follow the ISO 8601 standard.

This breaks the formatMaximum (and possibly also formatMinimum) validation because the dates are compared as plain strings, ie. eventually you get to a point where your compare "2018" and "+010000" and as far as JS strings are concerned, 2018 is greater, even though the intention was to compare year 2018 and year 10000.

Here, the ISO string is split into year component:

https://github.com/epoberezkin/ajv-keywords/blob/5f9eccc2e2b95745f659ef1abf5488f70da496f2/keywords/_formatLimit.js#L83-L87

And here is the actual string comparison of the two dates:

https://github.com/epoberezkin/ajv-keywords/blob/5f9eccc2e2b95745f659ef1abf5488f70da496f2/keywords/_formatLimit.js#L62-L67

@epoberezkin
Copy link
Member

What’s the use case I wonder...

@robertrossmann
Copy link
Author

I come from the year 9999. ajv and ajv-keywords has become the most prevailing validation software on the whole local stellar cluster. However, due to this limitation, we are afraid of a Y10K problem (similar to Y2K) where stepping into the year 10000 would break the whole economy and plunge humanity into chaos due to issues with unsupported date format.

We have identified this version to be the most likely point in time where this can still be fixed before the codebase evolves beyond easy fix. I have been appointed by the High Council for Economic Galactic Stability to travel back in time and resolve the problem before it becomes a major source for panic.

On a more serious note: We stumbled upon this issue while trying to "future-proof" some aspects of our product where users may want, on rare occasions, to create appointments in the distant future, mostly as a joke.

@epoberezkin
Copy link
Member

epoberezkin commented Apr 10, 2018

I am quite excited to learn that ajv (and JavaScript) have such a long and illustrious future to come, and AI apparently didn’t take over, and people still write code, at least in some part of space-time continuum.

I will have released the fix to this problem in 2048, in some part of the future timelines. In another part of future timelines there will have been a PR submitted and merged in 2018-19 by various users, depending on the timeline.

Either way, this problem is resolved in 9999, so your mission was a complete success, @robertrossmann

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

No branches or pull requests

2 participants