Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 41 additions & 26 deletions features/calendar/events.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
import { SignUpSheetType } from "@/features/calendar/signup_sheets";
import { AttendStatus } from "@/features/calendar/statuses";
import { EventType } from "@/features/calendar/types";
import { ExposedUser, ExposedUserModel } from "@/features/people";
import * as AdamRMS from "@/lib/adamrms";
import { prisma } from "@/lib/db";
import {
Attendee,
Crew,
Event,
Position,
Prisma,
RecurringAttendee,
RecurringEvent,
SignupSheet,
User,
type Attendee,
type Crew,
type Event,
type Position,
type Prisma,
type RecurringAttendee,
type RecurringEvent,
type SignupSheet,
type User,
} from "@prisma/client";
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { produce } from "immer";
import "server-only";
import { z } from "zod";

import { type SignUpSheetType } from "@/features/calendar/signup_sheets";
import { type AttendStatus } from "@/features/calendar/statuses";
import { type EventType } from "@/features/calendar/types";
import { type ExposedUser, ExposedUserModel } from "@/features/people";
import * as AdamRMS from "@/lib/adamrms";
import { prisma } from "@/lib/db";
import "server-only";
import { env } from "@/lib/env";

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

export interface EventAttendee {
event_id: number;
user_id: number;
Expand Down Expand Up @@ -434,19 +441,27 @@ export async function createRecurringEvent(
): Promise<EventObjectType> {
const recurringEvent = await prisma.recurringEvent.create();

const eventStartDate = dayjs(event.start_date).utc(true);
const hourDiff = dayjs(event.start_date).diff(
dayjs(event.start_date).tz(env.TZ_OVERRIDE, true),
"hours",
);

console.log(hourDiff);

const eventStartDate = dayjs(event.start_date).utc();

for (const recurring_date of recurringDates) {
const recurDate = dayjs(recurring_date);
const recurStartDate = dayjs(event.start_date).add(
Math.ceil(recurDate.diff(eventStartDate, "days", true)),
"days",
);

const recurEndDate = dayjs(event.end_date).add(
Math.ceil(recurDate.diff(eventStartDate, "days", true)),
"days",
);
const recurStartDate = dayjs(event.start_date)
.add(Math.ceil(recurDate.diff(eventStartDate, "days", true)), "days")
.add(hourDiff, "hours")
.tz(env.TZ_OVERRIDE, true);

console.log(recurStartDate.toISOString());

const recurEndDate = dayjs(event.end_date)
.add(Math.ceil(recurDate.diff(eventStartDate, "days", true)), "days")
.add(hourDiff, "hours");

await prisma.event.create({
data: {
Expand Down
1 change: 1 addition & 0 deletions lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const envSchema = z.object({
required_error:
"Try generating a random secret with `openssl rand -base64 32`",
}),
TZ_OVERRIDE: z.string().default("Europe/London"),
SLACK_ENABLED: z.enum(["true", "false"]).default("false"),
SLACK_BOT_TOKEN: slackEnvType,
SLACK_APP_TOKEN: slackEnvType,
Expand Down