Skip to content

Commit

Permalink
Fix keyboard bug selecting last day on calendar (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlurena authored and martijnrusschen committed Aug 26, 2019
1 parent 59d5706 commit 607bf2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import startOfDay from "date-fns/startOfDay";
import startOfWeek from "date-fns/startOfWeek";
import startOfMonth from "date-fns/startOfMonth";
import startOfYear from "date-fns/startOfYear";
import endOfDay from "date-fns/endOfDay";
import endOfWeek from "date-fns/endOfWeek";
import endOfMonth from "date-fns/endOfMonth";
import dfIsEqual from "date-fns/isEqual";
Expand Down Expand Up @@ -273,8 +274,11 @@ export function isEqual(date1, date2) {

export function isDayInRange(day, startDate, endDate) {
let valid;
const start = startOfDay(startDate);
const end = endOfDay(endDate);

try {
valid = isWithinInterval(day, { start: startDate, end: endDate });
valid = isWithinInterval(day, { start, end });
} catch (err) {
valid = false;
}
Expand Down
32 changes: 23 additions & 9 deletions test/date_utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,23 +431,37 @@ describe("date_utils", function() {

describe("isDayInRange", () => {
it("should tell if day is in range", () => {
const day = newDate("2016-02-15");
const startDate = newDate("2016-02-01");
const endDate = newDate("2016-03-15");
const day = newDate("2016-02-15 09:40");
const startDate = newDate("2016-02-01 09:40");
const endDate = newDate("2016-03-15 08:40");
expect(isDayInRange(day, startDate, endDate)).to.be.true;
});

it("should tell if day is in range, max bound test", () => {
const day = newDate("2016-03-15 09:40");
const startDate = newDate("2016-02-01 09:40");
const endDate = newDate("2016-03-15 08:40");
expect(isDayInRange(day, startDate, endDate)).to.be.true;
});

it("should tell if day is in range, min bound test", () => {
const day = newDate("2016-02-01 08:40");
const startDate = newDate("2016-02-01 09:40");
const endDate = newDate("2016-03-15 08:40");
expect(isDayInRange(day, startDate, endDate)).to.be.true;
});

it("should tell if day is not in range", () => {
const day = newDate("2016-07-15");
const startDate = newDate("2016-02-15");
const endDate = newDate("2016-03-15");
const day = newDate("2016-07-15 09:40");
const startDate = newDate("2016-02-15 09:40");
const endDate = newDate("2016-03-15 08:40");
expect(isDayInRange(day, startDate, endDate)).to.be.false;
});

it("should not throw exception if end date is before start date", () => {
const day = newDate("2016-02-01");
const startDate = newDate("2016-02-15");
const endDate = newDate("2016-01-15");
const day = newDate("2016-02-01 09:40");
const startDate = newDate("2016-02-15 09:40");
const endDate = newDate("2016-01-15 08:40");
expect(isDayInRange(day, startDate, endDate)).to.be.false;
});
});
Expand Down

0 comments on commit 607bf2c

Please sign in to comment.