-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
toDisplayedDate with object params, showGMT, tests
- Loading branch information
1 parent
a49714f
commit 4b01fc2
Showing
9 changed files
with
124 additions
and
51 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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
process.env.TZ = "Europe/Paris"; | ||
|
||
module.exports = { | ||
testEnvironment: "node", | ||
}; |
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,13 +1,40 @@ | ||
import { toDateString } from "./date"; | ||
import { parseISO } from "date-fns"; | ||
import { toDateString, toDisplayedDate } from "./date"; | ||
|
||
describe("Date utils tests", () => { | ||
describe("Date utils tests - toDateString", () => { | ||
it("should format a valid date", () => { | ||
const date = new Date("2021-01-01"); | ||
const date = parseISO("2021-01-01"); | ||
expect(toDateString(date)).toBe("2021-01-01"); | ||
}); | ||
|
||
it("can't format an empty string", () => { | ||
const date = new Date(""); | ||
const date = parseISO(""); | ||
expect(() => toDateString(date)).toThrow("Invalid time value"); | ||
}); | ||
}); | ||
|
||
describe("Date utils tests - toDisplayedDate", () => { | ||
it("should format a valid date", () => { | ||
const date = parseISO("2024-01-29 11:36:50.274+00"); | ||
expect(toDisplayedDate({ date })).toBe("29/01/2024"); | ||
}); | ||
|
||
it("should format a valid date with hours", () => { | ||
const date = parseISO("2024-01-29 11:36:50.274+00"); | ||
expect(toDisplayedDate({ date, withHours: true })).toBe( | ||
"29/01/2024 à 12h36", | ||
); | ||
}); | ||
|
||
it("should format a valid date with hours (with GMT mention)", () => { | ||
const date = parseISO("2024-01-29 11:36:50.274+00"); | ||
expect(toDisplayedDate({ date, withHours: true, showGMT: true })).toBe( | ||
"29/01/2024 à 12h36 (heure de Paris GMT+1)", | ||
); | ||
}); | ||
|
||
it("can't format an empty string", () => { | ||
const date = new Date(""); | ||
expect(() => toDisplayedDate({ date })).toThrow("Invalid time value"); | ||
}); | ||
}); |