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

Programming exercises: Use server time for exercise details dates #9755

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -17,6 +17,7 @@ import { ComplaintService } from 'app/complaints/complaint.service';
import { isDateLessThanAWeekInTheFuture } from 'app/utils/date.utils';
import { DifficultyLevelComponent } from 'app/shared/difficulty-level/difficulty-level.component';
import { ArtemisSharedCommonModule } from 'app/shared/shared-common.module';
import { ArtemisServerDateService } from 'app/shared/server-date.service';

@Component({
selector: 'jhi-exercise-headers-information',
Expand All @@ -41,15 +42,19 @@ export class ExerciseHeadersInformationComponent implements OnInit, OnChanges {
dueDate?: dayjs.Dayjs;
programmingExercise?: ProgrammingExercise;
individualComplaintDueDate?: dayjs.Dayjs;
now: dayjs.Dayjs;
achievedPoints: number = 0;
numberOfSubmissions: number;
informationBoxItems: InformationBox[] = [];

constructor(private sortService: SortService) {}
constructor(
private sortService: SortService,
private serverDateService: ArtemisServerDateService,
) {}

ngOnInit() {
this.dueDate = getExerciseDueDate(this.exercise, this.studentParticipation);

this.now = this.serverDateService.now();
if (this.course?.maxComplaintTimeDays) {
this.individualComplaintDueDate = ComplaintService.getIndividualComplaintDueDate(
this.exercise,
Expand Down Expand Up @@ -107,14 +112,12 @@ export class ExerciseHeadersInformationComponent implements OnInit, OnChanges {
}

addDueDateItems() {
const now = dayjs();

const dueDateItem = this.getDueDateItem();
if (dueDateItem) {
this.informationBoxItems.push(dueDateItem);
}
// If the due date is in the past and the assessment due date is in the future, show the assessment due date
if (this.dueDate?.isBefore(now) && this.exercise.assessmentDueDate?.isAfter(now)) {
if (this.dueDate?.isBefore(this.now) && this.exercise.assessmentDueDate?.isAfter(this.now)) {
const assessmentDueItem: InformationBox = {
title: 'artemisApp.courseOverview.exerciseDetails.assessmentDue',
content: {
Expand All @@ -123,11 +126,12 @@ export class ExerciseHeadersInformationComponent implements OnInit, OnChanges {
},
isContentComponent: true,
tooltip: 'artemisApp.courseOverview.exerciseDetails.assessmentDueTooltip',
tooltipParams: { date: this.exercise.assessmentDueDate.format('lll') },
};
this.informationBoxItems.push(assessmentDueItem);
}
// // If the assessment due date is in the past and the complaint due date is in the future, show the complaint due date
if (this.exercise.assessmentDueDate?.isBefore(now) && this.individualComplaintDueDate?.isAfter(now)) {
if (this.exercise.assessmentDueDate?.isBefore(this.now) && this.individualComplaintDueDate?.isAfter(this.now)) {
const complaintDueItem: InformationBox = {
title: 'artemisApp.courseOverview.exerciseDetails.complaintDue',
content: {
Expand All @@ -136,18 +140,19 @@ export class ExerciseHeadersInformationComponent implements OnInit, OnChanges {
},
isContentComponent: true,
tooltip: 'artemisApp.courseOverview.exerciseDetails.complaintDueTooltip',
tooltipParams: { date: this.individualComplaintDueDate.format('lll') },
};
this.informationBoxItems.push(complaintDueItem);
}
}

getDueDateItem(): InformationBox | undefined {
if (this.dueDate) {
const isDueDateInThePast = this.dueDate.isBefore(dayjs());
const isDueDateInThePast = this.dueDate.isBefore(this.now);
// If the due date is less than a day away, the color change to red
const dueDateStatusBadge = this.dueDate.isBetween(dayjs().add(1, 'day'), dayjs()) ? 'danger' : 'body-color';
const dueDateStatusBadge = this.dueDate.isBetween(this.now.add(1, 'day'), this.now) ? 'danger' : 'body-color';
// If the due date is less than a week away, text is displayed relatively e.g. 'in 2 days'
const shouldDisplayDueDateRelative = isDateLessThanAWeekInTheFuture(this.dueDate);
const shouldDisplayDueDateRelative = isDateLessThanAWeekInTheFuture(this.dueDate, this.now);

if (isDueDateInThePast) {
return {
Expand Down Expand Up @@ -175,9 +180,9 @@ export class ExerciseHeadersInformationComponent implements OnInit, OnChanges {
}

addStartDateItem() {
if (this.exercise.startDate && dayjs().isBefore(this.exercise.startDate)) {
if (this.exercise.startDate && this.now.isBefore(this.exercise.startDate)) {
// If the start date is less than a week away, text is displayed relatively e.g. 'in 2 days'
const shouldDisplayStartDateRelative = isDateLessThanAWeekInTheFuture(this.exercise.startDate);
const shouldDisplayStartDateRelative = isDateLessThanAWeekInTheFuture(this.exercise.startDate, this.now);
const startDateItem: InformationBox = {
title: 'artemisApp.courseOverview.exerciseDetails.startDate',
content: {
Expand Down Expand Up @@ -218,7 +223,7 @@ export class ExerciseHeadersInformationComponent implements OnInit, OnChanges {
}

addCategoryItems() {
const notReleased = this.exercise.releaseDate && dayjs(this.exercise.releaseDate).isAfter(dayjs());
const notReleased = this.exercise.releaseDate?.isAfter(this.now);

if (notReleased || this.exercise.includedInOverallScore !== IncludedInOverallScore.INCLUDED_COMPLETELY || this.exercise.categories?.length) {
const categoryItem: InformationBox = {
Expand Down
5 changes: 3 additions & 2 deletions src/main/webapp/app/utils/date.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function dayOfWeekZeroSundayToZeroMonday(dayOfWeekZeroSunday: number): nu
return (dayOfWeekZeroSunday + 6) % 7;
}

export function isDateLessThanAWeekInTheFuture(date: dayjs.Dayjs): boolean {
return date.isBetween(dayjs().add(1, 'week'), dayjs());
export function isDateLessThanAWeekInTheFuture(date: dayjs.Dayjs, compareTime?: dayjs.Dayjs): boolean {
const now = compareTime ?? dayjs();
return date.isBetween(now.add(1, 'week'), now);
}
Loading