Skip to content

Commit

Permalink
fix: group events by America/Los_Angeles day
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderl19 committed Oct 31, 2023
1 parent ef43685 commit e7d1c15
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/react": "18.2.20",
"@types/react-dom": "^18.2.0",
"bootstrap": "^5.3.1",
"dayjs": "^1.11.10",
"eslint": "8.46.0",
"eslint-config-next": "^13.4.1",
"framer-motion": "^10.16.4",
Expand Down
8 changes: 8 additions & 0 deletions apps/site/src/lib/day.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";

dayjs.extend(utc);
dayjs.extend(timezone);

export default dayjs;
11 changes: 7 additions & 4 deletions apps/site/src/views/Schedule/getSchedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod";
import { cache } from "react";
import { client } from "@/lib/sanity/client";
import { SanityDocument } from "@/lib/sanity/types";
import dayjs from "@/lib/day";

const Events = z.array(
SanityDocument.extend({
Expand Down Expand Up @@ -49,10 +50,12 @@ export const getSchedule = cache(async () => {
const eventsByDay = new Map<string, z.infer<typeof Events>>();

events.forEach((event) => {
eventsByDay.set(event.startTime.toLocaleDateString(), [
...(eventsByDay.get(event.startTime.toLocaleDateString()) ?? []),
event,
]);
const date = dayjs
.utc(event.startTime)
.tz("America/Los_Angeles")
.format("YYYY-MM-DD");

eventsByDay.set(date, [...(eventsByDay.get(date) ?? []), event]);
});

return Array.from(eventsByDay.values());
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7d1c15

Please sign in to comment.