Skip to content

Commit 4f4654b

Browse files
authored
Merge pull request #252 from os2display/feature/rrule-fixes
Reverted change to rrule dtstart
2 parents 98a7184 + d539a9e commit 4f4654b

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
- [#252](https://github.com/os2display/display-admin-client/pull/252)
8+
- Reverted change in https://github.com/os2display/display-admin-client/commit/65762066c708f541305a48fbd6b28264dca593b5 regarding rrule dtstart.
9+
- Added comments about how rrules are handled.
710
- [#242](https://github.com/os2display/display-admin-client/pull/243)
8-
- Add entry in example config for midttrafik api key
9-
- Clean up multi select component a bit, replace reduce with Map logic
10-
- Make the station selector call new api
11-
- Add config to context in app.jsx
11+
- Add entry in example config for midttrafik api key
12+
- Clean up multi select component a bit, replace reduce with Map logic
13+
- Make the station selector call new api
14+
- Add config to context in app.jsx
1215

1316
## [2.0.3] - 2024-08-01
1417

1518
- [#243](https://github.com/os2display/display-admin-client/pull/251)
16-
- Fix null bug: replace valueAsDate with target.value as valueAsDate was null
19+
- Fix null bug: replace valueAsDate with target.value as valueAsDate was null
1720

1821
## [2.0.2] - 2024-04-25
1922

src/components/util/schedule/schedule-util.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ dayjs.extend(localizedFormat);
1111
/**
1212
* Get rrule string from schedule.
1313
*
14+
*
15+
*
1416
* @param {object} schedule - The schedule.
1517
* @returns {string} - RRule string.
1618
*/
@@ -56,7 +58,18 @@ const createNewSchedule = () => {
5658
id: ulid(nowTimestamp),
5759
duration: 60 * 60 * 24, // Default one day.
5860
freq: RRule.WEEKLY,
59-
dtstart: new Date(),
61+
// For evaluation with the RRule library we pretend that "now" is in UTC instead of the local timezone.
62+
// That is 9:00 in Europe/Copenhagen time will be evaluated as if it was 9:00 in UTC.
63+
// @see https://github.com/jkbrzt/rrule#important-use-utc-dates
64+
dtstart: new Date(
65+
Date.UTC(
66+
now.getFullYear(),
67+
now.getMonth(),
68+
now.getDate(),
69+
now.getHours(),
70+
now.getMinutes()
71+
)
72+
),
6073
until: null,
6174
wkst: RRule.MO,
6275
byhour: null,

src/components/util/schedule/schedule.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ function Schedule({ schedules, onChange }) {
120120
*/
121121
const setDateValue = (scheduleId, target) => {
122122
const date = new Date(target.value);
123-
changeSchedule(scheduleId, target.id, date);
123+
124+
// For evaluation with the RRule library we pretend that the date is in UTC instead of the local timezone.
125+
// That is 9:00 in Europe/Copenhagen time will be evaluated as if it was 9:00 in UTC.
126+
// @see https://github.com/jkbrzt/rrule#important-use-utc-dates
127+
changeSchedule(scheduleId, target.id, new Date(Date.UTC(
128+
date.getFullYear(),
129+
date.getMonth(),
130+
date.getDate(),
131+
date.getHours(),
132+
date.getMinutes()
133+
)));
124134
};
125135

126136
/**
@@ -130,7 +140,7 @@ function Schedule({ schedules, onChange }) {
130140
* @returns {string} - The date formatted for datetime-local.
131141
*/
132142
const getDateValue = (date) => {
133-
return date ? dayjs(date).format("YYYY-MM-DDTHH:mm") : "";
143+
return date ? dayjs(date).utc().format("YYYY-MM-DDTHH:mm") : "";
134144
};
135145

136146
/**
@@ -342,6 +352,7 @@ function Schedule({ schedules, onChange }) {
342352
<div id="schedule_details" className="row">
343353
<strong>{t("schedule.rrulestring")}:</strong>
344354
<span>{schedule.rrule}</span>
355+
<small>{t("schedule.rrulestring-z-ignored")}</small>
345356
<div className="mt-2">
346357
<strong>{t("schedule.next-occurrences")}:</strong>
347358
{getNextOccurrences(schedule.rruleObject).map(

src/translations/da/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@
776776
"hourly": "Time",
777777
"minutely": "Minut",
778778
"rrulestring": "RRule",
779+
"rrulestring-z-ignored": "Bemærk at tidszonen (Z) bliver ignoreret i evalueringen af reglen. Tidsangivelserne vil altid blive behandlet i lokal tid.",
779780
"dtstart": "Startdato",
780781
"until": "Slutdato",
781782
"next-occurrences": "Næste 5 forekomster",

0 commit comments

Comments
 (0)