diff --git a/awx/ui/src/components/Schedule/shared/ScheduleForm.js b/awx/ui/src/components/Schedule/shared/ScheduleForm.js index efbb599a603b..08e304813067 100644 --- a/awx/ui/src/components/Schedule/shared/ScheduleForm.js +++ b/awx/ui/src/components/Schedule/shared/ScheduleForm.js @@ -556,10 +556,12 @@ function ScheduleForm({ const { end, endDate, + endTime, frequency, runOn, runOnDayNumber, startDate, + startTime, } = values; if ( @@ -577,7 +579,14 @@ function ScheduleForm({ if ( end === 'onDate' && - DateTime.fromISO(startDate) >= DateTime.fromISO(endDate) + DateTime.fromFormat( + `${startDate} ${startTime}`, + 'yyyy-LL-dd h:mm a' + ).toMillis() >= + DateTime.fromFormat( + `${endDate} ${endTime}`, + 'yyyy-LL-dd h:mm a' + ).toMillis() ) { errors.endDate = t`Please select an end date/time that comes after the start date/time.`; } diff --git a/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js b/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js index 5ee5d8afd4c2..f49435f5964c 100644 --- a/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js +++ b/awx/ui/src/components/Schedule/shared/ScheduleForm.test.js @@ -735,6 +735,36 @@ describe('', () => { ); }); + test('should create schedule with the same start and end date provided that the end date is at a later time', async () => { + const today = DateTime.now().toFormat('yyyy-LL-dd'); + const laterTime = DateTime.now().plus({ hours: 1 }).toFormat('h:mm a'); + await act(async () => { + wrapper.find('DatePicker[aria-label="End date"]').prop('onChange')( + today, + new Date(today) + ); + }); + wrapper.update(); + expect( + wrapper + .find('FormGroup[data-cy="schedule-End date/time"]') + .prop('helperTextInvalid') + ).toBe( + 'Please select an end date/time that comes after the start date/time.' + ); + await act(async () => { + wrapper.find('TimePicker[aria-label="End time"]').prop('onChange')( + laterTime + ); + }); + wrapper.update(); + expect( + wrapper + .find('FormGroup[data-cy="schedule-End date/time"]') + .prop('helperTextInvalid') + ).toBe(undefined); + }); + test('error shown when on day number is not between 1 and 31', async () => { act(() => { wrapper.find('select[id="schedule-frequency"]').invoke('onChange')(