Skip to content

Commit

Permalink
Scheduler - Toggling the All day switch should not change the End Dat…
Browse files Browse the repository at this point in the history
…e value (T1167123) (#25596)
  • Loading branch information
markallenramirez authored Sep 19, 2023
1 parent 780311e commit 413891f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/devextreme/js/__internal/scheduler/m_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ class Scheduler extends Widget<any> {

getFirstDayOfWeek: () => this.option('firstDayOfWeek'),
getStartDayHour: () => this.option('startDayHour'),
getCalculatedEndDate: (startDateWithStartHour) => this._workSpace.calculateEndDate(startDateWithStartHour),
getCalculatedEndDate: (date) => this._workSpace.calculateEndDate(date),
getTimeZoneCalculator: () => this.timeZoneCalculator,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -1211,15 +1211,15 @@ 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);

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) {
Expand Down

0 comments on commit 413891f

Please sign in to comment.