Commit 89f0868b347c1bc2f71163b16f87f35019494350

Authored by Aresn
Committed by GitHub
2 parents 61339d63 524dc2a5

Merge pull request #3315 from SergioCrisostomo/fix-3232

Fix date parsing
src/components/date-picker/picker.vue
... ... @@ -72,7 +72,7 @@
72 72 import clickoutside from '../../directives/clickoutside';
73 73 import TransferDom from '../../directives/transfer-dom';
74 74 import { oneOf } from '../../utils/assist';
75   - import { DEFAULT_FORMATS, TYPE_VALUE_RESOLVER_MAP } from './util';
  75 + import { DEFAULT_FORMATS, RANGE_SEPARATOR, TYPE_VALUE_RESOLVER_MAP } from './util';
76 76 import Emitter from '../../mixins/emitter';
77 77  
78 78 const prefixCls = 'ivu-date-picker';
... ... @@ -336,8 +336,14 @@
336 336 } else if (type === 'timerange') {
337 337 val = parser(val, format).map(v => v || '');
338 338 } else {
339   - val = val.map(date => new Date(date)); // try to parse
340   - val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed
  339 + const [start, end] = val;
  340 + if (start instanceof Date && end instanceof Date){
  341 + val = val.map(date => new Date(date));
  342 + } else if (typeof start === 'string' && typeof end === 'string'){
  343 + val = parser(val.join(RANGE_SEPARATOR), format);
  344 + } else if (!start || !end){
  345 + val = [null, null];
  346 + }
341 347 }
342 348 }
343 349 } else if (typeof val === 'string' && type.indexOf('time') !== 0){
... ...
src/components/date-picker/util.js
... ... @@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = {
147 147 datetimerange: 'yyyy-MM-dd HH:mm:ss'
148 148 };
149 149  
150   -const RANGE_SEPARATOR = ' - ';
  150 +export const RANGE_SEPARATOR = ' - ';
151 151  
152 152 const DATE_FORMATTER = function(value, format) {
153 153 return formatDate(value, format);
... ...