@coozzy/cal-dav
Advanced tools
Comparing version 2.6.33 to 2.6.34
@@ -56,3 +56,2 @@ import * as ICAL from 'ical.js'; | ||
private getStringDateWithoutTime; | ||
private convertUTCtoLocal; | ||
} |
@@ -254,3 +254,3 @@ "use strict"; | ||
let exceptionEventString = ''; | ||
if (event.toString().toLowerCase().includes('recurrence-id')) { | ||
if (event.toString().toLowerCase().includes('x-propbase-recurrence-id')) { | ||
// 4. case: occurrence event of recurrence which we have NOT in database | ||
@@ -426,3 +426,3 @@ // occurrence ical string will be created via Event.iterator | ||
} | ||
const xPropbaseRecurrenceId = event.component.getFirstProperty('recurrence-id'); | ||
const xPropbaseRecurrenceId = event.component.getFirstProperty('x-propbase-recurrence-id'); | ||
let recurrenceIdString = ''; | ||
@@ -440,4 +440,4 @@ if (recurrenceId) { | ||
} else if (recurrenceIdString) { | ||
event.component.removeAllProperties('recurrence-id'); | ||
event.component.addPropertyWithValue('RECURRENCE-ID', recurrenceIdString); | ||
event.component.removeAllProperties('x-propbase-recurrence-id'); | ||
event.component.addPropertyWithValue('X-PROPBASE-RECURRENCE-ID', recurrenceIdString); | ||
} | ||
@@ -624,3 +624,3 @@ if (attendees.length) { | ||
if (!isRecurring) { | ||
const recurrenceIdProperty = iCalEvent.component.getFirstProperty('recurrence-id'); | ||
const recurrenceIdProperty = iCalEvent.component.getFirstProperty('x-propbase-recurrence-id'); | ||
if (recurrenceIdProperty) { | ||
@@ -915,27 +915,2 @@ iCalEvent.occurrenceEventDate = this.icalStringToIcalTime(recurrenceIdProperty); | ||
} | ||
convertUTCtoLocal(icsContent) { | ||
// Function to convert UTC datetime strings to local time and remove 'Z' | ||
const convertDateTime = datetime => { | ||
// Parse the datetime string to a Date object | ||
const year = parseInt(datetime.slice(0, 4), 10); | ||
const month = parseInt(datetime.slice(4, 6), 10) - 1; // Month is 0-indexed | ||
const day = parseInt(datetime.slice(6, 8), 10); | ||
const hours = parseInt(datetime.slice(9, 11), 10); | ||
const minutes = parseInt(datetime.slice(11, 13), 10); | ||
const seconds = parseInt(datetime.slice(13, 15), 10); | ||
// Create a Date object in UTC | ||
const utcDate = new Date(Date.UTC(year, month, day, hours, minutes, seconds)); | ||
// Convert to local time by getting the ISO string and formatting it | ||
const localDate = new Date(utcDate.getTime() - utcDate.getTimezoneOffset() * 60000); | ||
const localFormatted = localDate.toISOString().replace(/[:-]/g, '').replace(/\.\d{3}/, ''); | ||
return localFormatted; | ||
}; | ||
// Replace DTSTART and DTEND with converted local time | ||
icsContent = icsContent.replace(/DTSTART:(\d{8}T\d{6})Z/g, (_, datetime) => `DTSTART:${convertDateTime(datetime)}`); | ||
icsContent = icsContent.replace(/DTEND:(\d{8}T\d{6})Z/g, (_, datetime) => `DTEND:${convertDateTime(datetime)}`); | ||
return icsContent; | ||
} | ||
} | ||
@@ -942,0 +917,0 @@ exports.DefaultCalDavClient = DefaultCalDavClient; |
{ | ||
"name": "@coozzy/cal-dav", | ||
"version": "2.6.33", | ||
"version": "2.6.34", | ||
"description": "Simple cal dav client.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,3 +8,2 @@ import * as ICAL from 'ical.js'; | ||
import {htmlToText} from 'html-to-text'; | ||
import * as fs from "node:fs"; | ||
@@ -347,3 +346,3 @@ export interface CalDavClient { | ||
let exceptionEventString = ''; | ||
if (event.toString().toLowerCase().includes('recurrence-id')) { | ||
if (event.toString().toLowerCase().includes('x-propbase-recurrence-id')) { | ||
// 4. case: occurrence event of recurrence which we have NOT in database | ||
@@ -542,3 +541,3 @@ // occurrence ical string will be created via Event.iterator | ||
} | ||
const xPropbaseRecurrenceId = event.component.getFirstProperty('recurrence-id'); | ||
const xPropbaseRecurrenceId = event.component.getFirstProperty('x-propbase-recurrence-id'); | ||
let recurrenceIdString = ''; | ||
@@ -557,4 +556,4 @@ if (recurrenceId) { | ||
} else if (recurrenceIdString) { | ||
event.component.removeAllProperties('recurrence-id'); | ||
event.component.addPropertyWithValue('RECURRENCE-ID', recurrenceIdString); | ||
event.component.removeAllProperties('x-propbase-recurrence-id'); | ||
event.component.addPropertyWithValue('X-PROPBASE-RECURRENCE-ID', recurrenceIdString); | ||
} | ||
@@ -813,3 +812,3 @@ | ||
if (!isRecurring) { | ||
const recurrenceIdProperty = iCalEvent.component.getFirstProperty('recurrence-id'); | ||
const recurrenceIdProperty = iCalEvent.component.getFirstProperty('x-propbase-recurrence-id'); | ||
if (recurrenceIdProperty) { | ||
@@ -1114,29 +1113,3 @@ iCalEvent.occurrenceEventDate = this.icalStringToIcalTime(recurrenceIdProperty); | ||
} | ||
private convertUTCtoLocal(icsContent: string): string { | ||
// Function to convert UTC datetime strings to local time and remove 'Z' | ||
const convertDateTime = (datetime: string): string => { | ||
// Parse the datetime string to a Date object | ||
const year = parseInt(datetime.slice(0, 4), 10); | ||
const month = parseInt(datetime.slice(4, 6), 10) - 1; // Month is 0-indexed | ||
const day = parseInt(datetime.slice(6, 8), 10); | ||
const hours = parseInt(datetime.slice(9, 11), 10); | ||
const minutes = parseInt(datetime.slice(11, 13), 10); | ||
const seconds = parseInt(datetime.slice(13, 15), 10); | ||
// Create a Date object in UTC | ||
const utcDate = new Date(Date.UTC(year, month, day, hours, minutes, seconds)); | ||
// Convert to local time by getting the ISO string and formatting it | ||
const localDate = new Date(utcDate.getTime() - (utcDate.getTimezoneOffset() * 60000)); | ||
const localFormatted = localDate.toISOString().replace(/[:-]/g, '').replace(/\.\d{3}/, ''); | ||
return localFormatted; | ||
}; | ||
// Replace DTSTART and DTEND with converted local time | ||
icsContent = icsContent.replace(/DTSTART:(\d{8}T\d{6})Z/g, (_, datetime) => `DTSTART:${convertDateTime(datetime)}`); | ||
icsContent = icsContent.replace(/DTEND:(\d{8}T\d{6})Z/g, (_, datetime) => `DTEND:${convertDateTime(datetime)}`); | ||
return icsContent; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
147343
2820
64