Merge pull request #3315 from SergioCrisostomo/fix-3232
Fix date parsing
This commit is contained in:
commit
89f0868b34
2 changed files with 10 additions and 4 deletions
|
@ -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){
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue