From 1ad7b76447712e1326da1a811988af4c09c85855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 22 Sep 2021 12:18:08 +0200 Subject: [PATCH] fix(calendar): start iCalendar on Monday --- package.json | 2 +- src/entities/Calendar/Calendrier.ts | 4 +- tests/Calendrier.test.ts | 407 ---------------------------- 3 files changed, 4 insertions(+), 409 deletions(-) diff --git a/package.json b/package.json index 688456d..98f72f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kdecole-api", - "version": "1.2.6", + "version": "1.2.7", "main": "dist/Kdecole.js", "types": "types/Kdecole.d.ts", "bin": { diff --git a/src/entities/Calendar/Calendrier.ts b/src/entities/Calendar/Calendrier.ts index 18632ca..95d81ee 100755 --- a/src/entities/Calendar/Calendrier.ts +++ b/src/entities/Calendar/Calendrier.ts @@ -62,6 +62,8 @@ export default class Calendrier { const numberOfWeek = (d1: Date, d2: Date): number => ((d1.getTime() - d2.getTime()) / (7 * 24 * 60 * 60 * 1000)) + const getMonday = (d: Date): Date => new Date(new Date(d.setDate((d.getDate() - d.getDay()) + (d.getDay() === 0 ? -6 : 1))).setHours(0, 0, 0, 0)) + return `BEGIN:VCALENDAR VERSION:2.0 PRODID:-//kdecole-api//ical//EN @@ -70,7 +72,7 @@ TZID:Europe/Paris NAME:${name} X-WR-CALNAME:${name} ` + this.listeJourCdt - .filter(jour => this.currentDate <= jour.date && numberOfWeek(jour.date, this.currentDate) < weeks) + .filter(jour => getMonday(this.currentDate) <= jour.date && numberOfWeek(jour.date, this.currentDate) < weeks) .map(jour => jour.listeSeances).flat() .filter(seance => seance.flagActif) .reduce((acc, seance) => diff --git a/tests/Calendrier.test.ts b/tests/Calendrier.test.ts index f211c70..695a7ce 100755 --- a/tests/Calendrier.test.ts +++ b/tests/Calendrier.test.ts @@ -40,411 +40,4 @@ describe('Test Calendrier', () => { url: '/calendrier/ideleve/AAP05567/' }) }) - it('should return correct VCalendar', async () => { - const calendar = await user.getCalendrier('AAP05567') - expect(calendar.toICalendar(2, 'Emploi du temps')).toBe(`BEGIN:VCALENDAR -VERSION:2.0 -PRODID:-//kdecole-api//ical//EN -METHOD:PUBLISH -TZID:Europe/Paris -NAME:Emploi du temps -X-WR-CALNAME:Emploi du temps -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:768972@kdecoleapi -DTSTART:20210921T060000Z -DTEND:20210921T075000Z -STATUS:CONFIRMED -SUMMARY:SPE_SPC 256 -DESCRIPTION:UID: 768972 -LOCATION:256 - TLE 2 SPE_SPC_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:752986@kdecoleapi -DTSTART:20210921T081000Z -DTEND:20210921T100000Z -STATUS:CONFIRMED -SUMMARY:ALLEMAND 302 -DESCRIPTION:UID: 752986 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:753984@kdecoleapi -DTSTART:20210921T110000Z -DTEND:20210921T115500Z -STATUS:CONFIRMED -SUMMARY:HISTOIRE-GEOGRAPHIE 302 -DESCRIPTION:UID: 753984 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:747131@kdecoleapi -DTSTART:20210921T115500Z -DTEND:20210921T125000Z -STATUS:CONFIRMED -SUMMARY:ANGLAIS 302 -DESCRIPTION:UID: 747131 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:755592@kdecoleapi -DTSTART:20210921T125000Z -DTEND:20210921T134500Z -STATUS:CONFIRMED -SUMMARY:PHILOSOPHIE 302 -DESCRIPTION:UID: 755592 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:753948@kdecoleapi -DTSTART:20210922T081000Z -DTEND:20210922T100000Z -STATUS:CONFIRMED -SUMMARY:HISTOIRE-GEOGRAPHIE 302 -DESCRIPTION:UID: 753948 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:745685@kdecoleapi -DTSTART:20210922T110000Z -DTEND:20210922T115500Z -STATUS:CONFIRMED -SUMMARY:EMC 302 -DESCRIPTION:UID: 745685 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:755520@kdecoleapi -DTSTART:20210922T115500Z -DTEND:20210922T134500Z -STATUS:CONFIRMED -SUMMARY:PHILOSOPHIE 302 -DESCRIPTION:UID: 755520 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:776740@kdecoleapi -DTSTART:20210923T060000Z -DTEND:20210923T075000Z -STATUS:CONFIRMED -SUMMARY:MATHS EXPERTES 302 -DESCRIPTION:UID: 776740 -LOCATION:302 - MATHS_EXP -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:770488@kdecoleapi -DTSTART:20210923T110000Z -DTEND:20210923T115500Z -STATUS:CONFIRMED -SUMMARY:MATHS EXPERTES 302 -DESCRIPTION:UID: 770488 -LOCATION:302 - MATHS_EXP -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:747168@kdecoleapi -DTSTART:20210923T115500Z -DTEND:20210923T125000Z -STATUS:CONFIRMED -SUMMARY:ANGLAIS 302 -DESCRIPTION:UID: 747168 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:768663@kdecoleapi -DTSTART:20210923T140000Z -DTEND:20210923T155000Z -STATUS:CONFIRMED -SUMMARY:SPE_MATH 302 -DESCRIPTION:UID: 768663 -LOCATION:302 - SPE_MATHS_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:769045@kdecoleapi -DTSTART:20210924T060000Z -DTEND:20210924T075000Z -STATUS:CONFIRMED -SUMMARY:SPE_SPC 256 -DESCRIPTION:UID: 769045 -LOCATION:256 - TLE 2 SPE_SPC_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:765918@kdecoleapi -DTSTART:20210924T090500Z -DTEND:20210924T100000Z -STATUS:CONFIRMED -SUMMARY:ENSEIG_SCIENTIFIQUE 252 -DESCRIPTION:UID: 765918 -LOCATION:252 - TLE 2 A -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:750753@kdecoleapi -DTSTART:20210924T110000Z -DTEND:20210924T115500Z -STATUS:CONFIRMED -SUMMARY:ENSEIG_SCIENTIFIQUE 256 -DESCRIPTION:UID: 750753 -LOCATION:256 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:775764@kdecoleapi -DTSTART:20210924T115500Z -DTEND:20210924T134500Z -STATUS:CONFIRMED -SUMMARY:SPE_MATH 302 -DESCRIPTION:UID: 775764 -LOCATION:302 - SPE_MATH_TLE_G2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:768627@kdecoleapi -DTSTART:20210927T060000Z -DTEND:20210927T075000Z -STATUS:CONFIRMED -SUMMARY:SPE_MATH 302 -DESCRIPTION:UID: 768627 -LOCATION:302 - SPE_MATHS_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:771136@kdecoleapi -DTSTART:20210927T081000Z -DTEND:20210927T100000Z -STATUS:CONFIRMED -SUMMARY:ED.PHYSIQUE & SPORT GYM -DESCRIPTION:UID: 771136 -LOCATION:GYM - EPS_TLEG_GEN -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:755557@kdecoleapi -DTSTART:20210927T110000Z -DTEND:20210927T115500Z -STATUS:CONFIRMED -SUMMARY:PHILOSOPHIE 302 -DESCRIPTION:UID: 755557 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:769009@kdecoleapi -DTSTART:20210927T115500Z -DTEND:20210927T134500Z -STATUS:CONFIRMED -SUMMARY:SPE_SPC 256 -DESCRIPTION:UID: 769009 -LOCATION:256 - TLE 2 SPE_SPC_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:770959@kdecoleapi -DTSTART:20210927T140000Z -DTEND:20210927T155000Z -STATUS:CONFIRMED -SUMMARY:LATIN 303 -DESCRIPTION:UID: 770959 -LOCATION:303 - LATIN_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:768973@kdecoleapi -DTSTART:20210928T060000Z -DTEND:20210928T075000Z -STATUS:CONFIRMED -SUMMARY:SPE_SPC 256 -DESCRIPTION:UID: 768973 -LOCATION:256 - TLE 2 SPE_SPC_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:752987@kdecoleapi -DTSTART:20210928T081000Z -DTEND:20210928T100000Z -STATUS:CONFIRMED -SUMMARY:ALLEMAND 302 -DESCRIPTION:UID: 752987 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:753985@kdecoleapi -DTSTART:20210928T110000Z -DTEND:20210928T115500Z -STATUS:CONFIRMED -SUMMARY:HISTOIRE-GEOGRAPHIE 302 -DESCRIPTION:UID: 753985 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:747132@kdecoleapi -DTSTART:20210928T115500Z -DTEND:20210928T125000Z -STATUS:CONFIRMED -SUMMARY:ANGLAIS 302 -DESCRIPTION:UID: 747132 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:755593@kdecoleapi -DTSTART:20210928T125000Z -DTEND:20210928T134500Z -STATUS:CONFIRMED -SUMMARY:PHILOSOPHIE 302 -DESCRIPTION:UID: 755593 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:753949@kdecoleapi -DTSTART:20210929T081000Z -DTEND:20210929T100000Z -STATUS:CONFIRMED -SUMMARY:HISTOIRE-GEOGRAPHIE 302 -DESCRIPTION:UID: 753949 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:755521@kdecoleapi -DTSTART:20210929T115500Z -DTEND:20210929T134500Z -STATUS:CONFIRMED -SUMMARY:PHILOSOPHIE 302 -DESCRIPTION:UID: 755521 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:776741@kdecoleapi -DTSTART:20210930T060000Z -DTEND:20210930T075000Z -STATUS:CONFIRMED -SUMMARY:MATHS EXPERTES 302 -DESCRIPTION:UID: 776741 -LOCATION:302 - MATHS_EXP -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:770489@kdecoleapi -DTSTART:20210930T110000Z -DTEND:20210930T115500Z -STATUS:CONFIRMED -SUMMARY:MATHS EXPERTES 302 -DESCRIPTION:UID: 770489 -LOCATION:302 - MATHS_EXP -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:747169@kdecoleapi -DTSTART:20210930T115500Z -DTEND:20210930T125000Z -STATUS:CONFIRMED -SUMMARY:ANGLAIS 302 -DESCRIPTION:UID: 747169 -LOCATION:302 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:768664@kdecoleapi -DTSTART:20210930T140000Z -DTEND:20210930T155000Z -STATUS:CONFIRMED -SUMMARY:SPE_MATH 302 -DESCRIPTION:UID: 768664 -LOCATION:302 - SPE_MATHS_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:769046@kdecoleapi -DTSTART:20211001T060000Z -DTEND:20211001T075000Z -STATUS:CONFIRMED -SUMMARY:SPE_SPC 256 -DESCRIPTION:UID: 769046 -LOCATION:256 - TLE 2 SPE_SPC_TLE -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:765937@kdecoleapi -DTSTART:20211001T081000Z -DTEND:20211001T090500Z -STATUS:CONFIRMED -SUMMARY:ENSEIG_SCIENTIFIQUE 256 -DESCRIPTION:UID: 765937 -LOCATION:256 - TLE 2 A -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:750737@kdecoleapi -DTSTART:20211001T110000Z -DTEND:20211001T115500Z -STATUS:CONFIRMED -SUMMARY:ENSEIG_SCIENTIFIQUE 252 -DESCRIPTION:UID: 750737 -LOCATION:252 - TLE 2 -END:VEVENT -BEGIN:VEVENT -DTSTAMP:20210921T060000Z -SEQUENCE:0 -UID:775765@kdecoleapi -DTSTART:20211001T115500Z -DTEND:20211001T134500Z -STATUS:CONFIRMED -SUMMARY:SPE_MATH 302 -DESCRIPTION:UID: 775765 -LOCATION:302 - SPE_MATH_TLE_G2 -END:VEVENT -END:VCALENDAR`) - }) })