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

fix: ensure date-time is ISO format #75

Merged
merged 2 commits into from
Nov 28, 2023
Merged

Conversation

jessicamcinchak
Copy link
Member

ajv-formats & jsonschema both permit a flexible interpretation of date-time that allows spaces, but we want to restrict to an ISO timestamp as flagged by BOPS.

The iso-date-time format won't be available until ajv-formats v3.0.0 is released, so I'm combining the existing date-time with a regex @pattern for now. There's a numer of existing issue threads on this topic, eg ajv-validator/ajv-formats#55

@jessicamcinchak jessicamcinchak requested a review from a team November 28, 2023 08:32
"format": "date-time",
"pattern": "^[0-9]{4}-((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(02)-(0[1-9]|[12][0-9]))T(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])\\.[0-9]{3}Z$",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex is too strict now - according to the RFC 3339 spec the second fraction is optional and is any number of digits. Also the T and Z may be upper/lower case and timezone offsets are allowed, e.g. 2023-08-31T00:00:00+01:00.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching, examples updated to catch these more diverse scenarios and regex sourced from here now

Copy link
Contributor

@DafyddLlyr DafyddLlyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this one up and the detailed comments. I'm not sure if we've set up dependabot in this repo yet but that's something we should do soon which will also help us spot when v3 is released.

@@ -1227,7 +1227,9 @@
"type": "string"
},
"DateTime": {
"description": "Regex-based implementation of iso-date-time until available in [email protected]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jessicamcinchak jessicamcinchak merged commit bbd880f into main Nov 28, 2023
3 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/iso-date-time branch November 28, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants