Skip to content

Commit

Permalink
Fix timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunkomath committed Jan 9, 2025
1 parent 405f139 commit 981b524
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
18 changes: 4 additions & 14 deletions app/(api)/api/calendar/[ownerId]/[projectId]/route.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { calendarEvent, project, task, taskList } from "@/drizzle/schema";
import { getUser } from "@/lib/ops/auth";
import { getDatabaseForOwner } from "@/lib/utils/useDatabase";
import { getVtimezoneComponent } from "@touch4it/ical-timezones";
import dayjs from "dayjs";
import tz from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { and, desc, eq, lte } from "drizzle-orm";
import ical, { ICalCalendarMethod } from "ical-generator";
import type { NextRequest } from "next/server";

dayjs.extend(utc);
dayjs.extend(tz);

export const revalidate = 0;
export const dynamic = "force-dynamic";

Expand Down Expand Up @@ -67,20 +60,17 @@ export async function GET(
const calendar = ical({
name: projectDetails.name,
method: ICalCalendarMethod.PUBLISH,
timezone: timezone
? { name: timezone, generator: getVtimezoneComponent }
: null,
});

for (const event of events) {
calendar.createEvent({
id: event.id,
start: timezone
? dayjs.utc(event.start).tz(timezone).format("YYYY-MM-DDTHH:mm:ssZ")
? event.start.toLocaleString("en-US", { timeZone: timezone })
: event.start,
end: event.end
? timezone
? dayjs.utc(event.end).tz(timezone).format("YYYY-MM-DDTHH:mm:ssZ")
? event.end.toLocaleString("en-US", { timeZone: timezone })
: event.end
: null,
summary: event.name,
Expand All @@ -105,10 +95,10 @@ export async function GET(
calendar.createEvent({
id: task.id,
start: timezone
? dayjs.utc(task.dueDate).tz(timezone).format("YYYY-MM-DDTHH:mm:ssZ")
? task.dueDate.toLocaleString("en-US", { timeZone: timezone })
: task.dueDate,
end: timezone
? dayjs.utc(task.dueDate).tz(timezone).format("YYYY-MM-DDTHH:mm:ssZ")
? task.dueDate.toLocaleString("en-US", { timeZone: timezone })
: task.dueDate,
summary: `[${tasklist.name}] ${task.name}`,
description: task.description,
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@touch4it/ical-timezones": "^1.9.0",
"autoprefixer": "10.4.14",
"better-sqlite3": "^11.7.0",
"class-variance-authority": "^0.6.1",
Expand All @@ -42,7 +41,7 @@
"drizzle-orm": "^0.38.2",
"easymde": "^2.18.0",
"eslint-config-next": "15.1.0",
"ical-generator": "^8.0.0",
"ical-generator": "^8.0.1",
"lucide-react": "^0.244.0",
"mime-types": "^2.1.35",
"next": "15.1.0",
Expand Down
16 changes: 7 additions & 9 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 981b524

Please sign in to comment.