[tableSortOrder]="courseTab.studentSortOrder"
[useGrayHeading]="false"
[enableRemindButton]="true"
- (sortStudentListEvent)="sortStudentList(courseTab, $event)"
(removeStudentFromCourseEvent)="removeStudentFromCourse(courseTab, $event)">
diff --git a/src/web/services/datetime.service.spec.ts b/src/web/services/datetime.service.spec.ts
index b97421b4986..1dee9dfb5b5 100644
--- a/src/web/services/datetime.service.spec.ts
+++ b/src/web/services/datetime.service.spec.ts
@@ -1,5 +1,6 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
+import { DateFormat, TimeFormat } from '../types/datetime-const';
import { DateTimeService } from './datetime.service';
import { TimezoneService } from './timezone.service';
@@ -77,4 +78,76 @@ describe('DateTimeService', () => {
expect(result.minute).toEqual(59);
});
+ it('should return 1 if the first date\'s year is later than the second date\'s year', () => {
+ const firstDate : DateFormat = { year: 2023, month: 8, day: 23 };
+ const secondDate: DateFormat = { year: 2022, month: 8, day: 23 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(1);
+ });
+
+ it('should return -1 if the first date\'s year is earlier than the second date\'s year', () => {
+ const firstDate : DateFormat = { year: 2022, month: 8, day: 23 };
+ const secondDate: DateFormat = { year: 2023, month: 8, day: 23 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(-1);
+ });
+
+ it('should return 1 if year is the same and first date\'s month is later than second date\'s month', () => {
+ const firstDate : DateFormat = { year: 2023, month: 9, day: 23 };
+ const secondDate: DateFormat = { year: 2023, month: 8, day: 23 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(1);
+ });
+
+ it('should return -1 if if year is the same and first date\'s month is earlier than second date\'s month', () => {
+ const firstDate : DateFormat = { year: 2023, month: 8, day: 23 };
+ const secondDate: DateFormat = { year: 2023, month: 9, day: 23 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(-1);
+ });
+
+ it('should return 1 if year and month are the same and first date\'s day is later than second date\'s day', () => {
+ const firstDate : DateFormat = { year: 2023, month: 9, day: 28 };
+ const secondDate: DateFormat = { year: 2023, month: 9, day: 23 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(1);
+ });
+
+ it('should return -1 if year and month are same and first date\'s day is earlier than second date\'s day', () => {
+ const firstDate : DateFormat = { year: 2023, month: 9, day: 23 };
+ const secondDate: DateFormat = { year: 2023, month: 9, day: 28 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(-1);
+ });
+
+ it('should return 0 if both dates have the same year and month and day', () => {
+ const firstDate : DateFormat = { year: 2023, month: 9, day: 28 };
+ const secondDate: DateFormat = { year: 2023, month: 9, day: 28 };
+ expect(DateTimeService.compareDateFormat(firstDate, secondDate)).toEqual(0);
+ });
+
+ it('should return 1 if the first timing\'s hour is later than the second timing\'s hour', () => {
+ const firstTime : TimeFormat = { hour: 21, minute: 0 };
+ const secondTime : TimeFormat = { hour: 19, minute: 0 };
+ expect(DateTimeService.compareTimeFormat(firstTime, secondTime)).toEqual(1);
+ });
+
+ it('should return -1 if the first timing\'s hour is earlier than the second timing\'s hour', () => {
+ const firstTime : TimeFormat = { hour: 20, minute: 0 };
+ const secondTime : TimeFormat = { hour: 21, minute: 0 };
+ expect(DateTimeService.compareTimeFormat(firstTime, secondTime)).toEqual(-1);
+ });
+
+ it('should return 1 if hour is the same and first timing\'s minute is later than second timing\'s minute', () => {
+ const firstTime : TimeFormat = { hour: 21, minute: 30 };
+ const secondTime : TimeFormat = { hour: 21, minute: 0 };
+ expect(DateTimeService.compareTimeFormat(firstTime, secondTime)).toEqual(1);
+ });
+
+ it('should return -1 if hour is same and first timing\'s minute is earlier than second timing\'s minute', () => {
+ const firstTime : TimeFormat = { hour: 21, minute: 0 };
+ const secondTime : TimeFormat = { hour: 21, minute: 30 };
+ expect(DateTimeService.compareTimeFormat(firstTime, secondTime)).toEqual(-1);
+ });
+
+ it('should return 0 if both timings have the same hour and minute', () => {
+ const firstTime : TimeFormat = { hour: 21, minute: 30 };
+ const secondTime : TimeFormat = { hour: 21, minute: 30 };
+ expect(DateTimeService.compareTimeFormat(firstTime, secondTime)).toEqual(0);
+ });
+
});
diff --git a/src/web/services/datetime.service.ts b/src/web/services/datetime.service.ts
index 9baef02632c..b6d86fcd290 100644
--- a/src/web/services/datetime.service.ts
+++ b/src/web/services/datetime.service.ts
@@ -123,4 +123,54 @@ export class DateTimeService {
minute: mmt.minute(),
};
}
+
+ /**
+ * Compares the first date with the second date and checks whether the first
+ * date is earlier, same or later than the second date.
+ * Returns 1 if the first date is later than second date, 0 if the first date is the
+ * same as the second date and -1 if the first date is earlier than the second date.
+ */
+ static compareDateFormat(firstDate : DateFormat, secondDate : DateFormat) : number {
+ if (firstDate.year > secondDate.year) {
+ return 1;
+ }
+ if (firstDate.year < secondDate.year) {
+ return -1;
+ }
+ if (firstDate.month > secondDate.month) {
+ return 1;
+ }
+ if (firstDate.month < secondDate.month) {
+ return -1;
+ }
+ if (firstDate.day > secondDate.day) {
+ return 1;
+ }
+ if (firstDate.day < secondDate.day) {
+ return -1;
+ }
+ return 0;
+ }
+
+ /**
+ * Compares the first timing with the second timing and checks whether the first
+ * timing is earlier, same or later than the second timing.
+ * Returns 1 if the first timing is later than second timing, 0 if the first timing is the
+ * same as the second timing and -1 if the first timing is earlier than the second timing.
+ */
+ static compareTimeFormat(firstTiming : TimeFormat, secondTiming : TimeFormat) : number {
+ if (firstTiming.hour > secondTiming.hour) {
+ return 1;
+ }
+ if (firstTiming.hour < secondTiming.hour) {
+ return -1;
+ }
+ if (firstTiming.minute > secondTiming.minute) {
+ return 1;
+ }
+ if (firstTiming.minute < secondTiming.minute) {
+ return -1;
+ }
+ return 0;
+ }
}