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

Add support for timestamp on date assert #102

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

madeiras
Copy link

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.

@madeiras madeiras self-assigned this Apr 17, 2016
@madeiras madeiras added the enhancement New feature or request label Apr 17, 2016
describe('DateAssert', () => {
it('should throw an error if the input value is not a string or a date', () => {
const choices = [[], {}, 123];
describe.only('DateAssert', () => {
Copy link
Member

Choose a reason for hiding this comment

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

👀

@ruimarinho
Copy link
Member

ruimarinho commented Apr 23, 2016

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) {
Copy link
Member

@ruimarinho ruimarinho Apr 23, 2016

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))) {

@ruimarinho ruimarinho force-pushed the enhancement/add-support-for-timestamp-on-date-assert branch from 69b8552 to 3c247f3 Compare April 23, 2016 00:59
@ruimarinho
Copy link
Member

Added a few more tests and fixed comments. Can you fix the other asserts before merging this in?

@madeiras madeiras force-pushed the enhancement/add-support-for-timestamp-on-date-assert branch from 3c247f3 to ddf9ab1 Compare April 27, 2016 14:25
@franciscocardoso franciscocardoso force-pushed the enhancement/add-support-for-timestamp-on-date-assert branch from c0cc9a6 to 1cc468e Compare April 29, 2016 10:37
@@ -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`.
Copy link
Author

@madeiras madeiras Apr 29, 2016

Choose a reason for hiding this comment

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

...or a number ? (timestamp)

Copy link
Contributor

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.

@madeiras madeiras force-pushed the enhancement/add-support-for-timestamp-on-date-assert branch from 1cc468e to 7d7dfad Compare April 29, 2016 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants