From 8243577484d27911a7d884cde4b9246a666825d0 Mon Sep 17 00:00:00 2001 From: yam-111 Date: Wed, 21 Aug 2024 15:48:57 +0800 Subject: [PATCH] fix the wrong time schedule formatted on ics --- web-extension/utils/helpers.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web-extension/utils/helpers.js b/web-extension/utils/helpers.js index c2ce47f..be8f001 100644 --- a/web-extension/utils/helpers.js +++ b/web-extension/utils/helpers.js @@ -94,9 +94,21 @@ export function parseDateTime(dateStr, timeStr) { return parsedDate; } -// Function to format date as iCalendar date-time format (yyyyMMddTHHmmssZ) +/**format date as iCalendar(ics) date-time format (yyyyMMddTHHmmssZ) + * + * @param {*} date + * @returns {string} - formatted date + */ export function formatICalDate(date) { - return date.toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z'; + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + const seconds = String(date.getSeconds()).padStart(2, '0'); + + // Return in iCal format without converting to UTC + return `${year}${month}${day}T${hours}${minutes}${seconds}`; } export function formatTime(timeString) { @@ -107,6 +119,7 @@ export function formatTime(timeString) { /**converts 24-hr to 12-hr format * @param {number} date + * @returns {string} - time in 12hr format */ export function convert24hrto12hr(date) { let hour = date.getHours();