From fa43898afca722e839e9fade713de61b46b773fb Mon Sep 17 00:00:00 2001 From: Jijun Leng <962285+jjleng@users.noreply.github.com> Date: Mon, 7 Apr 2025 13:34:11 -0700 Subject: [PATCH] fix: convert commit date string to iso8601 --- .../components/snapshot-view/commits-list.tsx | 3 ++- cp-webapp/src/lib/utils.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cp-webapp/src/components/snapshot-view/commits-list.tsx b/cp-webapp/src/components/snapshot-view/commits-list.tsx index 4e9519c..6cf7f73 100644 --- a/cp-webapp/src/components/snapshot-view/commits-list.tsx +++ b/cp-webapp/src/components/snapshot-view/commits-list.tsx @@ -22,6 +22,7 @@ import { Commit } from '@/generated/runner/types.gen'; import { GitCommit } from 'lucide-react'; import React, { useEffect, useState } from 'react'; import { useSnapshotContext } from './context'; +import { convertToISO8601 } from '@/lib/utils'; interface CommitsListProps { commits: Commit[]; @@ -156,7 +157,7 @@ export const CommitsList: React.FC = ({
{commit.message}
- {new Date(commit.date).toLocaleString(undefined, { + {new Date(convertToISO8601(commit.date)).toLocaleString(undefined, { year: 'numeric', month: 'numeric', day: 'numeric', diff --git a/cp-webapp/src/lib/utils.ts b/cp-webapp/src/lib/utils.ts index 1d69642..3e8ddd4 100644 --- a/cp-webapp/src/lib/utils.ts +++ b/cp-webapp/src/lib/utils.ts @@ -21,3 +21,21 @@ export function getProxiedImageUrl(url: string) { // Using Cloudflare's proxy service return `https://images.1choice.ai?url=${encodeURIComponent(url)}`; } + +export function convertToISO8601(dateString: string): string { + // Check if the input string matches the expected format + const regex = /^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) ([+-]\d{4})$/; + const match = dateString.match(regex); + + if (!match) { + throw new Error('Invalid date format. Expected format: YYYY-MM-DD HH:MM:SS ±HHMM'); + } + + const [, datePart, timePart, timezonePart] = match; + + // Insert 'T' between date and time + // Format timezone offset by inserting a colon (e.g., -0800 -> -08:00) + const formattedTimezone = `${timezonePart.slice(0, 3)}:${timezonePart.slice(3)}`; + + return `${datePart}T${timePart}${formattedTimezone}`; +}