format codebase with prettier
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { RRule, rrulestr } from 'rrule';
|
||||
import { CalendarEvent } from '@caldav/shared';
|
||||
import { RRule, rrulestr } from "rrule";
|
||||
import { CalendarEvent } from "@caldav/shared";
|
||||
|
||||
export interface ExpandedEvent extends CalendarEvent {
|
||||
occurrenceStart: Date;
|
||||
@@ -9,14 +9,16 @@ export interface ExpandedEvent extends CalendarEvent {
|
||||
// Convert local time to "fake UTC" for rrule
|
||||
// rrule interprets all dates as UTC internally, so we need to trick it
|
||||
function toRRuleDate(date: Date): Date {
|
||||
return new Date(Date.UTC(
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
date.getSeconds()
|
||||
));
|
||||
return new Date(
|
||||
Date.UTC(
|
||||
date.getFullYear(),
|
||||
date.getMonth(),
|
||||
date.getDate(),
|
||||
date.getHours(),
|
||||
date.getMinutes(),
|
||||
date.getSeconds(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Convert rrule result back to local time
|
||||
@@ -27,7 +29,7 @@ function fromRRuleDate(date: Date): Date {
|
||||
date.getUTCDate(),
|
||||
date.getUTCHours(),
|
||||
date.getUTCMinutes(),
|
||||
date.getUTCSeconds()
|
||||
date.getUTCSeconds(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -38,7 +40,7 @@ function fromRRuleDate(date: Date): Date {
|
||||
export function expandRecurringEvents(
|
||||
events: CalendarEvent[],
|
||||
rangeStart: Date,
|
||||
rangeEnd: Date
|
||||
rangeEnd: Date,
|
||||
): ExpandedEvent[] {
|
||||
const expanded: ExpandedEvent[] = [];
|
||||
|
||||
@@ -61,13 +63,15 @@ export function expandRecurringEvents(
|
||||
|
||||
// Recurring event: parse RRULE and expand
|
||||
try {
|
||||
const rule = rrulestr(`DTSTART:${formatRRuleDateString(startTime)}\nRRULE:${event.recurrenceRule}`);
|
||||
const rule = rrulestr(
|
||||
`DTSTART:${formatRRuleDateString(startTime)}\nRRULE:${event.recurrenceRule}`,
|
||||
);
|
||||
|
||||
// Get occurrences within the range (using fake UTC dates)
|
||||
const occurrences = rule.between(
|
||||
toRRuleDate(rangeStart),
|
||||
toRRuleDate(rangeEnd),
|
||||
true // inclusive
|
||||
true, // inclusive
|
||||
);
|
||||
|
||||
for (const occurrence of occurrences) {
|
||||
@@ -82,7 +86,10 @@ export function expandRecurringEvents(
|
||||
}
|
||||
} catch (error) {
|
||||
// If RRULE parsing fails, include the event as a single occurrence
|
||||
console.error(`Failed to parse recurrence rule for event ${event.id}:`, error);
|
||||
console.error(
|
||||
`Failed to parse recurrence rule for event ${event.id}:`,
|
||||
error,
|
||||
);
|
||||
expanded.push({
|
||||
...event,
|
||||
occurrenceStart: startTime,
|
||||
@@ -92,7 +99,9 @@ export function expandRecurringEvents(
|
||||
}
|
||||
|
||||
// Sort by occurrence start time
|
||||
expanded.sort((a, b) => a.occurrenceStart.getTime() - b.occurrenceStart.getTime());
|
||||
expanded.sort(
|
||||
(a, b) => a.occurrenceStart.getTime() - b.occurrenceStart.getTime(),
|
||||
);
|
||||
|
||||
return expanded;
|
||||
}
|
||||
@@ -100,10 +109,10 @@ export function expandRecurringEvents(
|
||||
// Format date as RRULE DTSTART string (YYYYMMDDTHHMMSS)
|
||||
function formatRRuleDateString(date: Date): string {
|
||||
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');
|
||||
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 `${year}${month}${day}T${hours}${minutes}${seconds}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user