Fix sort of date arrays
This commit is contained in:
parent
73a34dfab5
commit
5092777d17
1 changed files with 7 additions and 3 deletions
|
@ -127,6 +127,10 @@
|
||||||
const prefixCls = 'ivu-picker-panel';
|
const prefixCls = 'ivu-picker-panel';
|
||||||
const datePrefixCls = 'ivu-date-picker';
|
const datePrefixCls = 'ivu-date-picker';
|
||||||
|
|
||||||
|
const dateSorter = (a, b) => {
|
||||||
|
if (!a || !b) return 0;
|
||||||
|
return a.getTime() - b.getTime();
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'RangeDatePickerPanel',
|
name: 'RangeDatePickerPanel',
|
||||||
|
@ -185,14 +189,14 @@
|
||||||
return {
|
return {
|
||||||
left: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'left'),
|
left: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'left'),
|
||||||
right: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'right'),
|
right: this.leftPickerTable === tableType ? this.handleRangePick : this.handlePreSelection.bind(this, 'right'),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value(newVal) {
|
value(newVal) {
|
||||||
const minDate = newVal[0] ? toDate(newVal[0]) : null;
|
const minDate = newVal[0] ? toDate(newVal[0]) : null;
|
||||||
const maxDate = newVal[1] ? toDate(newVal[1]) : null;
|
const maxDate = newVal[1] ? toDate(newVal[1]) : null;
|
||||||
this.dates = [minDate, maxDate].sort();
|
this.dates = [minDate, maxDate].sort(dateSorter);
|
||||||
|
|
||||||
this.rangeState = {
|
this.rangeState = {
|
||||||
from: this.dates[0],
|
from: this.dates[0],
|
||||||
|
@ -308,7 +312,7 @@
|
||||||
},
|
},
|
||||||
handleRangePick (val) {
|
handleRangePick (val) {
|
||||||
if (this.rangeState.selecting || this.currentView === 'time'){
|
if (this.rangeState.selecting || this.currentView === 'time'){
|
||||||
const [minDate, maxDate] = [this.rangeState.from, val].sort((a, b) => a - b);
|
const [minDate, maxDate] = [this.rangeState.from, val].sort(dateSorter);
|
||||||
this.dates = [minDate, maxDate];
|
this.dates = [minDate, maxDate];
|
||||||
if (this.currentView === 'time'){
|
if (this.currentView === 'time'){
|
||||||
this.dates = val;
|
this.dates = val;
|
||||||
|
|
Loading…
Add table
Reference in a new issue