Commit 5092777d174656722ec3a7c057902868dfc3fc2e
1 parent
73a34dfa
Fix sort of date arrays
Showing
1 changed file
with
7 additions
and
3 deletions
Show diff stats
src/components/date-picker/panel/Date/date-range.vue
... | ... | @@ -127,6 +127,10 @@ |
127 | 127 | const prefixCls = 'ivu-picker-panel'; |
128 | 128 | const datePrefixCls = 'ivu-date-picker'; |
129 | 129 | |
130 | + const dateSorter = (a, b) => { | |
131 | + if (!a || !b) return 0; | |
132 | + return a.getTime() - b.getTime(); | |
133 | + }; | |
130 | 134 | |
131 | 135 | export default { |
132 | 136 | name: 'RangeDatePickerPanel', |
... | ... | @@ -185,14 +189,14 @@ |
185 | 189 | return { |
186 | 190 | left: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'left'), |
187 | 191 | right: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'right'), |
188 | - } | |
192 | + }; | |
189 | 193 | } |
190 | 194 | }, |
191 | 195 | watch: { |
192 | 196 | value(newVal) { |
193 | 197 | const minDate = newVal[0] ? toDate(newVal[0]) : null; |
194 | 198 | const maxDate = newVal[1] ? toDate(newVal[1]) : null; |
195 | - this.dates = [minDate, maxDate].sort(); | |
199 | + this.dates = [minDate, maxDate].sort(dateSorter); | |
196 | 200 | |
197 | 201 | this.rangeState = { |
198 | 202 | from: this.dates[0], |
... | ... | @@ -308,7 +312,7 @@ |
308 | 312 | }, |
309 | 313 | handleRangePick (val) { |
310 | 314 | if (this.rangeState.selecting || this.currentView === 'time'){ |
311 | - const [minDate, maxDate] = [this.rangeState.from, val].sort((a, b) => a - b); | |
315 | + const [minDate, maxDate] = [this.rangeState.from, val].sort(dateSorter); | |
312 | 316 | this.dates = [minDate, maxDate]; |
313 | 317 | if (this.currentView === 'time'){ |
314 | 318 | this.dates = val; | ... | ... |