-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: optional date arguments for functions (#58)
* isAfter, isBefore and diffMilliseconds now accept null/undefined to allow comparison with `now` * isBefore & isAfter doc change from now -> the current time changed isEqual to accept 1 optional date * all diff* functions now accept optional date arguments * all add* functions now support optional date argument. tests for them are combined with the ones for diff * same* now also support optional date arguments * nearestDay now accepts optional date input * *end, *start, yearDays, monthDays & dayOfYear now support optional date input * offset, removeOffset, tzDate, fill & createPartMap now support optional date input added 'the' before current * were missing * added isFuture & isPast * fix sameSecond inputDateA to Maybe * yearStart inputDate to maybe type * export isFuture & isPast * jsdoc change for MaybeDateInput to use `current time` instead of `now`
- Loading branch information
Showing
90 changed files
with
694 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": false | ||
"semi": false, | ||
"printWidth": 90, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { describe, expect, it } from "vitest" | ||
import { diffDays } from "../diffDays" | ||
import { addDay } from "../addDay" | ||
|
||
describe("differenceInDays", () => { | ||
it("difference is 3 days", () => { | ||
expect(diffDays("2024-04-10", "2024-04-07")).toBe(3) | ||
}) | ||
|
||
it("difference is 2 days", () => { | ||
expect( | ||
diffDays("2024-04-10T09:50:00.000Z", "2024-04-07T15:28:00.000Z") | ||
).toBe(2) | ||
expect(diffDays("2024-04-10T09:50:00.000Z", "2024-04-07T15:28:00.000Z")).toBe(2) | ||
}) | ||
|
||
it("difference is 3 days by using round", () => { | ||
expect( | ||
diffDays("2024-04-10T09:50:00.000Z", "2024-04-07T15:28:00.000Z", "round") | ||
).toBe(3) | ||
}) | ||
|
||
it("different should be -64 hours compared to the current time", () => { | ||
const compare = addDay(null, -28) | ||
expect(diffDays(compare)).toBe(-28) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { describe, expect, it } from "vitest" | ||
import { diffHours } from "../diffHours" | ||
import { addHour } from "../addHour" | ||
|
||
describe("differenceInHours", () => { | ||
it("difference is 5 hours", () => { | ||
expect( | ||
diffHours("2024-04-07T15:28:00.000Z", "2024-04-07T09:50:00.000Z") | ||
).toBe(5) | ||
expect(diffHours("2024-04-07T15:28:00.000Z", "2024-04-07T09:50:00.000Z")).toBe(5) | ||
}) | ||
|
||
it("different should be -64 hours compared to the current time", () => { | ||
const compare = addHour(null, 64) | ||
expect(diffHours(null, compare)).toBe(-64) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import { describe, it, expect } from "vitest" | ||
import { diffMilliseconds } from "../diffMilliseconds" | ||
|
||
describe("differenceInMilliseconds", () => { | ||
describe("diffMilliseconds", () => { | ||
it("difference is 257 milliseconds", () => { | ||
expect( | ||
diffMilliseconds("2024-04-07T09:10:48.257Z", "2024-04-07T09:10:48.000Z") | ||
).toBe(257) | ||
expect(diffMilliseconds("2024-04-07T09:10:48.257Z", "2024-04-07T09:10:48.000Z")).toBe( | ||
257 | ||
) | ||
}) | ||
|
||
it("should be 5000 milleseconds difference compared to the current time", () => { | ||
const now = new Date() | ||
now.setMilliseconds(5000) // because the date function sets ms to 0, the test needs to test with increments of 1000 | ||
expect(diffMilliseconds(now)).toBe(5000) | ||
}) | ||
|
||
it("should be -5000 milleseconds difference compared to the current time", () => { | ||
const now = new Date() | ||
now.setMilliseconds(5000) | ||
expect(diffMilliseconds(null, now)).toBe(-5000) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
import { describe, it, expect } from "vitest" | ||
import { diffMinutes } from "../diffMinutes" | ||
import { addMinute } from "../addMinute" | ||
|
||
describe("differenceInMinutes", () => { | ||
it("difference is 18 minutes", () => { | ||
expect( | ||
diffMinutes("2024-04-07T09:28:30.050Z", "2024-04-07T09:10:00.000Z") | ||
).toBe(18) | ||
expect(diffMinutes("2024-04-07T09:28:30.050Z", "2024-04-07T09:10:00.000Z")).toBe(18) | ||
}) | ||
it("difference is 19 minutes by using ceil", () => { | ||
expect( | ||
diffMinutes( | ||
"2024-04-07T09:28:01.050Z", | ||
"2024-04-07T09:10:00.000Z", | ||
"ceil" | ||
) | ||
diffMinutes("2024-04-07T09:28:01.050Z", "2024-04-07T09:10:00.000Z", "ceil") | ||
).toBe(19) | ||
}) | ||
|
||
it("different should be 23 minutes compared to the current time", () => { | ||
const compare = addMinute(null, 23) | ||
expect(diffMinutes(compare)).toBe(23) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { describe, it, expect } from "vitest" | ||
import { diffSeconds } from "../diffSeconds" | ||
import { addSecond } from "../addSecond" | ||
|
||
describe("differenceInSeconds", () => { | ||
it("difference is 28 seconds", () => { | ||
expect( | ||
diffSeconds("2024-04-07T09:10:28.900Z", "2024-04-07T09:10:00.000Z") | ||
).toBe(28) | ||
expect(diffSeconds("2024-04-07T09:10:28.900Z", "2024-04-07T09:10:00.000Z")).toBe(28) | ||
}) | ||
|
||
it("different should be 50 seconds compared to the current time", () => { | ||
const compare = addSecond(null, 50) | ||
expect(diffSeconds(compare)).toBe(50) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.