mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 02:11:14 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
46
src-old/components/ui/flexible-date-display.tsx
Normal file
46
src-old/components/ui/flexible-date-display.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { format } from 'date-fns';
|
||||
import { parseDateForDisplay } from '@/lib/dateUtils';
|
||||
import type { DatePrecision } from './flexible-date-input';
|
||||
|
||||
interface FlexibleDateDisplayProps {
|
||||
date?: string | Date | null;
|
||||
precision?: DatePrecision;
|
||||
fallback?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function FlexibleDateDisplay({
|
||||
date,
|
||||
precision = 'day',
|
||||
fallback = 'Unknown',
|
||||
className
|
||||
}: FlexibleDateDisplayProps) {
|
||||
if (!date) {
|
||||
return <span className={className || "text-muted-foreground"}>{fallback}</span>;
|
||||
}
|
||||
|
||||
// ⚠️ IMPORTANT: Use parseDateForDisplay to prevent timezone shifts
|
||||
// YYYY-MM-DD strings must be interpreted as local dates, not UTC
|
||||
const dateObj = parseDateForDisplay(date);
|
||||
|
||||
// Check for invalid date
|
||||
if (isNaN(dateObj.getTime())) {
|
||||
return <span className={className || "text-muted-foreground"}>{fallback}</span>;
|
||||
}
|
||||
|
||||
let formatted: string;
|
||||
switch (precision) {
|
||||
case 'year':
|
||||
formatted = format(dateObj, 'yyyy');
|
||||
break;
|
||||
case 'month':
|
||||
formatted = format(dateObj, 'MMMM yyyy');
|
||||
break;
|
||||
case 'day':
|
||||
default:
|
||||
formatted = format(dateObj, 'PPP');
|
||||
break;
|
||||
}
|
||||
|
||||
return <span className={className}>{formatted}</span>;
|
||||
}
|
||||
Reference in New Issue
Block a user