Skip to content

Commit

Permalink
changeMonth() - fix behavior when self.currentMonth > 12 | resolves #565
Browse files Browse the repository at this point in the history
  • Loading branch information
chmln committed Jan 19, 2017
1 parent 4ba9343 commit f485018
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/flatpickr.js
Expand Up @@ -786,7 +786,7 @@ function Flatpickr(element, config) {

function handleYearChange(newYear) {
if (self.currentMonth < 0 || self.currentMonth > 11) {
self.currentYear += self.currentMonth % 11;
self.currentYear += (self.currentMonth > 11 ? 1 : -1);
self.currentMonth = (self.currentMonth + 12) % 12;

triggerEvent("YearChange");
Expand Down
5 changes: 5 additions & 0 deletions test/flatpickr.spec.js
Expand Up @@ -317,6 +317,11 @@ describe('flatpickr', () => {

fp.changeMonth(2);
expect(fp.currentMonth).toEqual(1);
expect(fp.currentYear).toEqual(2017);

fp.changeMonth(14);
expect(fp.currentYear).toEqual(2018);
expect(fp.currentMonth).toEqual(3);
});

it("destroy()", () => {
Expand Down

0 comments on commit f485018

Please sign in to comment.