diff --git a/apps/site/assets/ts/helpers/__tests__/date-test.ts b/apps/site/assets/ts/helpers/__tests__/date-test.ts index 69200fe5d6..1abfc29787 100644 --- a/apps/site/assets/ts/helpers/__tests__/date-test.ts +++ b/apps/site/assets/ts/helpers/__tests__/date-test.ts @@ -2,7 +2,8 @@ import { addMinutes, addSeconds } from "date-fns"; import { compareStringTimes, formatRelativeTime, - formatToBostonTime + formatToBostonTime, + todayDateString } from "../date"; describe("compareStringTimes", () => { @@ -44,3 +45,18 @@ describe("formatRelativeTime", () => { expect(formatRelativeTime(laterDate, baseDate)).toBe("11:10 AM"); }); }); + +describe("todayDateString", () => { + beforeAll(() => { + jest.useFakeTimers(); + jest.setSystemTime(new Date("2012-10-10T09:00:00.000+04:00")); + }); + + it("returns formatted today date", () => { + expect(todayDateString()).toEqual("Oct 10"); + }); + + afterAll(() => { + jest.useRealTimers(); + }); +}); diff --git a/apps/site/assets/ts/helpers/date.ts b/apps/site/assets/ts/helpers/date.ts index cc2927e438..6a6406eaf5 100644 --- a/apps/site/assets/ts/helpers/date.ts +++ b/apps/site/assets/ts/helpers/date.ts @@ -119,4 +119,11 @@ export const isSameDayInBoston = ( return date1InBoston === date2InBoston; }; +export const todayDateString = (): string => + new Date().toLocaleDateString("en-US", { + month: "short", + day: "numeric", + timeZone: BOSTON_TIMEZONE + }); + export default formattedDate;