1
0
Fork 0

fix:handle timebased events

This commit is contained in:
Ryan Mwangi 2024-11-13 02:54:42 +03:00
parent d08d87f47c
commit 2e9de0749d
3 changed files with 48 additions and 46 deletions

View File

@ -44,24 +44,34 @@ export function addEventsToCalendar(calendarComponent, results) {
component.getAllSubcomponents('vevent').forEach((event) => {
const vevent = new ICAL.Event(event);
const newEvent = new ICAL.Component('vevent');
// Use ICAL.Time to handle dates correctly
const startDate = vevent.startDate;
const endDate = vevent.endDate;
// Create new ICAL.Time objects for start and end dates
const startTime = new ICAL.Time();
startTime.year = startDate.year;
startTime.month = startDate.month;
startTime.day = startDate.day;
startTime.isDate = true; // Set as all-day event
const endTime = new ICAL.Time();
endTime.year = endDate.year;
endTime.month = endDate.month;
endTime.day = endDate.day;
endTime.isDate = true; // Set as all-day event
const startTime = new ICAL.Time({
year: startDate.year,
month: startDate.month,
day: startDate.day,
hour: startDate.isDate ? null : startDate.hour,
minute: startDate.isDate ? null : startDate.minute,
second: startDate.isDate ? null : startDate.second,
zone: startDate.zone
});
startTime.isDate = startDate.isDate;
const endTime = new ICAL.Time({
year: endDate.year,
month: endDate.month,
day: endDate.day,
hour: endDate.isDate ? null : endDate.hour,
minute: endDate.isDate ? null : endDate.minute,
second: endDate.isDate ? null : endDate.second,
zone: endDate.zone
});
endTime.isDate = endDate.isDate;
// Retain the existing DTSTAMP from vevent
const dtstampProperty = event.getFirstProperty('dtstamp');
const dtstamp = dtstampProperty ? dtstampProperty.getFirstValue() : null;

View File

@ -92,37 +92,33 @@ describe('Calendar Merging API', () => {
// expect(actualOutput).toBe(expectedOutput);
// });
// test('Merge time-based calendar', async () => {
// const response = await request(server)
// .post('/merge')
// .send({
// linkGroupName: 'Time Based Calendar',
// calendars: [
// {
// url: loadCalendarFile('team_meeting_calendar.ics'),
// prefix: 'team_meeting_calendar',
// override: false,
// },
// {
// url: loadCalendarFile('work_task_calendar.ics'),
// prefix: 'work_task',
// override: false,
// },
// ],
// });
test('Merge time-based calendar', async () => {
const input = loadCalendarFile('work_task_calendar.ics');
const response = await request(server)
.post('/merge')
.send({
linkGroupName: 'Time Based Calendar',
calendars: [
{
url: input,
prefix: 'work_task',
override: false,
},
],
});
// expect(response.status).toBe(200);
// expect(response.body.url).toMatch(/calendar\/Time_Based_Calendar/);
expect(response.status).toBe(200);
expect(response.body.url).toMatch(/calendar\/Time_Based_Calendar/);
// // Check if the file was created in the test directory
// const filePath = path.join(CALENDARS_DIR, 'Time_Based_Calendar.ics');
// expect(fs.existsSync(filePath)).toBe(true);
// Check if the file was created in the test directory
const filePath = path.join(CALENDARS_DIR, 'Time_Based_Calendar.ics');
expect(fs.existsSync(filePath)).toBe(true);
// // Load expected output and compare
// const expectedOutput = loadExpectedOutput('Time_Based_Calendar.ics');
// const actualOutput = fs.readFileSync (filePath, 'utf8');
// expect(actualOutput).toBe(expectedOutput);
// });
// Load expected output and compare
const expectedOutput = fs.readFileSync(input, 'utf8');
const actualOutput = fs.readFileSync(filePath, 'utf8');
expect(actualOutput).toBe(expectedOutput);
});
// test('Merge calendar without prefix', async () => {
// const response = await request(server)

View File

@ -1,15 +1,11 @@
BEGIN:VCALENDAR
NAME:Time Based Calendar
VERSION:2.0
PRODID:-//Example Corp//NONSGML Event//EN
BEGIN:VEVENT
UID:20231108T090000-001@example.com
DTSTAMP:20231108T090000Z
DTSTART:20231108T090000Z
DTEND:20231108T100000Z
SUMMARY:Work Task
DESCRIPTION:Time-based work task event.
LOCATION:Office
STATUS:CONFIRMED
SEQUENCE:0
END:VEVENT
END:VCALENDAR
END:VCALENDAR