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,6 +127,10 @@ | ||
| 127 | const prefixCls = 'ivu-picker-panel'; | 127 | const prefixCls = 'ivu-picker-panel'; |
| 128 | const datePrefixCls = 'ivu-date-picker'; | 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 | export default { | 135 | export default { |
| 132 | name: 'RangeDatePickerPanel', | 136 | name: 'RangeDatePickerPanel', |
| @@ -185,14 +189,14 @@ | @@ -185,14 +189,14 @@ | ||
| 185 | return { | 189 | return { |
| 186 | left: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'left'), | 190 | left: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'left'), |
| 187 | right: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'right'), | 191 | right: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'right'), |
| 188 | - } | 192 | + }; |
| 189 | } | 193 | } |
| 190 | }, | 194 | }, |
| 191 | watch: { | 195 | watch: { |
| 192 | value(newVal) { | 196 | value(newVal) { |
| 193 | const minDate = newVal[0] ? toDate(newVal[0]) : null; | 197 | const minDate = newVal[0] ? toDate(newVal[0]) : null; |
| 194 | const maxDate = newVal[1] ? toDate(newVal[1]) : null; | 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 | this.rangeState = { | 201 | this.rangeState = { |
| 198 | from: this.dates[0], | 202 | from: this.dates[0], |
| @@ -308,7 +312,7 @@ | @@ -308,7 +312,7 @@ | ||
| 308 | }, | 312 | }, |
| 309 | handleRangePick (val) { | 313 | handleRangePick (val) { |
| 310 | if (this.rangeState.selecting || this.currentView === 'time'){ | 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 | this.dates = [minDate, maxDate]; | 316 | this.dates = [minDate, maxDate]; |
| 313 | if (this.currentView === 'time'){ | 317 | if (this.currentView === 'time'){ |
| 314 | this.dates = val; | 318 | this.dates = val; |