Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #744, Setting month and year before setting date solves the issue #745

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/DateTime.js
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
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