Skip to content

Commit

Permalink
feat(date): helper function to format today
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen committed Oct 30, 2023
1 parent a06d2fc commit a070329
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 17 additions & 1 deletion apps/site/assets/ts/helpers/__tests__/date-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { addMinutes, addSeconds } from "date-fns";
import {
compareStringTimes,
formatRelativeTime,
formatToBostonTime
formatToBostonTime,
todayDateString
} from "../date";

describe("compareStringTimes", () => {
Expand Down Expand Up @@ -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();
});
});
7 changes: 7 additions & 0 deletions apps/site/assets/ts/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit a070329

Please sign in to comment.