Spaces:
Running
Running
gpt-engineer-app[bot]
commited on
Commit
·
5251633
1
Parent(s):
67688f8
Fix: TypeError in CalendarPage
Browse filesThe `safeParseISO` function in `Calendar.tsx` was throwing a `TypeError: dateString.replace is not a function` error. This commit addresses the error.
- src/pages/Calendar.tsx +14 -6
src/pages/Calendar.tsx
CHANGED
@@ -10,15 +10,23 @@ const CalendarPage = () => {
|
|
10 |
const [selectedDate, setSelectedDate] = useState<Date | undefined>(new Date());
|
11 |
|
12 |
// Helper function to safely parse dates
|
13 |
-
const safeParseISO = (dateString: string | undefined): Date | null => {
|
14 |
if (!dateString || dateString === 'TBD') return null;
|
15 |
|
16 |
-
//
|
17 |
-
const
|
18 |
-
.replace(/(\d{4})-(\d{2})-(\d{1})/, '$1-$2-0$3');
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
};
|
23 |
|
24 |
// Get all unique dates (deadlines and conference dates)
|
|
|
10 |
const [selectedDate, setSelectedDate] = useState<Date | undefined>(new Date());
|
11 |
|
12 |
// Helper function to safely parse dates
|
13 |
+
const safeParseISO = (dateString: string | undefined | number): Date | null => {
|
14 |
if (!dateString || dateString === 'TBD') return null;
|
15 |
|
16 |
+
// Convert to string if it's a number
|
17 |
+
const dateStr = typeof dateString === 'number' ? dateString.toString() : dateString;
|
|
|
18 |
|
19 |
+
try {
|
20 |
+
// Try to parse the date, handling different formats
|
21 |
+
const normalizedDate = dateStr.replace(/(\d{4})-(\d{1})-(\d{1,2})/, '$1-0$2-$3')
|
22 |
+
.replace(/(\d{4})-(\d{2})-(\d{1})/, '$1-$2-0$3');
|
23 |
+
|
24 |
+
const parsedDate = parseISO(normalizedDate);
|
25 |
+
return isValid(parsedDate) ? parsedDate : null;
|
26 |
+
} catch (error) {
|
27 |
+
console.error("Error parsing date:", dateString);
|
28 |
+
return null;
|
29 |
+
}
|
30 |
};
|
31 |
|
32 |
// Get all unique dates (deadlines and conference dates)
|