-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for timestamp on date assert #102
base: master
Are you sure you want to change the base?
Add support for timestamp on date assert #102
Conversation
describe('DateAssert', () => { | ||
it('should throw an error if the input value is not a string or a date', () => { | ||
const choices = [[], {}, 123]; | ||
describe.only('DateAssert', () => { |
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.
👀
Can you apply the same changes to NullOrDateAssert, DateDiffGreaterThanAssert, DateDiffLessThanAssert? |
if (typeof value !== 'string' && Object.prototype.toString.call(value) !== '[object Date]') { | ||
throw new Violation(this, value, { value: 'must_be_a_date_or_a_string' }); | ||
if (typeof value === 'string') { | ||
if (isNaN(Date.parse(value)) === 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.
if (isNaN(Date.parse(value))) {
69b8552
to
3c247f3
Compare
Added a few more tests and fixed comments. Can you fix the other asserts before merging this in? |
3c247f3
to
ddf9ab1
Compare
c0cc9a6
to
1cc468e
Compare
@@ -152,6 +152,9 @@ Tests if the value is valid json. | |||
### NotEmpty | |||
Tests if the value is not an empty (empty object, empty array, empty string, etc). | |||
|
|||
### NullOrDate | |||
Tests if the value is a `null` or `date`. |
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.
...or a number
? (timestamp)
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.
If so we need to update here as well.
1cc468e
to
7d7dfad
Compare
Closes #93.
Some options were explored such as using a RegExp or forcing
moment
as a requirement. The proposed solution (the simplest) proved to be the most reliable though.