diff --git a/register.php b/register.php index 0eb44d1..b133d4f 100644 --- a/register.php +++ b/register.php @@ -252,26 +252,32 @@ if (!$webinar) { .then(data => { if (data.success) { formContainer.style.display = 'none'; - const webinarTitle = encodeURIComponent(data.webinar_title); + const webinarTitle = encodeURIComponent(data.webinar_title); const webinarDate = new Date(data.webinar_date_utc + 'Z'); - const startTime = webinarDate.toISOString().replace(/-|:|..*Z/g, '') + 'Z'; - const endTime = new Date(webinarDate.getTime() + (60 * 60 * 1000)).toISOString().replace(/-|:|..*Z/g, '') + 'Z'; + + // Correctly format dates for UTC (YYYYMMDDTHHMMSSZ) + const formatUTCDate = (date) => { + return date.toISOString().replace(/\.\d{3}Z$/, 'Z').replace(/[-:]/g, ''); + }; - const googleLink = `https://www.google.com/calendar/render?action=TEMPLATE&text=${webinarTitle}&dates=${startTime.replace(/Z$/, '')}/${endTime.replace(/Z$/, '')}&details=Join+the+webinar!`; + const startTime = formatUTCDate(webinarDate); + const endTime = formatUTCDate(new Date(webinarDate.getTime() + (60 * 60 * 1000))); + + const googleLink = `https://www.google.com/calendar/render?action=TEMPLATE&text=${webinarTitle}&dates=${startTime}/${endTime}&details=Join+the+webinar!&ctz=UTC`; const icsContent = [ 'BEGIN:VCALENDAR', 'VERSION:2.0', 'BEGIN:VEVENT', `URL:${window.location.href}`, - `DTSTART:${startTime.replace(/Z$/, '')}`, - `DTEND:${endTime.replace(/Z$/, '')}`, + `DTSTART:${startTime}`, + `DTEND:${endTime}`, `SUMMARY:${data.webinar_title}`, 'DESCRIPTION:Join the webinar!', 'END:VEVENT', 'END:VCALENDAR' ].join('\n'); - const outlookLink = `data:text/calendar;charset=utf8,${encodeURIComponent(icsContent)}`; + const outlookLink = `data:text/calendar;charset=utf-8,${encodeURIComponent(icsContent)}`; formResult.innerHTML = `