gpt-engineer-app[bot] commited on
Commit
67688f8
·
1 Parent(s): 64b8b1b

Fix: Invalid time value error in CalendarPage

Browse files

The `CalendarPage` component was throwing an `Invalid time value` error. This commit addresses the error.

Files changed (1) hide show
  1. src/pages/Calendar.tsx +30 -9
src/pages/Calendar.tsx CHANGED
@@ -9,15 +9,30 @@ import { parseISO, format, isValid } from "date-fns";
9
  const CalendarPage = () => {
10
  const [selectedDate, setSelectedDate] = useState<Date | undefined>(new Date());
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  // Get all unique dates (deadlines and conference dates)
13
  const getDatesWithEvents = () => {
14
  const dates = new Set<string>();
15
  conferencesData.forEach((conf: Conference) => {
16
- if (conf.deadline && conf.deadline !== 'TBD' && isValid(parseISO(conf.deadline))) {
17
- dates.add(format(parseISO(conf.deadline), 'yyyy-MM-dd'));
 
 
 
18
  }
19
- if (conf.start && isValid(parseISO(conf.start))) {
20
- dates.add(format(parseISO(conf.start), 'yyyy-MM-dd'));
21
  }
22
  });
23
  return Array.from(dates).map(date => parseISO(date));
@@ -27,9 +42,13 @@ const CalendarPage = () => {
27
  const getConferencesForDate = (date: Date) => {
28
  const formattedDate = format(date, 'yyyy-MM-dd');
29
  return conferencesData.filter((conf: Conference) => {
30
- const deadlineDate = conf.deadline && conf.deadline !== 'TBD' ? format(parseISO(conf.deadline), 'yyyy-MM-dd') : null;
31
- const startDate = conf.start ? format(parseISO(conf.start), 'yyyy-MM-dd') : null;
32
- return deadlineDate === formattedDate || startDate === formattedDate;
 
 
 
 
33
  });
34
  };
35
 
@@ -72,10 +91,12 @@ const CalendarPage = () => {
72
  {selectedDateConferences.map((conf: Conference) => (
73
  <div key={conf.id} className="bg-white p-4 rounded-lg shadow-sm">
74
  <h3 className="font-semibold text-lg">{conf.title}</h3>
75
- {conf.deadline && format(parseISO(conf.deadline), 'yyyy-MM-dd') === format(selectedDate, 'yyyy-MM-dd') && (
 
76
  <p className="text-red-600">Submission Deadline</p>
77
  )}
78
- {conf.start && format(parseISO(conf.start), 'yyyy-MM-dd') === format(selectedDate, 'yyyy-MM-dd') && (
 
79
  <p className="text-green-600">Conference Start Date</p>
80
  )}
81
  <div className="mt-2 flex flex-wrap gap-2">
 
9
  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
+ // Try to parse the date, handling different formats
17
+ const normalizedDate = dateString.replace(/(\d{4})-(\d{1})-(\d{1,2})/, '$1-0$2-$3')
18
+ .replace(/(\d{4})-(\d{2})-(\d{1})/, '$1-$2-0$3');
19
+
20
+ const parsedDate = parseISO(normalizedDate);
21
+ return isValid(parsedDate) ? parsedDate : null;
22
+ };
23
+
24
  // Get all unique dates (deadlines and conference dates)
25
  const getDatesWithEvents = () => {
26
  const dates = new Set<string>();
27
  conferencesData.forEach((conf: Conference) => {
28
+ const deadlineDate = safeParseISO(conf.deadline);
29
+ const startDate = safeParseISO(conf.start);
30
+
31
+ if (deadlineDate) {
32
+ dates.add(format(deadlineDate, 'yyyy-MM-dd'));
33
  }
34
+ if (startDate) {
35
+ dates.add(format(startDate, 'yyyy-MM-dd'));
36
  }
37
  });
38
  return Array.from(dates).map(date => parseISO(date));
 
42
  const getConferencesForDate = (date: Date) => {
43
  const formattedDate = format(date, 'yyyy-MM-dd');
44
  return conferencesData.filter((conf: Conference) => {
45
+ const deadlineDate = safeParseISO(conf.deadline);
46
+ const startDate = safeParseISO(conf.start);
47
+
48
+ const deadlineDateStr = deadlineDate ? format(deadlineDate, 'yyyy-MM-dd') : null;
49
+ const startDateStr = startDate ? format(startDate, 'yyyy-MM-dd') : null;
50
+
51
+ return deadlineDateStr === formattedDate || startDateStr === formattedDate;
52
  });
53
  };
54
 
 
91
  {selectedDateConferences.map((conf: Conference) => (
92
  <div key={conf.id} className="bg-white p-4 rounded-lg shadow-sm">
93
  <h3 className="font-semibold text-lg">{conf.title}</h3>
94
+ {conf.deadline && safeParseISO(conf.deadline) &&
95
+ format(safeParseISO(conf.deadline)!, 'yyyy-MM-dd') === format(selectedDate, 'yyyy-MM-dd') && (
96
  <p className="text-red-600">Submission Deadline</p>
97
  )}
98
+ {conf.start && safeParseISO(conf.start) &&
99
+ format(safeParseISO(conf.start)!, 'yyyy-MM-dd') === format(selectedDate, 'yyyy-MM-dd') && (
100
  <p className="text-green-600">Conference Start Date</p>
101
  )}
102
  <div className="mt-2 flex flex-wrap gap-2">