Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions test/tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down