fix time and time-range parsers
This commit is contained in:
parent
a1c88ebaf8
commit
4a1734b77e
2 changed files with 12 additions and 4 deletions
|
@ -160,11 +160,17 @@
|
||||||
// check if its empty values
|
// check if its empty values
|
||||||
if (isEmptyArray(val)) return true;
|
if (isEmptyArray(val)) return true;
|
||||||
|
|
||||||
|
// check if is time format
|
||||||
|
if (val[0].match(/^[\d:]+$/) && val[1].match(/^[\d:]+$/)) return true;
|
||||||
|
|
||||||
// check if its valid value
|
// check if its valid value
|
||||||
const [start, end] = val.map(v => new Date(v));
|
const [start, end] = val.map(v => new Date(v));
|
||||||
return !isNaN(start.getTime()) && !isNaN(end.getTime());
|
return !isNaN(start.getTime()) && !isNaN(end.getTime());
|
||||||
} else {
|
} else {
|
||||||
if (typeof val === 'string') val = val.trim();
|
if (typeof val === 'string') {
|
||||||
|
val = val.trim();
|
||||||
|
if (val.match(/^[\d:]+$/)) return true; // time format
|
||||||
|
}
|
||||||
const date = new Date(val);
|
const date = new Date(val);
|
||||||
return val === '' || val === null || !isNaN(date.getTime());
|
return val === '' || val === null || !isNaN(date.getTime());
|
||||||
}
|
}
|
||||||
|
@ -176,10 +182,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data(){
|
data(){
|
||||||
|
|
||||||
const isRange = this.type.includes('range');
|
const isRange = this.type.includes('range');
|
||||||
const emptyArray = isRange ? [null, null] : [null];
|
const emptyArray = isRange ? [null, null] : [null];
|
||||||
const initialValue = isEmptyArray(this.value || []) ? emptyArray : this.parseDate(this.value);
|
const initialValue = isEmptyArray((isRange ? this.value : [this.value]) || []) ? emptyArray : this.parseDate(this.value);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
showClose: false,
|
showClose: false,
|
||||||
|
@ -329,6 +335,8 @@
|
||||||
} else {
|
} else {
|
||||||
if (typeof val === 'string') {
|
if (typeof val === 'string') {
|
||||||
val = parser(val, format);
|
val = parser(val, format);
|
||||||
|
} else if (type === 'timerange') {
|
||||||
|
val = parser(val, format);
|
||||||
} else {
|
} else {
|
||||||
val = val.map(date => new Date(date)); // try to parse
|
val = val.map(date => new Date(date)); // try to parse
|
||||||
val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed
|
val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed
|
||||||
|
|
|
@ -167,7 +167,7 @@ const RANGE_FORMATTER = function(value, format) {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
const RANGE_PARSER = function(text, format) {
|
const RANGE_PARSER = function(text, format) {
|
||||||
const array = text.split(RANGE_SEPARATOR);
|
const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR);
|
||||||
if (array.length === 2) {
|
if (array.length === 2) {
|
||||||
const range1 = array[0];
|
const range1 = array[0];
|
||||||
const range2 = array[1];
|
const range2 = array[1];
|
||||||
|
|
Loading…
Add table
Reference in a new issue