-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow passing an option to string().isoDate() #1197
Conversation
06e46a9
to
847cb49
Compare
would it not make more sense to make it follow the |
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.
Yeah, I would actually rather this be a breaking change and follow the convert
path instead of the options object, too.
Also there's a test failing in the Node v4 suite ;)
Yah figured it should follow that option, but wanted to introduce it as a non breaking change first. I'll update and fix that test :) |
f7e9e5b
to
bcae592
Compare
lib/types/string/index.js
Outdated
try { | ||
return new Date(value).toISOString(); | ||
} | ||
catch (err) { } |
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.
We should be handling the error here.
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 now return the isoDate Error in the catch block with some additional details (the thrown err which will say why it was unable to convert to ISO string, and the fact that convert is true) instead of just falling through to the standard isoDate error. Would you prefer I add a new error type (i.e. isoDateConvert) that has a message that explicitly calls out that it was the conversion that failed?
bcae592
to
388688a
Compare
Looking good! Since |
388688a
to
258ad7a
Compare
@AdriVanHoudt it would be a breaking change because now dates passed as |
…mplified extended ISO format Mimics the formatting returned by date().iso() Includes tests
258ad7a
to
2a8f232
Compare
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 don't really mind this change personally, but it's a bit of a stretch. ISO format has many optional parts, and the dates you mentioned in the original issue are already in ISO format afaict, it's just not the format you'd want.
return new Date(value).toISOString(); | ||
} | ||
catch (err) { | ||
return this.createError('string.isoDate', { value, reason: err, convert: options.convert }, state, options); |
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 don't think this line is needed, that context is wrong.
It's possible to set the convert false only for isoDate as isoDate option ? I just want to no convert that fields in my validate object |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Allow passing an option to string().isoDate() which formats the string as the simplified extended ISO format
Mimics the formatting returned by date().iso(), and the default ensures backwards compatibility.
ideally would use convert option to toggle whether the conversion happens, but since convert defaults to true, this would be a breaking change.
Closes #1196