Skip to content

Commit dfd2a24

Browse files
committed
bug with the dates, fixed with claude's help. oof.
1 parent b6957e9 commit dfd2a24

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

assets/js/season.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,8 @@
348348

349349
function buildSeasonDateRange(presentations, fallback) {
350350
const dates = presentations
351-
.map((presentation) => presentation.date)
351+
.map((presentation) => parseDateValue(presentation.date))
352352
.filter(Boolean)
353-
.map((value) => new Date(value))
354-
.filter((date) => !Number.isNaN(date.valueOf()))
355353
.sort((a, b) => a - b);
356354

357355
if (dates.length === 0) {
@@ -368,13 +366,13 @@
368366
}
369367

370368
function comparePresentations(a, b) {
371-
const dateA = new Date(a.date || 0).valueOf();
372-
const dateB = new Date(b.date || 0).valueOf();
373-
if (!Number.isNaN(dateA) && !Number.isNaN(dateB)) {
374-
return dateA - dateB;
369+
const dateA = parseDateValue(a.date);
370+
const dateB = parseDateValue(b.date);
371+
if (dateA && dateB) {
372+
return dateA.valueOf() - dateB.valueOf();
375373
}
376-
if (!Number.isNaN(dateA)) return -1;
377-
if (!Number.isNaN(dateB)) return 1;
374+
if (dateA) return -1;
375+
if (dateB) return 1;
378376
return String(a.title || '').localeCompare(String(b.title || ''));
379377
}
380378

@@ -392,8 +390,8 @@
392390
}
393391

394392
function formatDate(input, options = {}) {
395-
const date = input instanceof Date ? input : new Date(input);
396-
if (Number.isNaN(date.valueOf())) return String(input);
393+
const date = parseDateValue(input);
394+
if (!date) return String(input);
397395

398396
const locale = navigator.language || 'en-US';
399397
const config = { month: 'short', day: 'numeric' };
@@ -403,6 +401,23 @@
403401
return date.toLocaleDateString(locale, config);
404402
}
405403

404+
function parseDateValue(value) {
405+
if (!value) return null;
406+
if (value instanceof Date && !Number.isNaN(value.valueOf())) return value;
407+
408+
if (typeof value === 'string') {
409+
const match = value.match(/^(\d{4})-(\d{2})-(\d{2})$/);
410+
if (match) {
411+
const [, year, month, day] = match;
412+
const date = new Date(Number(year), Number(month) - 1, Number(day));
413+
if (!Number.isNaN(date.valueOf())) return date;
414+
}
415+
}
416+
417+
const parsed = new Date(value);
418+
return Number.isNaN(parsed.valueOf()) ? null : parsed;
419+
}
420+
406421
function formatResourceLabel(type) {
407422
if (!type) return 'Resource';
408423
return type.replace(/-/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase());

0 commit comments

Comments
 (0)