From 4a1734b77edac0a1ac9465d5f17856b6a3725425 Mon Sep 17 00:00:00 2001 From: Sergio Crisostomo Date: Fri, 2 Feb 2018 14:26:44 +0100 Subject: [PATCH] fix time and time-range parsers --- src/components/date-picker/picker.vue | 14 +++++++++++--- src/components/date-picker/util.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/date-picker/picker.vue b/src/components/date-picker/picker.vue index 75431ab8..0aeb1c5d 100644 --- a/src/components/date-picker/picker.vue +++ b/src/components/date-picker/picker.vue @@ -160,11 +160,17 @@ // check if its empty values 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 const [start, end] = val.map(v => new Date(v)); return !isNaN(start.getTime()) && !isNaN(end.getTime()); } 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); return val === '' || val === null || !isNaN(date.getTime()); } @@ -176,10 +182,10 @@ } }, data(){ - const isRange = this.type.includes('range'); 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 { prefixCls: prefixCls, showClose: false, @@ -329,6 +335,8 @@ } else { if (typeof val === 'string') { val = parser(val, format); + } else if (type === 'timerange') { + val = parser(val, format); } else { val = val.map(date => new Date(date)); // try to parse val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed diff --git a/src/components/date-picker/util.js b/src/components/date-picker/util.js index 80aca94f..d85a2b56 100644 --- a/src/components/date-picker/util.js +++ b/src/components/date-picker/util.js @@ -167,7 +167,7 @@ const RANGE_FORMATTER = function(value, format) { return ''; }; 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) { const range1 = array[0]; const range2 = array[1];