Skip to content

Commit

Permalink
Fix scheduling for negative timezones
Browse files Browse the repository at this point in the history
And hopefully all other timezones. The date for a
scheduled event should now always be correct,
no matter what hour/minute is selected.

Aims at fixing opencast#1062.
  • Loading branch information
Arnei committed Jan 15, 2025
1 parent 962a9e1 commit 1b4c565
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/components/events/partials/wizards/NewEventSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MetadataSummaryTable from "./summaryTables/MetadataSummaryTable";
import MetadataExtendedSummaryTable from "./summaryTables/MetadataExtendedSummaryTable";
import AccessSummaryTable from "./summaryTables/AccessSummaryTable";
import WizardNavigationButtons from "../../../shared/wizard/WizardNavigationButtons";
import { translateOverrideFallback } from "../../../../utils/utils";
import { getCurrentLanguageInformation, translateOverrideFallback } from "../../../../utils/utils";

Check warning on line 13 in src/components/events/partials/wizards/NewEventSummary.tsx

View workflow job for this annotation

GitHub Actions / build

'getCurrentLanguageInformation' is defined but never used
import { useAppSelector } from "../../../../store";
import { FormikProps } from "formik";
import { TransformedAcl } from "../../../../slices/aclDetailsSlice";
Expand Down Expand Up @@ -190,7 +190,7 @@ const NewEventSummary = <T extends RequiredFormProps>({
</td>
<td>
{t("dateFormats.date.short", {
date: formik.values.scheduleStartDate,
date: renderValidDate(formik.values.scheduleStartDate),
})}
</td>
</tr>
Expand All @@ -210,7 +210,7 @@ const NewEventSummary = <T extends RequiredFormProps>({
</td>
<td>
{t("dateFormats.date.short", {
date: formik.values.scheduleEndDate,
date: renderValidDate(formik.values.scheduleEndDate),
})}
</td>
</tr>
Expand Down
25 changes: 10 additions & 15 deletions src/utils/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import { FormikErrors } from "formik";
* This File contains methods concerning dates
*/

// Get the ISO date string based on local time
const getISODateString = (date: Date) => {
return moment(date).format('YYYY-MM-DD');
}

// check if date can be parsed
export const renderValidDate = (date: string) => {
return !isNaN(Date.parse(date)) ? new Date(date) : ""
Expand Down Expand Up @@ -126,8 +121,8 @@ const changeStart = (
}

setDuration(startDate, endDate, setFieldValue);
setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleStartDate", getISODateString(startDate));
setFieldValue("scheduleEndDate", endDate.toISOString());
setFieldValue("scheduleStartDate", startDate.toISOString());

if (!!checkConflicts && !!formikValues.captureAgent) {
checkConflicts(
Expand Down Expand Up @@ -230,7 +225,7 @@ const changeEnd = (
}

setDuration(startDate, endDate, setFieldValue);
setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleEndDate", endDate.toISOString());

if (!!checkConflicts && !!formikValues.captureAgent) {
checkConflicts(
Expand Down Expand Up @@ -304,7 +299,7 @@ const changeDuration = (

setFieldValue("scheduleEndHour", makeTwoDigits(endDate.getHours()));
setFieldValue("scheduleEndMinute", makeTwoDigits(endDate.getMinutes()));
setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleEndDate", endDate.toISOString());

if (!!checkConflicts && !!formikValues.captureAgent) {
checkConflicts(
Expand Down Expand Up @@ -405,8 +400,8 @@ const changeStartMultiple = (
endDate.setDate(startDate.getDate() + 1);
}

setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleStartDate", getISODateString(startDate));
setFieldValue("scheduleEndDate", endDate.toISOString());
setFieldValue("scheduleStartDate", startDate.toISOString());

if (!!checkConflicts && !! formikValues.captureAgent) {
checkConflicts(
Expand Down Expand Up @@ -525,8 +520,8 @@ export const changeEndDateMultiple = async (
}
}

setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleStartDate", getISODateString(startDate));
setFieldValue("scheduleEndDate", endDate.toISOString());
setFieldValue("scheduleStartDate", startDate.toISOString());

if (!!checkConflicts && !!formikValues.captureAgent) {
checkConflicts(
Expand Down Expand Up @@ -571,7 +566,7 @@ const changeEndMultiple = (

if (isEndBeforeStart(startDate, endDate)) {
endDate.setDate(startDate.getDate() + 1);
setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleEndDate", endDate.toISOString());
}

if (!!checkConflicts && !!formikValues.captureAgent) {
Expand Down Expand Up @@ -668,7 +663,7 @@ const changeDurationMultiple = (

setFieldValue("scheduleEndHour", makeTwoDigits(endDate.getHours()));
setFieldValue("scheduleEndMinute", makeTwoDigits(endDate.getMinutes()));
setFieldValue("scheduleEndDate", getISODateString(endDate));
setFieldValue("scheduleEndDate", endDate.toISOString());

if (!!checkConflicts && !!formikValues.captureAgent) {
checkConflicts(
Expand Down

0 comments on commit 1b4c565

Please sign in to comment.