Skip to content

Commit 332915b

Browse files
authored
Merge pull request #251 from sebgroup/develop
next release
2 parents ad1e7d6 + 54623ef commit 332915b

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/isDateAfter/isDateAfter.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe("Util: isDateAfter", () => {
2222
},
2323
{
2424
statement: "Should return true if date1 is after date2",
25-
date1: new Date("2019-12-11"),
25+
date1: new Date("2019-12-01"),
2626
date2: new Date("2019-11-11"),
2727
result: true,
2828
},
@@ -39,7 +39,8 @@ describe("Util: isDateAfter", () => {
3939
result: false,
4040
},
4141
{
42-
statement: "Should ignore the time and return false if the two dates are equal",
42+
statement:
43+
"Should ignore the time and return false if the two dates are equal",
4344
date1: new Date("2019-11-11 23:00:00"),
4445
date2: new Date("2019-11-11 11:00:00"),
4546
result: false,

src/isDateAfter/isDateAfter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { isValidDate } from "../isValidDate";
77
* @returns {boolean} True if date `a` comes after than date `b`
88
*/
99
export function isDateAfter(a: Date, b: Date): boolean {
10-
if (!isValidDate(a) || !isValidDate(b)) {
11-
return a > b;
12-
} else {
10+
if (isValidDate(a) && isValidDate(b)) {
1311
return a.setHours(0, 0, 0).valueOf() > b.setHours(0, 0, 0).valueOf();
1412
}
13+
14+
return a > b;
1515
}

src/isDateBefore/isDateBefore.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe("Util: isDateBefore", () => {
2828
},
2929
{
3030
statement: "Should return false if date1 is not before date2",
31-
date1: new Date("2020-12-28"),
32-
date2: new Date("2020-12-25"),
31+
date1: new Date("2023-03-04"),
32+
date2: new Date("2023-02-15"),
3333
result: false,
3434
},
3535
{

src/isDateBefore/isDateBefore.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ import { isValidDate } from "../isValidDate";
77
* @returns {boolean} True if date `a` comes before date `b`
88
*/
99
export function isDateBefore(a: Date, b: Date): boolean {
10-
if (!isValidDate(a) || !isValidDate(b)) {
11-
return a < b;
12-
} else {
13-
return (
14-
a.getFullYear() < b.getFullYear() ||
15-
a.getMonth() < b.getMonth() ||
16-
a.getDate() < b.getDate()
17-
);
10+
if (isValidDate(a) && isValidDate(b)) {
11+
return a.setHours(0, 0, 0).valueOf() < b.setHours(0, 0, 0).valueOf();
1812
}
13+
14+
return a < b;
1915
}

0 commit comments

Comments
 (0)