Commit 4a1734b77edac0a1ac9465d5f17856b6a3725425
1 parent
a1c88eba
fix time and time-range parsers
Showing
2 changed files
with
12 additions
and
4 deletions
Show diff stats
src/components/date-picker/picker.vue
... | ... | @@ -160,11 +160,17 @@ |
160 | 160 | // check if its empty values |
161 | 161 | if (isEmptyArray(val)) return true; |
162 | 162 | |
163 | + // check if is time format | |
164 | + if (val[0].match(/^[\d:]+$/) && val[1].match(/^[\d:]+$/)) return true; | |
165 | + | |
163 | 166 | // check if its valid value |
164 | 167 | const [start, end] = val.map(v => new Date(v)); |
165 | 168 | return !isNaN(start.getTime()) && !isNaN(end.getTime()); |
166 | 169 | } else { |
167 | - if (typeof val === 'string') val = val.trim(); | |
170 | + if (typeof val === 'string') { | |
171 | + val = val.trim(); | |
172 | + if (val.match(/^[\d:]+$/)) return true; // time format | |
173 | + } | |
168 | 174 | const date = new Date(val); |
169 | 175 | return val === '' || val === null || !isNaN(date.getTime()); |
170 | 176 | } |
... | ... | @@ -176,10 +182,10 @@ |
176 | 182 | } |
177 | 183 | }, |
178 | 184 | data(){ |
179 | - | |
180 | 185 | const isRange = this.type.includes('range'); |
181 | 186 | const emptyArray = isRange ? [null, null] : [null]; |
182 | - const initialValue = isEmptyArray(this.value || []) ? emptyArray : this.parseDate(this.value); | |
187 | + const initialValue = isEmptyArray((isRange ? this.value : [this.value]) || []) ? emptyArray : this.parseDate(this.value); | |
188 | + | |
183 | 189 | return { |
184 | 190 | prefixCls: prefixCls, |
185 | 191 | showClose: false, |
... | ... | @@ -329,6 +335,8 @@ |
329 | 335 | } else { |
330 | 336 | if (typeof val === 'string') { |
331 | 337 | val = parser(val, format); |
338 | + } else if (type === 'timerange') { | |
339 | + val = parser(val, format); | |
332 | 340 | } else { |
333 | 341 | val = val.map(date => new Date(date)); // try to parse |
334 | 342 | val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed | ... | ... |
src/components/date-picker/util.js
... | ... | @@ -167,7 +167,7 @@ const RANGE_FORMATTER = function(value, format) { |
167 | 167 | return ''; |
168 | 168 | }; |
169 | 169 | const RANGE_PARSER = function(text, format) { |
170 | - const array = text.split(RANGE_SEPARATOR); | |
170 | + const array = Array.isArray(text) ? text : text.split(RANGE_SEPARATOR); | |
171 | 171 | if (array.length === 2) { |
172 | 172 | const range1 = array[0]; |
173 | 173 | const range2 = array[1]; | ... | ... |