Skip to content

Commit

Permalink
Merge pull request #96 from JKillian/toMonth
Browse files Browse the repository at this point in the history
Fix bug where endpoint months could not be shown
  • Loading branch information
gpbl committed Nov 20, 2015
2 parents 250b642 + 270fdbc commit 89e1df1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export default class DayPicker extends Component {

allowMonth(d) {
const { fromMonth, toMonth } = this.props;
if ((fromMonth && Helpers.getMonthsDiff(fromMonth, d) <= 0) ||
(toMonth && Helpers.getMonthsDiff(toMonth, d) >= 0)) {
if ((fromMonth && Helpers.getMonthsDiff(fromMonth, d) < 0) ||
(toMonth && Helpers.getMonthsDiff(toMonth, d) > 0)) {
return false;
}
return true;
Expand Down
19 changes: 19 additions & 0 deletions test/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,25 @@ describe("DayPicker", () => {
expect(dayPickerEl.state.currentMonth.getFullYear()).to.equal(2015);
});

it("can show the first allowed month, `fromMonth`", () => {
const dayPickerEl = TestUtils.renderIntoDocument(
<DayPicker initialMonth={new Date(2015, 6)} fromMonth={new Date(2015, 4)} />
);
dayPickerEl.showMonth(new Date(2015, 4));

expect(dayPickerEl.state.currentMonth.getMonth()).to.equal(4);
expect(dayPickerEl.state.currentMonth.getFullYear()).to.equal(2015);
});

it("can show the last allowed month, `toMonth`", () => {
const dayPickerEl = TestUtils.renderIntoDocument(
<DayPicker initialMonth={new Date(2015, 6)} toMonth={new Date(2015, 8)} />
);
dayPickerEl.showMonth(new Date(2015, 8));

expect(dayPickerEl.state.currentMonth.getMonth()).to.equal(8);
expect(dayPickerEl.state.currentMonth.getFullYear()).to.equal(2015);
});
});

it("displays a modified state upon changing initialMonth prop", (done) => {
Expand Down

0 comments on commit 89e1df1

Please sign in to comment.