Fix Invalid Date for datetime strings from API
The API returns dates as "2024-12-11T00:00:00" (datetime, no timezone), not bare "2024-12-11". Appending T12:00:00 directly produced an invalid string. Use .slice(0, 10) to extract the date part first before parsing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -26,12 +26,12 @@ type FilterPill = "all" | "full band" | "guitar" | "vocals" | "drums" | "keys" |
|
||||
const PILLS: FilterPill[] = ["all", "full band", "guitar", "vocals", "drums", "keys", "commented"];
|
||||
|
||||
function formatDate(iso: string): string {
|
||||
const d = new Date(iso + "T12:00:00");
|
||||
const d = new Date(iso.slice(0, 10) + "T12:00:00");
|
||||
return d.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
|
||||
}
|
||||
|
||||
function formatDateLabel(iso: string): string {
|
||||
const d = new Date(iso + "T12:00:00");
|
||||
const d = new Date(iso.slice(0, 10) + "T12:00:00");
|
||||
const today = new Date();
|
||||
today.setHours(12, 0, 0, 0);
|
||||
const diffDays = Math.round((today.getTime() - d.getTime()) / (1000 * 60 * 60 * 24));
|
||||
|
||||
@@ -24,7 +24,7 @@ interface SessionDetail {
|
||||
}
|
||||
|
||||
function formatDate(iso: string): string {
|
||||
const d = new Date(iso + "T12:00:00");
|
||||
const d = new Date(iso.slice(0, 10) + "T12:00:00");
|
||||
return d.toLocaleDateString(undefined, { weekday: "long", year: "numeric", month: "long", day: "numeric" });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user