import ical, { VEvent } from 'node-ical'; interface PageProps { params: Promise<{ 'days': string; 'ical-link': string[]; }>; } function getIcalText(field: any): string { if (!field) return ''; if (typeof field === 'string') return field; if (typeof field === 'object' && 'val' in field) return field.val as string; return String(field); } function getIcalDate(dateValue: any): Date { if (!dateValue) return new Date(0); // Fallback: 01.01.1970, falls kein Datum da ist if (dateValue instanceof Date) return dateValue; return new Date(dateValue); } function getCategories(categoriesField: any): string[] { if (!categoriesField) return []; if (Array.isArray(categoriesField)) { return categoriesField.map((cat) => getIcalText(cat)); } return [getIcalText(categoriesField)]; } type TimeMap = Record export default async function EvaluationPage({ params }: PageProps) { let times: TimeMap = {}; let total: number = 0; // get all params const resolvedParams = await params; // get amount of days to fetch const daysToFetch = Number(resolvedParams['days']) || 7; //fallback to 7 days // get the URL from the own URL (/evaluation/) const pathSegments = resolvedParams['ical-link']; let rawUrl = pathSegments.join('/'); rawUrl = decodeURIComponent(rawUrl); const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://'); // fetch the file const response = await fetch(icalUrl, { next: { revalidate: 3600 } }); if (!response.ok) { return
Fehler beim Laden der Kalenderdaten. Status: {response.status}
; } const icalData = await response.text(); const parsedData = ical.sync.parseICS(icalData); // calculate range of time const now = new Date(); const cutoffDate = new Date(); cutoffDate.setDate(now.getDate() - daysToFetch); // filter and sort data (needed: "VEVENT"; time range) const events = Object.values(parsedData) .filter((item): item is VEvent => item !== undefined && item.type === 'VEVENT') .filter((event) => { const startDate = getIcalDate(event.start); return startDate >= cutoffDate && startDate <= now; }) .sort((a, b) => getIcalDate(b.start).getTime() - getIcalDate(a.start).getTime()); // newest first // read time per categorie events.map((event, index) => { const startDate = getIcalDate(event.start); const endDate = getIcalDate(event.end); const durationInMs = endDate.getTime() - startDate.getTime(); const durationInMinutes = durationInMs / (1000 * 60); const categories = getCategories(event.categories); categories.forEach((cat) => { times[cat] = (times[cat] || 0) + durationInMinutes }) total = (total || 0) + durationInMinutes }) return (

Gesamtdauer pro Kategorie

{Object.keys(times).length === 0 ? (

Keine Zeiten erfasst.

) : ( //
    // {Object.entries(times).map(([category, minutes]) => ( //
  • // {category}: {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt) //
  • // ))} //
{Object.entries(times).map(([category, minutes]) => ( ))}
Categorie Time Percentage
{category} {Math.floor(minutes / 60)} Std. {minutes % 60} Min. ({minutes} Min. gesamt) {Math.round(minutes / total *100 *10)/10}
Total {Math.floor(total / 60)} Std. {total % 60} Min. ({total} Min. gesamt)
)}
{events.length === 0 ? (

Keine Termine gefunden.

) : (
    {events.map((event, index) => { const startDate = getIcalDate(event.start); const endDate = getIcalDate(event.end); return (
  • {getIcalText(event.summary)}

    Start: {startDate.toLocaleString('de-DE')}
    Ende: {endDate.toLocaleString('de-DE')}

    {event.location && (

    Ort: {getIcalText(event.location)}

    )} {event.description && (

    Beschreibung: {getIcalText(event.description)}

    )} {event.categories && (
    Kategorien: {getCategories(event.categories).map((cat, i) => ( {cat} ))}
    )}
  • ); })}
)}
); }