Skip to content

Commit

Permalink
Merge pull request #252 from os2display/feature/rrule-fixes
Browse files Browse the repository at this point in the history
Reverted change to rrule dtstart
  • Loading branch information
tuj authored Aug 6, 2024
2 parents 98a7184 + d539a9e commit 4f4654b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
13 changes: 8 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- [#252](https://github.com/os2display/display-admin-client/pull/252)
- Reverted change in https://github.com/os2display/display-admin-client/commit/65762066c708f541305a48fbd6b28264dca593b5 regarding rrule dtstart.
- 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
- Make the station selector call new api
- Add config to context in app.jsx
- Add entry in example config for midttrafik api key
- Clean up multi select component a bit, replace reduce with Map logic
- Make the station selector call new api
- Add config to context in app.jsx

## [2.0.3] - 2024-08-01

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

## [2.0.2] - 2024-04-25

Expand Down
15 changes: 14 additions & 1 deletion src/components/util/schedule/schedule-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dayjs.extend(localizedFormat);
/**
* Get rrule string from schedule.
*
*
*
* @param {object} schedule - The schedule.
* @returns {string} - RRule string.
*/
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions src/components/util/schedule/schedule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)));
};

/**
Expand All @@ -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") : "";
};

/**
Expand Down Expand Up @@ -342,6 +352,7 @@ function Schedule({ schedules, onChange }) {
<div id="schedule_details" className="row">
<strong>{t("schedule.rrulestring")}:</strong>
<span>{schedule.rrule}</span>
<small>{t("schedule.rrulestring-z-ignored")}</small>
<div className="mt-2">
<strong>{t("schedule.next-occurrences")}:</strong>
{getNextOccurrences(schedule.rruleObject).map(
Expand Down
1 change: 1 addition & 0 deletions src/translations/da/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@
"hourly": "Time",
"minutely": "Minut",
"rrulestring": "RRule",
"rrulestring-z-ignored": "Bemærk at tidszonen (Z) bliver ignoreret i evalueringen af reglen. Tidsangivelserne vil altid blive behandlet i lokal tid.",
"dtstart": "Startdato",
"until": "Slutdato",
"next-occurrences": "Næste 5 forekomster",
Expand Down

0 comments on commit 4f4654b

Please sign in to comment.