11import ical , { ICalEventStatus } from "ical-generator" ;
22import { Lesson } from "./types" ;
33
4- export function lessonsToIcs ( lessons : Lesson [ ] , timezone : string ) : string {
4+ export function lessonsToIcs (
5+ lessons : Lesson [ ] ,
6+ timezone : string ,
7+ requestedTimetable : string
8+ ) : string {
59 const cal = ical ( { name : "WebUntis Timetable" , timezone } ) ;
610
711 for ( const l of lessons ) {
@@ -10,6 +14,18 @@ export function lessonsToIcs(lessons: Lesson[], timezone: string): string {
1014 const endHour = Math . floor ( l . endTime / 100 ) ;
1115 const endMinute = l . endTime % 100 ;
1216
17+ const teacherCount = l . teacher . length ;
18+ const teacherList = l . teacher . slice ( 0 , 3 ) . join ( ", " ) ;
19+ const teacherSummary =
20+ teacherCount > 3
21+ ? `${ teacherList } ...+${ teacherCount - 3 } `
22+ : teacherList ;
23+
24+ const classCount = l . class . length ;
25+ const classList = l . class . slice ( 0 , 3 ) . join ( ", " ) ;
26+ const classSummary =
27+ classCount > 3 ? `${ classList } ...+${ classCount - 3 } ` : classList ;
28+
1329 cal . createEvent ( {
1430 start : new Date (
1531 l . date . getFullYear ( ) ,
@@ -25,9 +41,14 @@ export function lessonsToIcs(lessons: Lesson[], timezone: string): string {
2541 endHour ,
2642 endMinute
2743 ) ,
28- summary : `${ l . subject } (${ l . class } )` ,
29- description : `Teacher: ${ l . teacher } \nRoom: ${ l . room } ` ,
44+ summary : `${ l . subject } (${ teacherSummary } ) - ${ classSummary } ` ,
3045 location : l . room ,
46+ description : `Subject: ${ l . subject } \nTeacher: ${ l . teacher . join (
47+ ", "
48+ ) } \nRoom: ${ l . room } \nClass: ${ l . class . join (
49+ ", "
50+ ) } \nTimetable: ${ requestedTimetable } `,
51+
3152 status : "CONFIRMED" as ICalEventStatus ,
3253 } ) ;
3354 }
0 commit comments