From 5b8f0a57e7861b17e77750deec8321eb92e228a0 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sun, 18 Apr 2021 09:23:02 +0300 Subject: [PATCH] fix recurring events calendar by using zeroed time data in before and after stamps --- calendar/plugin.json | 2 +- calendar/plugin.ts | 9 +++++++-- squeebot.repo.json | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/calendar/plugin.json b/calendar/plugin.json index 80de5bc..4891070 100644 --- a/calendar/plugin.json +++ b/calendar/plugin.json @@ -2,7 +2,7 @@ "main": "plugin.js", "name": "calendar", "description": "Plugin for iCalendar/VCS room events", - "version": "1.1.0", + "version": "1.1.1", "tags": ["commands", "utility", "calendar"], "dependencies": ["simplecommands"], "npmDependencies": ["node-ical@^0.12.3"] diff --git a/calendar/plugin.ts b/calendar/plugin.ts index e312eb2..dee1e1c 100644 --- a/calendar/plugin.ts +++ b/calendar/plugin.ts @@ -37,6 +37,11 @@ function nts(): number { return Math.floor(Date.now() / 1000); } +function utcNoHours(start: number): Date { + const fts = new Date(start); + return new Date(Date.UTC(fts.getFullYear(), fts.getMonth(), fts.getDate())); +} + function eventsFor(msg: IMessage): Event[] { return memcache.filter((ev: Event) => { if (!msg.fullRoomID) { @@ -146,8 +151,8 @@ async function fetchCalendars(interval: number): Promise { // Recurring events handling if ('rrule' in data) { const rrule = (data as any).rrule as any; - const recurring = rrule.between(new Date(), - new Date(Date.now() + cfg.timeFrame * 1000)); + const recurring = rrule.between(utcNoHours(Date.now()), + utcNoHours(Date.now() + cfg.timeFrame * 1000), true); const originalDuration = end - start; for (const date of recurring) { const newStart = Math.floor(new Date(date).getTime() / 1000); diff --git a/squeebot.repo.json b/squeebot.repo.json index 6bed318..1bf28aa 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -3,7 +3,7 @@ "plugins": [ { "name": "calendar", - "version": "1.1.0" + "version": "1.1.1" }, { "name": "debug",