diff --git a/components/Modals/CreateCalendarEvent.tsx b/components/Modals/CreateCalendarEvent.tsx index 747420b..512f328 100644 --- a/components/Modals/CreateCalendarEvent.tsx +++ b/components/Modals/CreateCalendarEvent.tsx @@ -124,7 +124,6 @@ export default function CreateCalendarEventModal() { if (imageUrl) { tags.push(["image", imageUrl]); } - console.log("Adding ", tags); const preEvent = { content: description, pubkey: currentUser.pubkey, @@ -153,7 +152,7 @@ export default function CreateCalendarEventModal() { toast.error("An error occured"); } } catch (err) { - console.log("err", err); + console.log("error creating event", err); } finally { setIsLoading(false); } diff --git a/lib/utils/dates.ts b/lib/utils/dates.ts index acb8544..d00a0ec 100644 --- a/lib/utils/dates.ts +++ b/lib/utils/dates.ts @@ -124,6 +124,7 @@ export function convertToTimezone(inputDate: Date, targetTimezone: string) { dayjs.extend(utc); dayjs.extend(timezone); let hours = inputDate.getHours().toString(); + if (hours.length === 1) { hours = "0" + hours; } @@ -131,13 +132,21 @@ export function convertToTimezone(inputDate: Date, targetTimezone: string) { if (minutes.length === 1) { minutes = "0" + minutes; } + let day = inputDate.getDate().toString(); + if (day.length === 1) { + day = "0" + day; + } + let month = (inputDate.getMonth() + 1).toString(); + if (month.length === 1) { + month = "0" + month; + } - const dateString = `${inputDate.getFullYear()}-${ - inputDate.getMonth() + 1 - }-${inputDate.getDate()}T${hours}:${minutes}:00.000Z`; + const dateString = `${inputDate.getFullYear()}-${month}-${day}T${hours}:${minutes}:00.000Z`; // Get plain date w/o timezones const initialDate = new Date(dateString); + const plainString = initialDate.toISOString().split(".")[0] as string; + const plain = dayjs.tz(plainString, targetTimezone); return plain.toDate(); }