date.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _rule = require('../rule/');
  6. var _rule2 = _interopRequireDefault(_rule);
  7. var _util = require('../util');
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9. function date(rule, value, callback, source, options) {
  10. // console.log('integer rule called %j', rule);
  11. var errors = [];
  12. var validate = rule.required || !rule.required && source.hasOwnProperty(rule.field);
  13. // console.log('validate on %s value', value);
  14. if (validate) {
  15. if ((0, _util.isEmptyValue)(value) && !rule.required) {
  16. return callback();
  17. }
  18. _rule2['default'].required(rule, value, source, errors, options);
  19. if (!(0, _util.isEmptyValue)(value)) {
  20. var dateObject = void 0;
  21. if (typeof value === 'number') {
  22. dateObject = new Date(value);
  23. } else {
  24. dateObject = value;
  25. }
  26. _rule2['default'].type(rule, dateObject, source, errors, options);
  27. if (dateObject) {
  28. _rule2['default'].range(rule, dateObject.getTime(), source, errors, options);
  29. }
  30. }
  31. }
  32. callback(errors);
  33. }
  34. exports['default'] = date;
  35. module.exports = exports['default'];