Skip to content

Commit 89fe6c5

Browse files
authored
Merge pull request #46 from hs-shell/develop
bugfix: add validation for date range format to prevent undefined rep…
2 parents bb8ca77 + 043bc7f commit 89fe6c5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/hooks/useCourseData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function useCourseData(courses: any[]) {
101101
setIsPending(false);
102102
} catch (error) {
103103
localStorage.removeItem('lastRequestTime');
104-
// setIsError(true);
104+
setIsError(true);
105105
setIsPending(false);
106106
}
107107
}, [courses]);

src/lib/utils.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@ export function cn(...inputs: ClassValue[]) {
66
return twMerge(clsx(inputs));
77
}
88

9-
export function isCurrentDateInRange(dateRange: string) {
9+
export function isCurrentDateInRange(dateRange: string | null) {
10+
if (!dateRange || !dateRange.includes(' ~ ')) {
11+
return false;
12+
}
13+
1014
const [startStr, endStr] = dateRange.split(' ~ ');
1115

16+
if (!startStr || !endStr) {
17+
return false;
18+
}
19+
1220
const startDate = new Date(startStr.replace(/-/g, '/'));
1321
const endDate = new Date(endStr.replace(/-/g, '/'));
1422

1523
const currentDate = new Date();
1624

1725
return currentDate >= startDate && currentDate <= endDate;
1826
}
19-
export function isCurrentDateByDate(date: string) {
27+
28+
export function isCurrentDateByDate(date: string | null) {
29+
if (!date || date.length <= 1) return false;
2030
const endDate = new Date(date);
2131
const currentDate = new Date();
2232
return currentDate <= endDate;

0 commit comments

Comments
 (0)