Commit 147f23a50ba5d2b648c9867da3280c1b5800d9d4

Authored by Aresn
Committed by GitHub
2 parents 61666e4e 226b084c

Merge pull request #4255 from SergioCrisostomo/fix-3773

Correct month last day when changing date panel dates
Showing 1 changed file with 14 additions and 5 deletions   Show diff stats
src/components/date-picker/panel/Date/date-range.vue
@@ -260,8 +260,8 @@ @@ -260,8 +260,8 @@
260 }, 260 },
261 setPanelDates(leftPanelDate){ 261 setPanelDates(leftPanelDate){
262 this.leftPanelDate = leftPanelDate; 262 this.leftPanelDate = leftPanelDate;
263 - const rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, leftPanelDate.getDate());  
264 - this.rightPanelDate = this.splitPanels ? new Date(Math.max(this.dates[1], rightPanelDate)) : rightPanelDate; 263 + const rightPanelDate = new Date(leftPanelDate.getFullYear(), leftPanelDate.getMonth() + 1, 1);
  264 + this.rightPanelDate = this.splitPanels ? new Date(Math.max(this.dates[1].getTime(), rightPanelDate.getTime())) : rightPanelDate;
265 }, 265 },
266 panelLabelConfig (direction) { 266 panelLabelConfig (direction) {
267 const locale = this.t('i.locale'); 267 const locale = this.t('i.locale');
@@ -312,9 +312,18 @@ @@ -312,9 +312,18 @@
312 } else { 312 } else {
313 // keep the panels together 313 // keep the panels together
314 const otherPanel = panel === 'left' ? 'right' : 'left'; 314 const otherPanel = panel === 'left' ? 'right' : 'left';
315 - const otherCurrent = new Date(this[`${otherPanel}PanelDate`]);  
316 - otherCurrent[`set${type}`](otherCurrent[`get${type}`]() + increment);  
317 - this[`${otherPanel}PanelDate`] = otherCurrent; 315 + const currentDate = this[`${otherPanel}PanelDate`];
  316 + const temp = new Date(currentDate);
  317 +
  318 + if (type === 'Month') {
  319 + const nextMonthLastDate = new Date(
  320 + temp.getFullYear(), temp.getMonth() + increment + 1, 0
  321 + ).getDate();
  322 + temp.setDate(Math.min(nextMonthLastDate, temp.getDate()));
  323 + }
  324 +
  325 + temp[`set${type}`](temp[`get${type}`]() + increment);
  326 + this[`${otherPanel}PanelDate`] = temp;
318 } 327 }
319 }, 328 },
320 showYearPicker (panel) { 329 showYearPicker (panel) {