-
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
Date assert should be able to handle unix timestamp #93
Comments
@JoaoHenriquePereira can you submit a PR adding |
Actually I took some time today to think about this. WDYT something like this: this.validate = value => {
if (typeof value === 'string') {
if (isNaN(Date.parse(value)) === true) {
throw new Violation(this, value);
}
return true;
}
if (typeof value === 'number') {
if (new Date(value).getTime() < 0) {
throw new Violation(this, value);
}
return true;
}
if (Object.prototype.toString.call(value) !== '[object Date]') {
throw new Violation(this, value, { value: 'must_be_a_date_or_a_string_or_a_timestamp' });
}
return true;
}; It keeps compatibility, adds support to evaluate a |
Update: Ok noticed you changed the assert already :) I'll update later what needs to be done. |
Something like that would work, yes. That would work for server as minor, otherwise adding moment has the caveat of making it a major (requires additional peer dependency). |
Note this from MDN:
|
I'll have a look on how I could add support for negative dates and submit a PR. |
No description provided.
The text was updated successfully, but these errors were encountered: