Commit 524dc2a5f6385bc659f1bb38ccaa404679309f1a
1 parent
309912df
Fix date parsing
Fixes #3232
Showing
2 changed files
with
10 additions
and
4 deletions
Show diff stats
src/components/date-picker/picker.vue
@@ -72,7 +72,7 @@ | @@ -72,7 +72,7 @@ | ||
72 | import clickoutside from '../../directives/clickoutside'; | 72 | import clickoutside from '../../directives/clickoutside'; |
73 | import TransferDom from '../../directives/transfer-dom'; | 73 | import TransferDom from '../../directives/transfer-dom'; |
74 | import { oneOf } from '../../utils/assist'; | 74 | import { oneOf } from '../../utils/assist'; |
75 | - import { DEFAULT_FORMATS, TYPE_VALUE_RESOLVER_MAP } from './util'; | 75 | + import { DEFAULT_FORMATS, RANGE_SEPARATOR, TYPE_VALUE_RESOLVER_MAP } from './util'; |
76 | import Emitter from '../../mixins/emitter'; | 76 | import Emitter from '../../mixins/emitter'; |
77 | 77 | ||
78 | const prefixCls = 'ivu-date-picker'; | 78 | const prefixCls = 'ivu-date-picker'; |
@@ -336,8 +336,14 @@ | @@ -336,8 +336,14 @@ | ||
336 | } else if (type === 'timerange') { | 336 | } else if (type === 'timerange') { |
337 | val = parser(val, format).map(v => v || ''); | 337 | val = parser(val, format).map(v => v || ''); |
338 | } else { | 338 | } else { |
339 | - val = val.map(date => new Date(date)); // try to parse | ||
340 | - val = val.map(date => isNaN(date.getTime()) ? null : date); // check if parse passed | 339 | + const [start, end] = val; |
340 | + if (start instanceof Date && end instanceof Date){ | ||
341 | + val = val.map(date => new Date(date)); | ||
342 | + } else if (typeof start === 'string' && typeof end === 'string'){ | ||
343 | + val = parser(val.join(RANGE_SEPARATOR), format); | ||
344 | + } else if (!start || !end){ | ||
345 | + val = [null, null]; | ||
346 | + } | ||
341 | } | 347 | } |
342 | } | 348 | } |
343 | } else if (typeof val === 'string' && type.indexOf('time') !== 0){ | 349 | } else if (typeof val === 'string' && type.indexOf('time') !== 0){ |
src/components/date-picker/util.js
@@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = { | @@ -147,7 +147,7 @@ export const DEFAULT_FORMATS = { | ||
147 | datetimerange: 'yyyy-MM-dd HH:mm:ss' | 147 | datetimerange: 'yyyy-MM-dd HH:mm:ss' |
148 | }; | 148 | }; |
149 | 149 | ||
150 | -const RANGE_SEPARATOR = ' - '; | 150 | +export const RANGE_SEPARATOR = ' - '; |
151 | 151 | ||
152 | const DATE_FORMATTER = function(value, format) { | 152 | const DATE_FORMATTER = function(value, format) { |
153 | return formatDate(value, format); | 153 | return formatDate(value, format); |