-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show leading zeros on minutes in shared link expiration display
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { formatDate, formatDateLong } from "./date-helpers"; | ||
|
||
describe("formatDate", () => { | ||
test("should format date correctly", () => { | ||
const result = formatDate("2023-11-14T13:14:00Z"); | ||
expect(result).toBe("2023-10-2"); // Note: getMonth() is zero-based, getDay() returns day of the week | ||
}); | ||
|
||
test("should handle invalid date", () => { | ||
const result = formatDate("invalid-date"); | ||
expect(result).toBe("NaN-NaN-NaN"); | ||
}); | ||
}); | ||
|
||
describe("formatDateLong", () => { | ||
it("should return a properly formatted date string for a valid date input", () => { | ||
const inputDate = "2023-11-14T13:14:00Z"; // UTC time | ||
const dateObj = new Date(inputDate); | ||
|
||
// Dynamically generate the expected output based on the local time zone | ||
const expectedOutput = `${dateObj.toLocaleString("en-US", { month: "long" })} ${dateObj.getDate()}, ${dateObj.getFullYear()}, ${ | ||
dateObj.getHours() > 12 ? dateObj.getHours() - 12 : dateObj.getHours() | ||
}:${dateObj.getMinutes().toString().padStart(2, "0")}${ | ||
dateObj.getHours() >= 12 ? "pm" : "am" | ||
}`; | ||
|
||
expect(formatDateLong(inputDate)).toBe(expectedOutput); | ||
}); | ||
|
||
it("should return an empty string for an undefined input", () => { | ||
expect(formatDateLong(undefined)).toBe(""); | ||
}); | ||
|
||
it("should handle midnight correctly", () => { | ||
const inputDate = "2023-11-14T00:00:00Z"; // UTC time | ||
const dateObj = new Date(inputDate); | ||
|
||
const expectedOutput = `${dateObj.toLocaleString("en-US", { month: "long" })} ${dateObj.getDate()}, ${dateObj.getFullYear()}, ${ | ||
dateObj.getHours() > 12 ? dateObj.getHours() - 12 : dateObj.getHours() | ||
}:${dateObj.getMinutes().toString().padStart(2, "0")}${ | ||
dateObj.getHours() >= 12 ? "pm" : "am" | ||
}`; | ||
|
||
expect(formatDateLong(inputDate)).toBe(expectedOutput); | ||
}); | ||
|
||
it("should handle noon correctly", () => { | ||
const inputDate = "2023-11-14T12:00:00Z"; // UTC time | ||
const dateObj = new Date(inputDate); | ||
|
||
const expectedOutput = `${dateObj.toLocaleString("en-US", { month: "long" })} ${dateObj.getDate()}, ${dateObj.getFullYear()}, ${ | ||
dateObj.getHours() > 12 ? dateObj.getHours() - 12 : dateObj.getHours() | ||
}:${dateObj.getMinutes().toString().padStart(2, "0")}${ | ||
dateObj.getHours() >= 12 ? "pm" : "am" | ||
}`; | ||
|
||
expect(formatDateLong(inputDate)).toBe(expectedOutput); | ||
}); | ||
|
||
it("should pad minutes correctly", () => { | ||
const inputDate = "2023-11-14T13:04:00Z"; // UTC time | ||
const dateObj = new Date(inputDate); | ||
|
||
const expectedOutput = `${dateObj.toLocaleString("en-US", { month: "long" })} ${dateObj.getDate()}, ${dateObj.getFullYear()}, ${ | ||
dateObj.getHours() > 12 ? dateObj.getHours() - 12 : dateObj.getHours() | ||
}:${dateObj.getMinutes().toString().padStart(2, "0")}${ | ||
dateObj.getHours() >= 12 ? "pm" : "am" | ||
}`; | ||
|
||
expect(formatDateLong(inputDate)).toBe(expectedOutput); | ||
}); | ||
}); |
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