-
Notifications
You must be signed in to change notification settings - Fork 96
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
Specify format: 'date-time' for date properties #322
Specify format: 'date-time' for date properties #322
Conversation
Looks like we might have hit this issue ajv-validator/ajv-formats#73 |
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.
I am not a regex guru by any means and I understand if you don't want to write a full test suite before confirming approach is valid, but a couple of sanity test cases to begin would help.
Even the happiest path 2022-10-14T10:20:30.405060Z
doesn't appear to pass the regex.
I have no problem at all (and actually probably prefer it) for us to come up with our own tailor-made regex since we have specific requirements on the format.
where are you seeing this? im pretty sure it works just fine /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test('2022-10-14T10:20:30.405060Z') // true the only issue i potentially could see is that we have extra precision compared to browser environments, so if they changed the |
@dcrousso, you are right, I sanity tested a few tests and saw the wrong result, it's |
can you elaborate why that is unexpected? is the issue that there's not enough precision? |
I'm happy that @thehenrytsai gave me permission to just add our own regex for the Once I made the change, I can see that some tests started to fail immediately, and they were easy to patch up. We started with 12 errors; I got it down to 2 errors with 59cc6ba. The remaining errors I get from running
It looks like the Temporal library is not writing the trailing 'Z' in its toString() method.
I don't quite understand the nuance of the ISO 8601 format, currently I'm assuming that a trailing Z is required, which is what @thehenrytsai wrote in #113. These might be relevant: Having read this comment from 133 above, I think PlainDateTime is not the right class because it explicitly doesn't support time zones. Most likely, we should switch to using Instant instead. |
In 2189fd3 I just decided to inline the date strings and that made all the tests pass. Let me know if we want to keep that. |
edea949
to
2189fd3
Compare
I figured out how to construct Now the code looks more like how it was before, but we're not using I hope this patch can now be called completed. If we want to ensure that there are always 6 digits before the Z, the following regex can be used:
|
Yes, please enforce 6 digits, and please add tests to sanity verify the 3 cases outlined in #113 as you referenced. |
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.
Thanks @duncanmak for the contribution! 🙏 🚀 🥇
Addresses #147.
According to https://json-schema.org/understanding-json-schema/reference/string.html#dates-and-times, there's already a predefined format called
date-time
for the ISO-8601 format in JSON Schema.The concrete definition is here:
These formats are part of the
ajv-formats
package, so I've added it via npm. If we want to avoid installing an entire package, we could also add a single format using theaddFormat
method in our owncompile-validators.js
.While` I'm at it, I also bumped the ajv package version, I could back that out if we don't want to bundle it in.Having reviewed #150, I hope that by using a regex defined elsewhere, that this is a better approach that what was in #150.
If this PR is indeed correct, I can work out some test cases and add it to the test suite.
cc @thehenrytsai @diehuxx