From 2c9fb8fd77e77c646364f9e840fb36503cccbaef Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:13:03 +0200 Subject: [PATCH 1/2] 2000: Reverted change to rrule dtstart --- CHANGELOG.md | 3 +++ src/components/util/schedule/schedule-util.js | 15 ++++++++++++++- src/components/util/schedule/schedule.jsx | 15 +++++++++++++-- src/translations/da/common.json | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 125629b2..af395496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- Reverted change in https://github.com/os2display/display-admin-client/commit/65762066c708f541305a48fbd6b28264dca593b5. +- Added comments about how rrules are handled. + - [#242](https://github.com/os2display/display-admin-client/pull/243) - Add entry in example config for midttrafik api key - Clean up multi select component a bit, replace reduce with Map logic diff --git a/src/components/util/schedule/schedule-util.js b/src/components/util/schedule/schedule-util.js index 73138a4e..f2a778d7 100644 --- a/src/components/util/schedule/schedule-util.js +++ b/src/components/util/schedule/schedule-util.js @@ -11,6 +11,8 @@ dayjs.extend(localizedFormat); /** * Get rrule string from schedule. * + * + * * @param {object} schedule - The schedule. * @returns {string} - RRule string. */ @@ -56,7 +58,18 @@ const createNewSchedule = () => { id: ulid(nowTimestamp), duration: 60 * 60 * 24, // Default one day. freq: RRule.WEEKLY, - dtstart: new Date(), + // For evaluation with the RRule library we pretend that "now" is in UTC instead of the local timezone. + // That is 9:00 in Europe/Copenhagen time will be evaluated as if it was 9:00 in UTC. + // @see https://github.com/jkbrzt/rrule#important-use-utc-dates + dtstart: new Date( + Date.UTC( + now.getFullYear(), + now.getMonth(), + now.getDate(), + now.getHours(), + now.getMinutes() + ) + ), until: null, wkst: RRule.MO, byhour: null, diff --git a/src/components/util/schedule/schedule.jsx b/src/components/util/schedule/schedule.jsx index e12d036e..50e86fe8 100644 --- a/src/components/util/schedule/schedule.jsx +++ b/src/components/util/schedule/schedule.jsx @@ -120,7 +120,17 @@ function Schedule({ schedules, onChange }) { */ const setDateValue = (scheduleId, target) => { const date = new Date(target.value); - changeSchedule(scheduleId, target.id, date); + + // For evaluation with the RRule library we pretend that the date is in UTC instead of the local timezone. + // That is 9:00 in Europe/Copenhagen time will be evaluated as if it was 9:00 in UTC. + // @see https://github.com/jkbrzt/rrule#important-use-utc-dates + changeSchedule(scheduleId, target.id, new Date(Date.UTC( + date.getFullYear(), + date.getMonth(), + date.getDate(), + date.getHours(), + date.getMinutes() + ))); }; /** @@ -130,7 +140,7 @@ function Schedule({ schedules, onChange }) { * @returns {string} - The date formatted for datetime-local. */ const getDateValue = (date) => { - return date ? dayjs(date).format("YYYY-MM-DDTHH:mm") : ""; + return date ? dayjs(date).utc().format("YYYY-MM-DDTHH:mm") : ""; }; /** @@ -342,6 +352,7 @@ function Schedule({ schedules, onChange }) {