From 86f52f89c5b21f92f9e2399d12044a64a0c90bf1 Mon Sep 17 00:00:00 2001 From: shyam Date: Wed, 14 Oct 2020 01:24:43 +0530 Subject: [PATCH] Fix #744, Setting month and year before setting date solves the issue. Include test case for #744. --- src/DateTime.js | 10 +++++----- test/tests.spec.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/DateTime.js b/src/DateTime.js index 88a72bfb0..4d6dbd475 100644 --- a/src/DateTime.js +++ b/src/DateTime.js @@ -338,17 +338,17 @@ export default class Datetime extends React.Component { let updateOnView = this.getUpdateOn( this.getFormat('date') ); let viewDate = this.state.viewDate.clone(); - // Set the value into day/month/year - viewDate[ this.viewToMethod[currentView] ]( - parseInt( e.target.getAttribute('data-value'), 10 ) - ); - // Need to set month and year will for days view (prev/next month) if ( currentView === 'days' ) { viewDate.month( parseInt( e.target.getAttribute('data-month'), 10 ) ); viewDate.year( parseInt( e.target.getAttribute('data-year'), 10 ) ); } + // Set the value into day/month/year + viewDate[ this.viewToMethod[currentView] ]( + parseInt( e.target.getAttribute('data-value'), 10 ) + ); + let update = {viewDate: viewDate}; if ( currentView === updateOnView ) { update.selectedDate = viewDate.clone(); diff --git a/test/tests.spec.js b/test/tests.spec.js index 498afa2ec..138b58c68 100644 --- a/test/tests.spec.js +++ b/test/tests.spec.js @@ -248,6 +248,18 @@ describe('Datetime', () => { expect(component.find('.rdtSwitch').text()).toEqual('December 2018'); }); + it('click on 31st of the prev month (#744)', () => { + const component = utils.createDatetime({ + initialViewMode: 'days', + initialValue: new Date(2020, 8, 1) + }); + + utils.openDatepicker(component); + utils.clickClassItem(component, '.rdtOld', 1); + + expect(utils.getInputValue(component)).toEqual('08/31/2020 12:00 AM'); + }); + it('sets CSS class on selected item (day)', () => { const component = utils.createDatetime({ initialViewMode: 'days' }); utils.openDatepicker(component);