Skip to content

Commit

Permalink
[#12131] Instructor edit session times: timing restrictions are not a…
Browse files Browse the repository at this point in the history
…s expected (#12133)
  • Loading branch information
samuelfangjw authored Feb 25, 2023
1 parent 83557c3 commit b294a5b
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/web/app/components/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { DateFormat, TimeFormat, getDefaultTimeFormat, getDefaultDateFormat } fr
styleUrls: ['./timepicker.component.scss'],
})
export class TimepickerComponent {

@Input()
isDisabled: boolean = false;

Expand Down Expand Up @@ -70,23 +69,35 @@ export class TimepickerComponent {
* datetime.
*/
isOptionDisabled(t: TimeFormat): boolean {
if (this.minDate && this.minTime
&& this.date.year === this.minDate?.year && this.date.month === this.minDate?.month
&& this.date.day === this.minDate?.day
&& (t.hour < this.minTime?.hour || t.minute < this.minTime?.minute)) {
return true;
const date = this.toJsDate(this.date, t);

if (this.minDate && this.minTime) {
const minDate = this.toJsDate(this.minDate, this.minTime);
if (date < minDate) {
return true;
}
}

if (this.maxDate && this.maxTime
&& this.date.year === this.maxDate?.year && this.date.month === this.maxDate?.month
&& this.date.day === this.maxDate?.day
&& (t.hour > this.maxTime?.hour || t.minute > this.maxTime?.minute)) {
return true;
if (this.maxDate && this.maxTime) {
const maxDate = this.toJsDate(this.maxDate, this.maxTime);
if (date > maxDate) {
return true;
}
}

return false;
}

private toJsDate(date: DateFormat, time: TimeFormat): Date {
return new Date(
date.year,
date.month - 1,
date.day,
time.hour,
time.minute,
);
}

/**
* Checks whether the time is in the fixed list to select.
*/
Expand Down
Loading

0 comments on commit b294a5b

Please sign in to comment.