From 5fe7a6b6bfc11f46d2f6e78cae3d67eab9b0bac0 Mon Sep 17 00:00:00 2001 From: maria luiza <151561030+maluviieira@users.noreply.github.com> Date: Wed, 17 Dec 2025 11:34:03 +0000 Subject: [PATCH 1/6] created DownloadSchedule + calculations for date and time --- .../planner/schedule/DownloadSchedule.tsx | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/components/planner/schedule/DownloadSchedule.tsx diff --git a/src/components/planner/schedule/DownloadSchedule.tsx b/src/components/planner/schedule/DownloadSchedule.tsx new file mode 100644 index 000000000..589dca01e --- /dev/null +++ b/src/components/planner/schedule/DownloadSchedule.tsx @@ -0,0 +1,45 @@ +import { ClassDescriptor } from "../../../@types"; + +type Props = {classes: ClassDescriptor[]} + +const DownloadSchedule = ({classes} : Props) => { + const downloadIcs = () => { + let icsContent = 'BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//TTS//TTS Schedule//EN\n' + + const now = new Date() + const currentDay = now.getDay() + + classes.forEach((cls) => { + const {courseInfo, classInfo} = cls + classInfo.slots.forEach((slot) => { + + const jsTargetDay = (slot.day + 1) % 7 + + const daysUntil = (jsTargetDay - currentDay + 7) % 7 + const nextDate = new Date(now) + nextDate.setDate(now.getDate() + daysUntil) + + const startHour = Math.floor(slot.start_time) + const startMinute = Math.floor((slot.start_time - startHour) * 60) + + const endTime = slot.start_time + slot.duration + const endHour = Math.floor(endTime) + const endMinute = Math.round((endTime - endHour) * 60) + + const startDate = new Date(nextDate) + startDate.setHours(startHour, startMinute, 0, 0) + const endDate = new Date(nextDate) + endDate.setHours(endHour, endMinute, 0, 0) + + // YYYYMMDDTHHMMSS + const formatDate = (date: Date) => { + const pad = (n: number) => n < 10 ? '0' + n : n + return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}T${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}` + } + + + + }) + }) + } +} \ No newline at end of file From 35b95f510badfcda4effb04ff6997e449843d19f Mon Sep 17 00:00:00 2001 From: maria luiza <151561030+maluviieira@users.noreply.github.com> Date: Wed, 17 Dec 2025 11:44:15 +0000 Subject: [PATCH 2/6] updating icsContent with event details --- src/components/planner/schedule/DownloadSchedule.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/planner/schedule/DownloadSchedule.tsx b/src/components/planner/schedule/DownloadSchedule.tsx index 589dca01e..a302bbe9c 100644 --- a/src/components/planner/schedule/DownloadSchedule.tsx +++ b/src/components/planner/schedule/DownloadSchedule.tsx @@ -37,9 +37,16 @@ const DownloadSchedule = ({classes} : Props) => { return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}T${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}` } - + icsContent += 'BEGIN:VEVENT\n' + icsContent += `SUMMARY:${courseInfo.acronym} - ${slot.lesson_type}\n` + icsContent += `LOCATION:${slot.location}/n` + icsContent += `DTSTART:${formatDate(startDate)}\n` + icsContent += `DTEND:${formatDate(endDate)}\n` + icsContent += 'RRULE:FREQ=WEEKLY\n' + icsContent += 'END:VEVENT\n' }) }) + icsContent += 'END:VCALENDAR' } } \ No newline at end of file From feded300ba68c7cefaa9a0bb1906286f41a3e189 Mon Sep 17 00:00:00 2001 From: Francisca Portugal <159019602+franpts2@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:48:38 +0000 Subject: [PATCH 3/6] Added button and logic to download schedule --- src/components/planner/Schedule.tsx | 2 ++ .../planner/schedule/DownloadSchedule.tsx | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/components/planner/Schedule.tsx b/src/components/planner/Schedule.tsx index a896c422c..81b31daf6 100644 --- a/src/components/planner/Schedule.tsx +++ b/src/components/planner/Schedule.tsx @@ -15,6 +15,7 @@ import { ThemeContext } from '../../contexts/ThemeContext' import MultipleOptionsContext from '../../contexts/MultipleOptionsContext' import ConflictsContext from '../../contexts/ConflictsContext' +import DownloadSchedule from './schedule/DownloadSchedule' const dayValues = Array.from({ length: 6 }, (_, i) => i) const hourValues = Array.from({ length: maxHour - minHour + 1 }, (_, i) => minHour + i) @@ -142,6 +143,7 @@ const Schedule = ({
Descarregar HorĂ¡rio
+