Skip to content

Commit 6c8ae80

Browse files
move helpers to global date util
1 parent 15c31f1 commit 6c8ae80

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/main/webapp/app/lecture/manage/lecture-series-create/lecture-series-create.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { LectureCreateDTO } from 'app/lecture/shared/entities/lecture.model';
1818
import { TranslateDirective } from 'app/shared/language/translate.directive';
1919
import { TranslateService } from '@ngx-translate/core';
2020
import { getCurrentLocaleSignal } from 'app/shared/util/global.utils';
21-
import { addOneMinuteTo, isFirstAfterOrEqualSecond } from 'app/lecture/manage/util/lecture-management.utils';
21+
import { addOneMinuteTo, isFirstDateAfterOrEqualSecond } from 'app/shared/util/date.utils';
2222
import { finalize } from 'rxjs';
2323

2424
type WeekdayIndex = 1 | 2 | 3 | 4 | 5 | 6 | 7;
@@ -83,7 +83,7 @@ export class LectureSeriesCreateComponent {
8383
startDate = signal<Date | undefined>(undefined);
8484
endDate = signal<Date | undefined>(undefined);
8585
minimumEndDate = computed(() => addOneMinuteTo(this.startDate()) ?? new Date());
86-
isEndDateInvalid = computed(() => isFirstAfterOrEqualSecond(this.startDate(), this.endDate()));
86+
isEndDateInvalid = computed(() => isFirstDateAfterOrEqualSecond(this.startDate(), this.endDate()));
8787
isLoading = signal(false);
8888
areInputsInvalid = computed(() => this.isStartAndEndTimeCombinationInvalid() || this.isEndDateInvalid());
8989

src/main/webapp/app/lecture/manage/lecture-series-edit-modal/lecture-series-edit-modal.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dayjs, { Dayjs } from 'dayjs/esm';
1010
import { TranslateService } from '@ngx-translate/core';
1111
import { TranslateDirective } from 'app/shared/language/translate.directive';
1212
import { getCurrentLocaleSignal } from 'app/shared/util/global.utils';
13-
import { addOneMinuteTo, isFirstAfterOrEqualSecond } from 'app/lecture/manage/util/lecture-management.utils';
13+
import { addOneMinuteTo, isFirstDateAfterOrEqualSecond } from 'app/shared/util/date.utils';
1414

1515
@Component({
1616
selector: 'jhi-lecture-series-edit-modal',
@@ -28,10 +28,10 @@ export class LectureSeriesEditModalComponent {
2828
visibleDate = signal<Date | undefined>(undefined);
2929
startDate = signal<Date | undefined>(undefined);
3030
minimumStartDate = computed(() => addOneMinuteTo(this.visibleDate()));
31-
isStartDateInvalid = computed(() => isFirstAfterOrEqualSecond(this.visibleDate(), this.startDate()));
31+
isStartDateInvalid = computed(() => isFirstDateAfterOrEqualSecond(this.visibleDate(), this.startDate()));
3232
endDate = signal<Date | undefined>(undefined);
3333
minimumEndDate = computed(() => addOneMinuteTo(this.startDate()) ?? addOneMinuteTo(this.visibleDate()));
34-
isEndDateInvalid = computed(() => isFirstAfterOrEqualSecond(this.visibleDate(), this.endDate()) || isFirstAfterOrEqualSecond(this.startDate(), this.endDate()));
34+
isEndDateInvalid = computed(() => isFirstDateAfterOrEqualSecond(this.visibleDate(), this.endDate()) || isFirstDateAfterOrEqualSecond(this.startDate(), this.endDate()));
3535
show = signal<boolean>(false);
3636
areInputsInvalid = computed(() => this.isTitleInvalid() || this.isStartDateInvalid() || this.isEndDateInvalid());
3737
headerTitle = computed<string>(() => {

src/main/webapp/app/lecture/manage/util/lecture-management.utils.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/main/webapp/app/shared/util/date.utils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,19 @@ export function isDateLessThanAWeekInTheFuture(date: dayjs.Dayjs, compareTime?:
7979
const now = compareTime ?? dayjs();
8080
return date.isBetween(now.add(1, 'week'), now);
8181
}
82+
83+
export function isFirstDateAfterOrEqualSecond(firstDate?: Date, secondDate?: Date): boolean {
84+
if (!firstDate || !secondDate) {
85+
return false;
86+
}
87+
return firstDate.getTime() >= secondDate.getTime();
88+
}
89+
90+
export function addOneMinuteTo(referenceDate?: Date) {
91+
if (!referenceDate) {
92+
return undefined;
93+
}
94+
const minimumDate = new Date(referenceDate.getTime());
95+
minimumDate.setMinutes(minimumDate.getMinutes() + 1);
96+
return minimumDate;
97+
}

0 commit comments

Comments
 (0)