Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler(T1225416): fix incorrect exclude from recurrence handling #28905

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import Scheduler from 'devextreme-testcafe-models/scheduler';
import {
getTimezoneTest,
MACHINE_TIMEZONES,
MachineTimezonesType,
} from '../../../../helpers/machineTimezones';
import url from '../../../../helpers/getPageUrl';
import { generateOptionMatrix } from '../../../../helpers/generateOptionMatrix';
import { createWidget } from '../../../../helpers/createWidget';

fixture`Scheduler exclude from recurrence`
.page(url(__dirname, '../../../container.html'));

const SCHEDULER_SELECTOR = '#container';
const MS_IN_MINUTE = 60000;
const MS_IN_HOUR = MS_IN_MINUTE * 60;
const APPOINTMENT_TEXT = 'TEST_APPT';

const getAppointments = (
startDate: Date,
currentView: string,
) => [
{
startDate,
endDate: new Date(startDate.getTime() + MS_IN_HOUR),
text: APPOINTMENT_TEXT,
recurrenceRule: currentView === 'week' ? 'FREQ=DAILY' : 'FREQ=WEEKLY;BYDAY=FR',
},
];

const getFirstDayOfWeek = (currentView: string) => (currentView === 'week' ? 4 : 0);
const getAppointmentsCount = (currentView: string) => (currentView === 'week' ? 7 : 6);

generateOptionMatrix({
timeZone: [undefined, 'America/New_York'],
currentView: ['week', 'month'],
location: [
[MACHINE_TIMEZONES.EuropeBerlin, 'summer', '2024-03-31', new Date('2024-01-01T12:00:00Z')],
[MACHINE_TIMEZONES.EuropeBerlin, 'winter', '2024-10-27', new Date('2024-01-01T12:00:00Z')],
[MACHINE_TIMEZONES.AmericaLosAngeles, 'summer', '2024-03-10', new Date('2024-01-01T12:00:00Z')],
[MACHINE_TIMEZONES.AmericaLosAngeles, 'winter', '2024-11-03', new Date('2024-01-01T12:00:00Z')],
] as [MachineTimezonesType, string, string, Date][],
}).forEach(({
timeZone,
currentView,
location: [machineTimezone, caseName, currentDate, startDate],
}) => {
const dataSource = getAppointments(startDate, currentView);
const firstDayOfWeek = getFirstDayOfWeek(currentView);
const appointmentsCount = getAppointmentsCount(currentView);

getTimezoneTest([machineTimezone])(
`Should correctly exclude appointment from recurrence (week, ${timeZone}, ${machineTimezone}, ${caseName})`,
async (t) => {
const scheduler = new Scheduler(SCHEDULER_SELECTOR);

await t.expect(scheduler.getAppointmentCount()).eql(appointmentsCount);

for (let idx = 0; idx < appointmentsCount; idx += 1) {
await t.click(scheduler.getAppointment(APPOINTMENT_TEXT, 0).element)
.click(scheduler.appointmentTooltip.deleteButton);

await t.expect(scheduler.getAppointmentCount()).eql(appointmentsCount - (idx + 1));
}

await t.expect(scheduler.getAppointmentCount()).eql(0);
},
).before(async () => {
await createWidget('dxScheduler', {
timeZone,
dataSource,
currentDate,
currentView,
firstDayOfWeek,
recurrenceEditMode: 'occurrence',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export class DateGeneratorBaseStrategy {

return {
...item,
// TODO: Check usages & delete this field.
exceptionDate: new Date(item.startDate),
};
});
Expand All @@ -188,22 +189,20 @@ export class DateGeneratorBaseStrategy {
return !timeZoneUtils.isEqualLocalTimeZone(this.timeZone, appointment.startDate);
}

_getProcessedNotNativeDateIfCrossDST(date, offset) {
if (offset < 0) { // summer time
const newDate = new Date(date);

const newDateMinusOneHour = new Date(newDate);
newDateMinusOneHour.setHours(newDateMinusOneHour.getHours() - 1);
_getDateOffsetDST(date) {
const dateMinusHour = new Date(date);
dateMinusHour.setHours(dateMinusHour.getHours() - 1);

const newDateOffset = this.timeZoneCalculator.getOffsets(newDate).common;
const newDateMinusOneHourOffset = this.timeZoneCalculator.getOffsets(newDateMinusOneHour).common;
const dateCommonOffset = this.timeZoneCalculator.getOffsets(date).common;
const dateMinusHourCommonOffset = this.timeZoneCalculator.getOffsets(dateMinusHour).common;

if (newDateOffset !== newDateMinusOneHourOffset) {
return 0;
}
}
return dateMinusHourCommonOffset - dateCommonOffset;
}

return offset;
_getProcessedNotNativeDateIfCrossDST(date, offset) {
return offset < 0 && this._getDateOffsetDST(date) !== 0
? 0
: offset;
}

_getCommonOffset(date) {
Expand Down Expand Up @@ -236,6 +235,7 @@ export class DateGeneratorBaseStrategy {
...item,
startDate: newStartDate,
endDate: newEndDate,
// TODO: Check usages & delete this field.
exceptionDate: new Date(newStartDate),
};
});
Expand Down Expand Up @@ -386,18 +386,26 @@ export class DateGeneratorBaseStrategy {
true,
),

getPostProcessedException: (date) => {
if (isEmptyObject(this.timeZone) || timeZoneUtils.isEqualLocalTimeZone(this.timeZone, date)) {
return date;
}

const appointmentOffset = this.timeZoneCalculator.getOffsets(originalAppointmentStartDate).common;
const exceptionAppointmentOffset = this.timeZoneCalculator.getOffsets(date).common;

let diff = appointmentOffset - exceptionAppointmentOffset;
diff = this._getProcessedNotNativeDateIfCrossDST(date, diff);

return new Date(date.getTime() - diff * dateUtils.dateToMilliseconds('hour'));
getExceptionDateTimezoneOffsets: (date: Date): [number, number, number] => {
const localMachineTimezoneOffset = -timeZoneUtils.getClientTimezoneOffset(date);

const appointmentTimezoneOffset: number = this.timeZoneCalculator.getOriginStartDateOffsetInMs(
date,
appointment.rawAppointment.startDateTimeZone,
true,
);

const offsetDST = this._getDateOffsetDST(date);
// NOTE: Apply only winter -> summer DST extra offset
const extraSummerTimeChangeOffset = offsetDST < 0
? offsetDST * toMs('hour')
: 0;

return [
localMachineTimezoneOffset,
appointmentTimezoneOffset,
extraSummerTimeChangeOffset,
];
},
};
}
Expand Down
13 changes: 6 additions & 7 deletions packages/devextreme/js/__internal/scheduler/m_recurrence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,15 @@ class RecurrenceProcessor {
.map((rule) => this.getDateByAsciiString(rule));

exceptionDates.forEach((date) => {
if (options.getPostProcessedException) {
date = options.getPostProcessedException(date);
}

const utcDate = timeZoneUtils.setOffsetsToDate(
const rruleTimezoneOffsets = typeof options.getExceptionDateTimezoneOffsets === 'function'
? options.getExceptionDateTimezoneOffsets(date)
: [-timeZoneUtils.getClientTimezoneOffset(date), options.appointmentTimezoneOffset];
const exceptionDateInPseudoUtc = timeZoneUtils.setOffsetsToDate(
date,
[-timeZoneUtils.getClientTimezoneOffset(date), options.appointmentTimezoneOffset],
rruleTimezoneOffsets,
);

this.rRuleSet!.exdate(utcDate);
this.rRuleSet!.exdate(exceptionDateInPseudoUtc);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const subscribes = {
}

if ((newCellIndex !== oldCellIndex) || isDragAndDropBetweenComponents || movedBetweenAllDayAndSimple) {
this._checkRecurringAppointment(rawAppointment, targetedRawAppointment, info.sourceAppointment.exceptionDate, () => {
this._checkRecurringAppointment(rawAppointment, targetedRawAppointment, info.sourceAppointment.startDate, () => {
this._updateAppointment(rawAppointment, targetedRawAppointment, function () {
this._appointments.moveAppointmentBack(event);
}, event);
Expand Down
Loading