fix: parse dates as UTC for correct local time display

Backend returns UTC dates without timezone indicator. Added
parseUTCDate helper that appends 'Z' to ensure JavaScript
correctly interprets dates as UTC and converts to local time.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
michael 2025-12-27 07:32:25 -06:00
parent 0966ce717c
commit be660bbcff

View file

@ -31,6 +31,15 @@ const STATUS_LABELS: Record<string, string> = {
const getStatusLabel = (status: string): string => STATUS_LABELS[status] || status;
// Parse date string as UTC (backend returns UTC dates without timezone indicator)
const parseUTCDate = (dateString: string): Date => {
// If the date string doesn't have timezone info, treat it as UTC
if (!dateString.endsWith('Z') && !dateString.includes('+') && !dateString.includes('-', 10)) {
return new Date(dateString + 'Z');
}
return new Date(dateString);
};
// Date range filter options
const DATE_RANGE_OPTIONS = [
{ value: '', label: 'All Time' },
@ -178,10 +187,10 @@ export function JobsList() {
const now = new Date();
if (dateRangeFilter === 'last7') {
const cutoff = subDays(now, 7);
jobs = jobs.filter((job: Job) => isAfter(new Date(job.created_at), cutoff));
jobs = jobs.filter((job: Job) => isAfter(parseUTCDate(job.created_at), cutoff));
} else if (dateRangeFilter === 'last30') {
const cutoff = subDays(now, 30);
jobs = jobs.filter((job: Job) => isAfter(new Date(job.created_at), cutoff));
jobs = jobs.filter((job: Job) => isAfter(parseUTCDate(job.created_at), cutoff));
}
}
@ -197,7 +206,7 @@ export function JobsList() {
comparison = (a.created_by_name || '').localeCompare(b.created_by_name || '');
break;
case 'created_at':
comparison = new Date(a.created_at).getTime() - new Date(b.created_at).getTime();
comparison = parseUTCDate(a.created_at).getTime() - parseUTCDate(b.created_at).getTime();
break;
case 'status':
comparison = a.status.localeCompare(b.status);
@ -786,7 +795,7 @@ export function JobsList() {
</td>
{/* Date Created */}
<td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{formatDistanceToNow(new Date(job.created_at))} ago
{formatDistanceToNow(parseUTCDate(job.created_at))} ago
</td>
{/* Languages Count */}
<td className="px-4 py-4 whitespace-nowrap text-sm text-gray-500">