fixed date issue on safari
This commit is contained in:
parent
7f06b68bce
commit
a3c4f55388
@ -78,15 +78,19 @@ export default function CreateCalendarEventModal() {
|
|||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
console.log("CALLED", ndk, currentUser);
|
console.log("CALLED", ndk, currentUser);
|
||||||
if (!ndk || !currentUser) return;
|
if (!ndk || !currentUser) {
|
||||||
|
alert("MISSING");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
if (!title) {
|
if (!title) {
|
||||||
setError("Please add a title");
|
setError("Please add a title");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const random = randomId();
|
const random = randomId();
|
||||||
|
|
||||||
const tags: string[][] = [
|
const tags: string[][] = [
|
||||||
["d", random],
|
["d", random],
|
||||||
["name", title],
|
["name", title],
|
||||||
@ -95,6 +99,7 @@ export default function CreateCalendarEventModal() {
|
|||||||
["end", toUnix(convertToTimezone(endDate, timezone)).toString()],
|
["end", toUnix(convertToTimezone(endDate, timezone)).toString()],
|
||||||
["start_tzid", timezone],
|
["start_tzid", timezone],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (location) {
|
if (location) {
|
||||||
tags.push([
|
tags.push([
|
||||||
"location",
|
"location",
|
||||||
@ -110,6 +115,7 @@ export default function CreateCalendarEventModal() {
|
|||||||
]);
|
]);
|
||||||
tags.push(["g", location.geohash]);
|
tags.push(["g", location.geohash]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageUrl) {
|
if (imageUrl) {
|
||||||
tags.push(["image", imageUrl]);
|
tags.push(["image", imageUrl]);
|
||||||
}
|
}
|
||||||
@ -121,6 +127,7 @@ export default function CreateCalendarEventModal() {
|
|||||||
tags: tags,
|
tags: tags,
|
||||||
kind: 31923,
|
kind: 31923,
|
||||||
};
|
};
|
||||||
|
|
||||||
const event = await createEvent(ndk, preEvent);
|
const event = await createEvent(ndk, preEvent);
|
||||||
if (event) {
|
if (event) {
|
||||||
toast.success("Event Created!");
|
toast.success("Event Created!");
|
||||||
|
@ -27,6 +27,7 @@ export async function createEvent(
|
|||||||
) {
|
) {
|
||||||
log("func", "createEvent");
|
log("func", "createEvent");
|
||||||
try {
|
try {
|
||||||
|
alert("at pub");
|
||||||
const pubkey = ndk.activeUser?.pubkey;
|
const pubkey = ndk.activeUser?.pubkey;
|
||||||
if (!pubkey) {
|
if (!pubkey) {
|
||||||
throw new Error("No public key provided!");
|
throw new Error("No public key provided!");
|
||||||
|
@ -138,9 +138,20 @@ export function convertToTimezone(inputDate: Date, targetTimezone: string) {
|
|||||||
}
|
}
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
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
|
// 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 plainString = initialDate.toISOString().split(".")[0] as string;
|
||||||
const plain = dayjs.tz(plainString, targetTimezone);
|
const plain = dayjs.tz(plainString, targetTimezone);
|
||||||
return plain.toDate();
|
return plain.toDate();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user