date.js 901 B

1234567891011121314151617181920212223242526272829303132
  1. import rules from '../rule/';
  2. import { isEmptyValue } from '../util';
  3. function date(rule, value, callback, source, options) {
  4. // console.log('integer rule called %j', rule);
  5. var errors = [];
  6. var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
  7. // console.log('validate on %s value', value);
  8. if (validate) {
  9. if (isEmptyValue(value) && !rule.required) {
  10. return callback();
  11. }
  12. rules.required(rule, value, source, errors, options);
  13. if (!isEmptyValue(value)) {
  14. var dateObject = void 0;
  15. if (typeof value === 'number') {
  16. dateObject = new Date(value);
  17. } else {
  18. dateObject = value;
  19. }
  20. rules.type(rule, dateObject, source, errors, options);
  21. if (dateObject) {
  22. rules.range(rule, dateObject.getTime(), source, errors, options);
  23. }
  24. }
  25. }
  26. callback(errors);
  27. }
  28. export default date;