gpt-engineer-app[bot] commited on
Commit
019c4ee
·
1 Parent(s): d70266a

Fix: Invalid time value error

Browse files

The `CalendarPage` component throws an `Invalid time value` error. This commit aims to resolve the error.

Files changed (1) hide show
  1. src/pages/Calendar.tsx +48 -31
src/pages/Calendar.tsx CHANGED
@@ -13,12 +13,23 @@ const CalendarPage = () => {
13
 
14
  // Helper function to safely parse dates
15
  const safeParseISO = (dateString: string | undefined | number): Date | null => {
16
- if (!dateString || dateString === 'TBD') return null;
17
- const dateStr = typeof dateString === 'number' ? dateString.toString() : dateString;
18
 
19
  try {
20
- const normalizedDate = dateStr.replace(/(\d{4})-(\d{1})-(\d{1,2})/, '$1-0$2-$3')
21
- .replace(/(\d{4})-(\d{2})-(\d{1})/, '$1-$2-0$3');
 
 
 
 
 
 
 
 
 
 
 
22
  const parsedDate = parseISO(normalizedDate);
23
  return isValid(parsedDate) ? parsedDate : null;
24
  } catch (error) {
@@ -182,34 +193,40 @@ const CalendarPage = () => {
182
  Events in {format(selectedDate, isYearView ? 'yyyy' : 'MMMM yyyy')}
183
  </h2>
184
  <div className="space-y-4">
185
- {events.map((conf: Conference) => (
186
- <div key={conf.id} className="bg-white p-4 rounded-lg shadow-sm">
187
- <h3 className="font-semibold text-lg">{conf.title}</h3>
188
- <div className="space-y-1">
189
- {conf.deadline && safeParseISO(conf.deadline) && (
190
- <p className="text-red-500">
191
- Submission Deadline: {format(safeParseISO(conf.deadline)!, 'MMMM d, yyyy')}
192
- </p>
193
- )}
194
- {conf.start && (
195
- <p className="text-purple-600">
196
- Conference Date: {format(safeParseISO(conf.start)!, 'MMMM d')}
197
- {conf.end ? ` - ${format(safeParseISO(conf.end)!, 'MMMM d, yyyy')}` :
198
- `, ${format(safeParseISO(conf.start)!, 'yyyy')}`}
199
- </p>
200
- )}
201
- </div>
202
- <div className="mt-2 flex flex-wrap gap-2">
203
- {conf.tags.map((tag) => (
204
- <span key={tag} className="inline-flex items-center px-2 py-1 rounded-full
205
- text-xs bg-neutral-100">
206
- <Tag className="h-3 w-3 mr-1" />
207
- {tag}
208
- </span>
209
- ))}
 
 
 
 
 
 
210
  </div>
211
- </div>
212
- ))}
213
  </div>
214
  </div>
215
  )}
 
13
 
14
  // Helper function to safely parse dates
15
  const safeParseISO = (dateString: string | undefined | number): Date | null => {
16
+ if (!dateString) return null;
17
+ if (dateString === 'TBD') return null;
18
 
19
  try {
20
+ // If it's a Date object wrapped in a stringified object (from console logs)
21
+ if (typeof dateString === 'object') {
22
+ return null;
23
+ }
24
+
25
+ // Convert number to string if needed
26
+ const dateStr = typeof dateString === 'number' ? dateString.toString() : dateString;
27
+
28
+ // Add leading zeros to single-digit months and days
29
+ const normalizedDate = dateStr
30
+ .replace(/(\d{4})-(\d{1})-(\d{1,2})/, '$1-0$2-0$3')
31
+ .replace(/(\d{4})-(\d{2})-(\d{1})/, '$1-$2-0$1');
32
+
33
  const parsedDate = parseISO(normalizedDate);
34
  return isValid(parsedDate) ? parsedDate : null;
35
  } catch (error) {
 
193
  Events in {format(selectedDate, isYearView ? 'yyyy' : 'MMMM yyyy')}
194
  </h2>
195
  <div className="space-y-4">
196
+ {events.map((conf: Conference) => {
197
+ const deadlineDate = safeParseISO(conf.deadline);
198
+ const startDate = safeParseISO(conf.start);
199
+ const endDate = safeParseISO(conf.end);
200
+
201
+ return (
202
+ <div key={conf.id} className="bg-white p-4 rounded-lg shadow-sm">
203
+ <h3 className="font-semibold text-lg">{conf.title}</h3>
204
+ <div className="space-y-1">
205
+ {deadlineDate && (
206
+ <p className="text-red-500">
207
+ Submission Deadline: {format(deadlineDate, 'MMMM d, yyyy')}
208
+ </p>
209
+ )}
210
+ {startDate && (
211
+ <p className="text-purple-600">
212
+ Conference Date: {format(startDate, 'MMMM d')}
213
+ {endDate ? ` - ${format(endDate, 'MMMM d, yyyy')}` :
214
+ `, ${format(startDate, 'yyyy')}`}
215
+ </p>
216
+ )}
217
+ </div>
218
+ <div className="mt-2 flex flex-wrap gap-2">
219
+ {conf.tags.map((tag) => (
220
+ <span key={tag} className="inline-flex items-center px-2 py-1 rounded-full
221
+ text-xs bg-neutral-100">
222
+ <Tag className="h-3 w-3 mr-1" />
223
+ {tag}
224
+ </span>
225
+ ))}
226
+ </div>
227
  </div>
228
+ );
229
+ })}
230
  </div>
231
  </div>
232
  )}