Skip to content

fix(frontend): show local date in history cards (matches displayed time)#720

Open
Osamaali313 wants to merge 1 commit into
666ghj:mainfrom
Osamaali313:fix/history-local-date
Open

fix(frontend): show local date in history cards (matches displayed time)#720
Osamaali313 wants to merge 1 commit into
666ghj:mainfrom
Osamaali313:fix/history-local-date

Conversation

@Osamaali313

Copy link
Copy Markdown

Problem

In frontend/src/components/HistoryDatabase.vue, the history card's date and time are derived from different time zones, so they can disagree by up to a day.

const formatDate = (dateStr) => {           // UTC
  const date = new Date(dateStr)
  return date.toISOString().slice(0, 10)
}
const formatTime = (dateStr) => {           // local
  const date = new Date(dateStr)
  return `${date.getHours()...}:${date.getMinutes()...}`
}

created_at is a naive-local timestamp (datetime.now().isoformat()), returned verbatim by the history API. new Date("2026-07-08T01:00:00") is parsed as local; formatTime shows the local clock, but formatDate's toISOString() converts to UTC first. For any non-UTC client the day can shift — e.g. for the project's UTC+8 audience, a record created between 00:00 and 08:00 local shows yesterday's date next to today's time.

Fix

Derive the date from local components, matching formatTime:

const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${year}-${month}-${day}`

Verification

Extracted both helpers and ran them under Node on a UTC+3 machine with the naive timestamp 2026-07-08T01:00:00:

  • formatTime01:00 (local, July 8)
  • Before: formatDate2026-07-07 (UTC) — wrong day
  • After: formatDate2026-07-08 — matches the time shown

Under TZ=UTC the discrepancy disappears in both versions, confirming the time zone was the sole cause. (No frontend test suite exists; happy to add a vitest case if you set one up.)

HistoryDatabase.vue formatDate() derived the day from UTC
(new Date(dateStr).toISOString().slice(0, 10)) while the sibling
formatTime() uses local hours/minutes. The backend sends naive-local
timestamps (datetime.now().isoformat()), so for any non-UTC client the
two disagree by up to a day -- e.g. for the project's UTC+8 audience a
record created 00:00-08:00 local shows the previous day's date next to
the current time. Derive the date from local components so it matches
the time shown.
Copilot AI review requested due to automatic review settings July 9, 2026 20:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants