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);