Skip to content

Commit

Permalink
[datetime] [bugfix] render the correct month when DRP singleMonthOnly…
Browse files Browse the repository at this point in the history
… is enabled (#3504)
  • Loading branch information
David authored and adidahiya committed May 16, 2019
1 parent 2eddfde commit ad402b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/datetime/src/dateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class DateRangePicker extends AbstractPureComponent<IDateRangePickerProps
// subtracting one avoids that weird, wraparound state (#289).
const initialMonthEqualsMinMonth = DateUtils.areSameMonth(initialMonth, props.minDate);
const initalMonthEqualsMaxMonth = DateUtils.areSameMonth(initialMonth, props.maxDate);
if (!initialMonthEqualsMinMonth && initalMonthEqualsMaxMonth) {
if (!props.singleMonthOnly && !initialMonthEqualsMinMonth && initalMonthEqualsMaxMonth) {
initialMonth.setMonth(initialMonth.getMonth() - 1);
}

Expand Down
7 changes: 7 additions & 0 deletions packages/datetime/test/dateRangePickerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ describe("<DateRangePicker>", () => {
render({ maxDate, minDate, value }).left.assertMonthYear(Months.APRIL, 2007);
});

it("has correct initial month on singleMonthOnly and maxDate == initialMonth", () => {
const maxDate = new Date(2019, Months.MAY, 6);
const minDate = new Date(2019, Months.MARCH, 3);
const initialMonth = maxDate;
render({ singleMonthOnly: true, maxDate, minDate, initialMonth }).left.assertMonthYear(Months.MAY, 2019);
});

it("is (endDate - 1 month) if only endDate is set", () => {
const value = [null, new Date(2007, Months.APRIL, 4)] as DateRange;
render({ value }).left.assertMonthYear(Months.MARCH, 2007);
Expand Down

1 comment on commit ad402b6

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[datetime] [bugfix] render the correct month when DRP singleMonthOnly is enabled (#3504)

Previews: documentation | landing | table

Please sign in to comment.