Fix timezone-independent date display

This commit is contained in:
gpt-engineer-app[bot]
2025-11-02 19:24:54 +00:00
parent 4215c8ad52
commit 0f742f36b6
7 changed files with 139 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ import { toast } from 'sonner';
import { getErrorMessage } from '@/lib/errorHandler';
import { UserRideCredit } from '@/types/database';
import { convertValueFromMetric, getDisplayUnit } from '@/lib/units';
import { parseDateForDisplay } from '@/lib/dateUtils';
import {
AlertDialog,
AlertDialogAction,
@@ -233,13 +234,14 @@ export function RideCreditCard({ credit, position, maxPosition, viewMode, isEdit
{credit.first_ride_date && (
<div className="flex items-center gap-1">
<Calendar className="w-3 h-3" />
<span>First: {format(new Date(credit.first_ride_date), 'MMM d, yyyy')}</span>
{/* ⚠️ Use parseDateForDisplay to prevent timezone shifts */}
<span>First: {format(parseDateForDisplay(credit.first_ride_date), 'MMM d, yyyy')}</span>
</div>
)}
{credit.last_ride_date && (
<div className="flex items-center gap-1">
<Calendar className="w-3 h-3" />
<span>Last: {format(new Date(credit.last_ride_date), 'MMM d, yyyy')}</span>
<span>Last: {format(parseDateForDisplay(credit.last_ride_date), 'MMM d, yyyy')}</span>
</div>
)}
</div>
@@ -410,7 +412,7 @@ export function RideCreditCard({ credit, position, maxPosition, viewMode, isEdit
{credit.first_ride_date && (
<div className="text-xs text-muted-foreground">
<Calendar className="w-3 h-3 inline mr-1" />
{format(new Date(credit.first_ride_date), 'MMM d, yyyy')}
{format(parseDateForDisplay(credit.first_ride_date), 'MMM d, yyyy')}
</div>
)}