Skip to content

Commit

Permalink
Show leading zeros on minutes in shared link expiration display
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Feb 6, 2025
1 parent 59350a9 commit ff1157a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/utils/date-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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", () => {
test("should format date correctly in long format", () => {
const result = formatDateLong("2023-11-14T13:14:00Z");
expect(result).toBe("November 14, 2023, 1:14pm");
});

test("should return empty string if date is undefined", () => {
const result = formatDateLong(undefined);
expect(result).toBe("");
});

test("should format time correctly with leading zeroes in minutes", () => {
const result = formatDateLong("2023-11-14T01:04:00Z");
expect(result).toBe("November 14, 2023, 1:04am");
});
});
2 changes: 1 addition & 1 deletion lib/utils/date-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function formatDateLong(date: string | undefined): string {
// Write a JS Date object to a string in the format like "November 14, 2023, 1:14pm"
return `${dateObj.toLocaleString("en-US", {
month: "long",
})} ${dateObj.getDate()}, ${dateObj.getFullYear()}, ${hour}:${dateObj.getMinutes()}${
})} ${dateObj.getDate()}, ${dateObj.getFullYear()}, ${hour}:${dateObj.getMinutes().toString().padStart(2, "0")}${
dateObj.getHours() > 12 ? "pm" : "am"
}`;
}

0 comments on commit ff1157a

Please # to comment.