Merge pull request #3315 from SergioCrisostomo/fix-3232

Fix date parsing
This commit is contained in:
Aresn 2018-04-10 16:58:30 +08:00 committed by GitHub
commit 89f0868b34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -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){

View file

@ -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);