-
-
Notifications
You must be signed in to change notification settings - Fork 100
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 validator addition #208
Conversation
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.
Perfect! Love all the tests. I'm putting this upstream issue as sort of a blocker. The changes required would be quite small.
@@ -0,0 +1,265 @@ | |||
import moment from 'moment'; |
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 think we can/should avoid moment and use native JS functions or date-fns
if last resort.
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 used it in the unit tests since the dependency was needed anyway so might as well use the closest thing possible to the validator implementation. If ember-validators does remove moment
it would indeed be better to work without it in tests.
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.
For the extremely simple cases ember-validators uses it for, it definitely should be optional and use the platform if so. This test would still be useful as the API would look like:
validator(key, 'Nov || 3rd || 1998', { dateFn: moment })
or something like that
); | ||
assert.equal(validator(key, 'Nov || 3rd || 1998'), true); | ||
}); | ||
|
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.
wow. Phenomenal tests!
addon/validators/date.js
Outdated
}; | ||
} | ||
|
||
export {errorFormat}; |
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.
export { errorFormat }
addon/validators/date.js
Outdated
const errorFormat = "MMM Do, YYYY"; | ||
|
||
export default function validateNumber(options = {}) { | ||
options = withDefaults(options, { allowBlank: false, errorFormat: errorFormat}); |
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.
... errorFormat: errorFormat }
Another thought is we just re-implement the date validator ourselves if that issue goes unaddressed for some reason. |
I have a feeling we need to roll our own and avoid use of |
I have the impression that working with vanilla
Implementing date validations from scratch sounds a bit demanding and I don't have plenty of time right now, though I am coincidentally working with Dayjs in another project and it seems pretty small and useful for both operations and testing/comparisons. I can try giving it a go this weekend if that sounds good to you and can let you if I have any progress. |
That sounds good! If we do go the route of requiring a library, tree shakeability or immutability would be important points! Just to note, if we are limited https://github.com/offirgolan/ember-validators/blob/master/addon/date.js |
@jathanasiou Would this be something you would like me to tackle? I got the time ;) |
@snewcomer Apologies for the delay. I have other tasks on my plate right now and cannot currently commit to this. If you'd like to do the rest of the work and to refactor out |
Closes #204 .
Changes proposed in this pull request
Adds
date
validator, along with documentation and unit testing of corresponding options.Moment shim had to be included in order for the validator and tests to run.