Skip to content

fix(admin): parse SQLite timestamps as UTC#1121

Open
eyupcanakman wants to merge 1 commit into
emdash-cms:mainfrom
eyupcanakman:fix/revision-date-utc-parsing
Open

fix(admin): parse SQLite timestamps as UTC#1121
eyupcanakman wants to merge 1 commit into
emdash-cms:mainfrom
eyupcanakman:fix/revision-date-utc-parsing

Conversation

@eyupcanakman
Copy link
Copy Markdown
Contributor

What does this PR do?

Admin revision timestamps showed the wrong relative and absolute date on SQLite-backed sites. datetime('now') stores values as YYYY-MM-DD HH:MM:SS with no timezone suffix, and new Date() parses that form as local time, so a revision created seconds ago rendered as hours ago for any viewer not on UTC.

parseTimestamp in packages/admin/src/lib/utils.ts now treats a timestamp with no Z or numeric offset as UTC, matching the replace(" ", "T") + "Z" form already used in the WXR importer. formatRelativeTime and the revision panel's formatFullDate both parse through it. Values that already carry a timezone are returned unchanged.

The admin browser tests run on a UTC CI runner, where parsing as local time gives the same result as UTC, so the bug would slip through. The vitest config now pins a non-UTC timezoneId so the parseTimestamp tests exercise the offset path.

Closes #919

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.7

Screenshots / test output

✓ tests/lib/utils.test.ts (19 tests)

Test Files  1 passed (1)
     Tests  19 passed (19)

SQLite datetime('now') stores timestamps with no timezone suffix, which new Date() reads as local time.
Revision and dashboard timestamps in the admin UI drifted by the viewer's offset.

Closes emdash-cms#919
Copilot AI review requested due to automatic review settings May 20, 2026 18:46
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

🦋 Changeset detected

Latest commit: 4a27b66

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 20, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1121

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1121

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1121

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1121

emdash

npm i https://pkg.pr.new/emdash@1121

create-emdash

npm i https://pkg.pr.new/create-emdash@1121

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1121

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1121

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1121

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1121

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1121

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1121

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1121

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1121

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1121

commit: 4a27b66

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect admin-side timestamp rendering for SQLite-backed sites by ensuring “naive” DB timestamps (no timezone suffix) are interpreted as UTC in the admin UI, and by adjusting browser test execution to catch local-vs-UTC parsing differences.

Changes:

  • Add parseTimestamp() utility that treats timestamps without Z/offset as UTC and route relative/full-date formatting through it.
  • Update revision history and dashboard relative-time formatting to use the normalized timestamp parser.
  • Pin Vitest browser timezone to a non-UTC zone and add unit tests covering SQLite, Z, offsets, and Postgres-style offsets.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/admin/vitest.config.ts Pins Playwright browser context timezone to ensure timestamp parsing bugs are caught in CI.
packages/admin/tests/lib/utils.test.ts Adds parseTimestamp test coverage for naive SQLite timestamps and zoned variants.
packages/admin/src/lib/utils.ts Introduces parseTimestamp and updates formatRelativeTime to use it.
packages/admin/src/components/RevisionHistory.tsx Uses parseTimestamp for full timestamp display in revision history UI.
.changeset/fix-revision-date-utc.md Adds a patch changeset describing the admin timestamp fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +33
const hasZone = TIMEZONE_DESIGNATOR_PATTERN.test(value);
if (hasTime && !hasZone) {
return new Date(value.replace(" ", "T") + "Z");
}
return new Date(value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revisions show incorrect date

2 participants