diff --git a/src/components/date-picker/picker.vue b/src/components/date-picker/picker.vue index a622064..6d877f8 100644 --- a/src/components/date-picker/picker.vue +++ b/src/components/date-picker/picker.vue @@ -72,7 +72,7 @@ import clickoutside from '../../directives/clickoutside'; import TransferDom from '../../directives/transfer-dom'; import { oneOf } from '../../utils/assist'; - import { DEFAULT_FORMATS, TYPE_VALUE_RESOLVER_MAP } from './util'; + import { DEFAULT_FORMATS, RANGE_SEPARATOR, TYPE_VALUE_RESOLVER_MAP } from './util'; import Emitter from '../../mixins/emitter'; const prefixCls = 'ivu-date-picker'; @@ -336,8 +336,14 @@ } else if (type === 'timerange') { val = parser(val, format).map(v => v || ''); } else { - val = val.map(date => new Date(date)); // try to parse - val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed + const [start, end] = val; + if (start instanceof Date && end instanceof Date){ + val = val.map(date => new Date(date)); + } else if (typeof start === 'string' && typeof end === 'string'){ + val = parser(val.join(RANGE_SEPARATOR), format); + } else if (!start || !end){ + val = [null, null]; + } } } } else if (typeof val === 'string' && type.indexOf('time') !== 0){ diff --git a/src/components/date-picker/util.js b/src/components/date-picker/util.js index 9074652..0531b4a 100644 --- a/src/components/date-picker/util.js +++ b/src/components/date-picker/util.js @@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = { datetimerange: 'yyyy-MM-dd HH:mm:ss' }; -const RANGE_SEPARATOR = ' - '; +export const RANGE_SEPARATOR = ' - '; const DATE_FORMATTER = function(value, format) { return formatDate(value, format); -- libgit2 0.21.4