You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
901 B
32 lines
901 B
import rules from '../rule/';
|
|
import { isEmptyValue } from '../util';
|
|
|
|
function date(rule, value, callback, source, options) {
|
|
// console.log('integer rule called %j', rule);
|
|
var errors = [];
|
|
var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
|
|
// console.log('validate on %s value', value);
|
|
if (validate) {
|
|
if (isEmptyValue(value) && !rule.required) {
|
|
return callback();
|
|
}
|
|
rules.required(rule, value, source, errors, options);
|
|
if (!isEmptyValue(value)) {
|
|
var dateObject = void 0;
|
|
|
|
if (typeof value === 'number') {
|
|
dateObject = new Date(value);
|
|
} else {
|
|
dateObject = value;
|
|
}
|
|
|
|
rules.type(rule, dateObject, source, errors, options);
|
|
if (dateObject) {
|
|
rules.range(rule, dateObject.getTime(), source, errors, options);
|
|
}
|
|
}
|
|
}
|
|
callback(errors);
|
|
}
|
|
|
|
export default date; |