From 413891f6112798520959be1416686300efab055b Mon Sep 17 00:00:00 2001 From: Mark Allen Ramirez Date: Tue, 19 Sep 2023 15:41:26 +0800 Subject: [PATCH] Scheduler - Toggling the All day switch should not change the End Date value (T1167123) (#25596) --- .../scheduler/appointment_popup/m_form.ts | 13 ++++++++----- .../js/__internal/scheduler/m_scheduler.ts | 2 +- .../appointmentPopup.tests.js | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/devextreme/js/__internal/scheduler/appointment_popup/m_form.ts b/packages/devextreme/js/__internal/scheduler/appointment_popup/m_form.ts index df1c65236567..5e76203bbec0 100644 --- a/packages/devextreme/js/__internal/scheduler/appointment_popup/m_form.ts +++ b/packages/devextreme/js/__internal/scheduler/appointment_popup/m_form.ts @@ -24,7 +24,7 @@ export const APPOINTMENT_FORM_GROUP_NAMES = { Recurrence: 'recurrenceGroup', }; -const getStartDateWithStartHour = (startDate, startDayHour) => new Date(new Date(startDate).setHours(startDayHour)); +const getDateWithStartHour = (date, startDayHour) => new Date(new Date(date).setHours(startDayHour)); const validateAppointmentFormDate = (editor, value, previousValue) => { const isCurrentDateCorrect = value === null || !!value; @@ -300,17 +300,20 @@ export class AppointmentForm { const startDateEditor = this.form.getEditor(dataExprs.startDateExpr); const endDateEditor = this.form.getEditor(dataExprs.endDateExpr); const startDate = dateSerialization.deserializeDate(startDateEditor.option('value')); + const endDate = dateSerialization.deserializeDate(endDateEditor.option('value')); if (this.semaphore.isFree() && startDate) { if (value) { const allDayStartDate = dateUtils.trimTime(startDate); + const allDayEndDate = dateUtils.trimTime(endDate); startDateEditor.option('value', new Date(allDayStartDate)); - endDateEditor.option('value', new Date(allDayStartDate)); + endDateEditor.option('value', new Date(allDayEndDate)); } else { - const startDateWithStartHour = getStartDateWithStartHour(startDate, this.scheduler.getStartDayHour()); - const endDate = this.scheduler.getCalculatedEndDate(startDateWithStartHour); + const startDateWithStartHour = getDateWithStartHour(startDate, this.scheduler.getStartDayHour()); + const endDateWithStartHour = getDateWithStartHour(endDate, this.scheduler.getStartDayHour()); + const calculatedEndDate = this.scheduler.getCalculatedEndDate(endDateWithStartHour); startDateEditor.option('value', startDateWithStartHour); - endDateEditor.option('value', endDate); + endDateEditor.option('value', calculatedEndDate); } } diff --git a/packages/devextreme/js/__internal/scheduler/m_scheduler.ts b/packages/devextreme/js/__internal/scheduler/m_scheduler.ts index 398974b86b49..b5663fc93efe 100644 --- a/packages/devextreme/js/__internal/scheduler/m_scheduler.ts +++ b/packages/devextreme/js/__internal/scheduler/m_scheduler.ts @@ -1357,7 +1357,7 @@ class Scheduler extends Widget { getFirstDayOfWeek: () => this.option('firstDayOfWeek'), getStartDayHour: () => this.option('startDayHour'), - getCalculatedEndDate: (startDateWithStartHour) => this._workSpace.calculateEndDate(startDateWithStartHour), + getCalculatedEndDate: (date) => this._workSpace.calculateEndDate(date), getTimeZoneCalculator: () => this.timeZoneCalculator, }; diff --git a/packages/devextreme/testing/tests/DevExpress.ui.widgets.scheduler/appointmentPopup.tests.js b/packages/devextreme/testing/tests/DevExpress.ui.widgets.scheduler/appointmentPopup.tests.js index 6ab1cafe7068..0771af5574a4 100644 --- a/packages/devextreme/testing/tests/DevExpress.ui.widgets.scheduler/appointmentPopup.tests.js +++ b/packages/devextreme/testing/tests/DevExpress.ui.widgets.scheduler/appointmentPopup.tests.js @@ -1189,7 +1189,7 @@ QUnit.module('Appointment Popup Content', moduleOptions, () => { assert.equal(allDayEditor.option('value'), true, 'value is right'); }); - QUnit.test('allDay changing should switch date & type in editors', function(assert) { + QUnit.test('allDay changing should switch type, but not date in editors', function(assert) { const scheduler = createInstance({ startDayHour: 5, }); @@ -1211,7 +1211,7 @@ QUnit.module('Appointment Popup Content', moduleOptions, () => { assert.deepEqual(startDate.option('value'), new Date(2015, 1, 1), 'value is right'); assert.equal(startDate.option('type'), 'date', 'type is right'); - assert.deepEqual(endDate.option('value'), new Date(2015, 1, 1), 'value is right'); + assert.deepEqual(endDate.option('value'), new Date(2015, 1, 2), 'value is right'); assert.equal(endDate.option('type'), 'date', 'type is right'); allDayEditor.option('value', false); @@ -1219,7 +1219,7 @@ QUnit.module('Appointment Popup Content', moduleOptions, () => { assert.equal(startDate.option('type'), 'datetime', 'type is right after turning off allDay'); assert.equal(endDate.option('type'), 'datetime', 'type is right after turning off allDay'); assert.deepEqual(startDate.option('value'), new Date(2015, 1, 1, 5), 'startdate is OK'); - assert.deepEqual(endDate.option('value'), new Date(2015, 1, 1, 5, 30), 'enddate is OK'); + assert.deepEqual(endDate.option('value'), new Date(2015, 1, 2, 5, 30), 'enddate is OK'); }); QUnit.test('allDay changing should switch only type in editors, if startDate is undefined', function(assert) {