Skip to content

Commit

Permalink
Merge pull request #9 from yam-1111/main
Browse files Browse the repository at this point in the history
fix the wrong time schedule formatted on ics
  • Loading branch information
KevsterAmp authored Aug 21, 2024
2 parents be2d1e8 + 8243577 commit a7ff2ef
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions web-extension/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down

0 comments on commit a7ff2ef

Please sign in to comment.