fixed date issue on safari

This commit is contained in:
zmeyer44 2023-10-24 17:58:18 -04:00
parent 7f06b68bce
commit a3c4f55388
3 changed files with 22 additions and 3 deletions

View File

@ -78,15 +78,19 @@ export default function CreateCalendarEventModal() {
async function handleSubmit() {
console.log("CALLED", ndk, currentUser);
if (!ndk || !currentUser) return;
if (!ndk || !currentUser) {
alert("MISSING");
return;
}
setIsLoading(true);
if (!title) {
setError("Please add a title");
return;
}
try {
const random = randomId();
const tags: string[][] = [
["d", random],
["name", title],
@ -95,6 +99,7 @@ export default function CreateCalendarEventModal() {
["end", toUnix(convertToTimezone(endDate, timezone)).toString()],
["start_tzid", timezone],
];
if (location) {
tags.push([
"location",
@ -110,6 +115,7 @@ export default function CreateCalendarEventModal() {
]);
tags.push(["g", location.geohash]);
}
if (imageUrl) {
tags.push(["image", imageUrl]);
}
@ -121,6 +127,7 @@ export default function CreateCalendarEventModal() {
tags: tags,
kind: 31923,
};
const event = await createEvent(ndk, preEvent);
if (event) {
toast.success("Event Created!");

View File

@ -27,6 +27,7 @@ export async function createEvent(
) {
log("func", "createEvent");
try {
alert("at pub");
const pubkey = ndk.activeUser?.pubkey;
if (!pubkey) {
throw new Error("No public key provided!");

View File

@ -138,9 +138,20 @@ 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;
}
let minutes = inputDate.getMinutes().toString();
if (minutes.length === 1) {
minutes = "0" + minutes;
}
const dateString = `${inputDate.getFullYear()}-${
inputDate.getMonth() + 1
}-${inputDate.getDate()}T${hours}:${minutes}:00.000Z`;
// Get plain date w/o timezones
const initialDate = new Date(inputDate + "Z");
const initialDate = new Date(dateString);
const plainString = initialDate.toISOString().split(".")[0] as string;
const plain = dayjs.tz(plainString, targetTimezone);
return plain.toDate();