Skip to content

fix: task timer shows wrong elapsed time in sidebar#1332

Merged
arnestrickmann merged 2 commits intogeneralaction:mainfrom
sairus2k:emdash/task-timer-9j2
Mar 6, 2026
Merged

fix: task timer shows wrong elapsed time in sidebar#1332
arnestrickmann merged 2 commits intogeneralaction:mainfrom
sairus2k:emdash/task-timer-9j2

Conversation

@sairus2k
Copy link
Contributor

@sairus2k sairus2k commented Mar 6, 2026

Summary

Task timer in sidebar shows wrong elapsed time — a newly created task immediately displays hours instead of "now".

  • Extract normalizeSqliteTimestamp() utility to fix SQLite UTC timestamps being parsed as local time
  • Apply fix to all 4 affected date formatting functions across the renderer

Fixes

If this PR fixes an issue, mention it like: Fixes #1331

Snapshot

Add screenshots, GIFs, or videos demonstrating the changes (if applicable)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • This change requires a documentation update

Mandatory Tasks

  • I have self-reviewed the code
  • A decent size PR without self-review might be rejected

Checklist

  • I have read the contributing guide
  • My code follows the style guidelines of this project (pnpm run format)
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked if my PR needs changes to the documentation
  • I have checked if my changes generate no new warnings (pnpm run lint)
  • I have added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

Test

Before the fix

image

After the fix

image

@vercel
Copy link

vercel bot commented Mar 6, 2026

@sairus2k is attempting to deploy a commit to the General Action Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 6, 2026

Greptile Summary

This PR fixes the task timer in the sidebar showing wrong elapsed time (e.g. hours instead of "now") by extracting a normalizeSqliteTimestamp() utility that appends a Z suffix to SQLite's CURRENT_TIMESTAMP format (YYYY-MM-DD HH:MM:SS) so JavaScript's Date constructor treats it as UTC rather than local time. The fix is then applied to all four date-formatting functions across the renderer.

  • The core fix in TaskItem.tsx and relative-time.tsx is correct and directly addresses the reported bug.
  • normalizeSqliteTimestamp() in utils.ts has a regex without a $ end anchor, meaning it can unintentionally match timestamps that already carry a trailing timezone offset (e.g. git commit dates like "2024-01-01 12:00:00 +0000"), producing an invalid ISO string like "2024-01-01T12:00:00 +0000Z".
  • Applying the normalization in CommitList.tsx to git commit dates is potentially risky since those dates are not SQLite timestamps and may include timezone offsets — the NaN guard prevents a crash but would silently fall back to displaying the raw timestamp text.
  • The application to prCommentsStatus.ts is safe since GitHub API timestamps are already ISO 8601 and the normalization becomes a no-op for them.

Confidence Score: 3/5

  • Safe to merge for the core sidebar timer fix, but the unanchored regex and its application to git commit dates introduce a potential regression in CommitList that should be verified.
  • The primary bug fix is correct and well-scoped. However, the normalizeSqliteTimestamp regex lacks a $ anchor, which could cause it to mangle timestamps that already have timezone offsets (such as git log dates), silently degrading date display in CommitList. The risk depends on the exact format gitGetLog returns, which is not verified in this PR.
  • src/renderer/lib/utils.ts (regex anchor) and src/renderer/components/diff-viewer/CommitList.tsx (applicability of SQLite normalization to git commit dates)

Important Files Changed

Filename Overview
src/renderer/lib/utils.ts Introduces normalizeSqliteTimestamp() utility — the regex lacks a $ end anchor, meaning it can match and mangle timestamps that already carry a trailing timezone offset (e.g. git commit dates), producing an invalid ISO string.
src/renderer/components/TaskItem.tsx Applies normalizeSqliteTimestamp() to formatCompactDate() — correct fix for task.updatedAt which is a SQLite UTC timestamp; no regressions introduced here.
src/renderer/components/diff-viewer/CommitList.tsx Applies normalizeSqliteTimestamp() to formatRelativeDate() — git commit dates may already include timezone offsets and are not guaranteed to be in SQLite format; if they do, the unanchored regex can produce invalid date strings causing fallback to raw text display.
src/renderer/components/ui/relative-time.tsx Refactors inline SQLite normalization logic in parseTimestamp() to use the new utility; behavior is functionally equivalent to the old code and the date-only + fallback paths are preserved correctly.
src/renderer/lib/prCommentsStatus.ts Applies normalizeSqliteTimestamp() to formatRelativeTime() — timestamps here come from the GitHub API and are already ISO 8601, so the normalization is a safe no-op; the buildPrCommentsStatus sort still uses raw timestamps but that's consistent since GitHub timestamps don't need normalization.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Raw date string input] --> B{Matches SQLite pattern?}
    B -- Yes --> C[Replace space with T and append Z]
    B -- No --> D[Return unchanged]
    C --> E[new Date normalized]
    D --> E
    E --> F{isNaN?}
    F -- No --> G[Use parsed UTC Date for display]
    F -- Yes --> H[NaN fallback or raw string]

    subgraph Callers
        T1[TaskItem.tsx]
        T2[CommitList.tsx]
        T3[relative-time.tsx]
        T4[prCommentsStatus.ts]
    end

    T1 & T2 & T3 & T4 --> A
Loading

Last reviewed commit: 8c73e58

Comment on lines +14 to +15
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(dateStr)) {
return dateStr.replace(' ', 'T') + 'Z';
Copy link
Contributor

Choose a reason for hiding this comment

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

Regex missing end anchor — may mangle timestamps with trailing timezone offsets

The regex /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/ has no $ anchor after the seconds. This means any string that starts with the SQLite datetime pattern will match — including git commit dates that include a trailing timezone offset like "2024-01-01 12:00:00 +0000".

For such a string:

  1. The regex matches (starts with the pattern) ✓
  2. .replace(' ', 'T') replaces only the first space → "2024-01-01T12:00:00 +0000"
  3. + 'Z' appends → "2024-01-01T12:00:00 +0000Z"invalid ISO 8601

new Date() will produce Invalid Date for that result. In CommitList.tsx this is caught by the isNaN guard and falls back to displaying the raw string, but in TaskItem.tsx and prCommentsStatus.ts there is no guard — new Date(...).getTime() would be NaN and the UI would show an empty string.

Anchoring the regex at the end (and only after the seconds, before any optional fractional-seconds or offset) prevents this misfiring:

Suggested change
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(dateStr)) {
return dateStr.replace(' ', 'T') + 'Z';
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(dateStr)) {
return dateStr.replace(' ', 'T') + 'Z';

This accepts optional fractional seconds but rejects strings that continue with a space+timezone offset, leaving those untouched so existing JS Date parsing handles them correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use the same regex as it was


function formatRelativeDate(dateStr: string): string {
const date = new Date(dateStr);
const date = new Date(normalizeSqliteTimestamp(dateStr));
Copy link
Contributor

Choose a reason for hiding this comment

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

normalizeSqliteTimestamp may not be appropriate for git commit dates

Git commit dates are not SQLite timestamps — they typically carry an explicit timezone offset, e.g. "2024-01-01 12:00:00 +0000" (from %ci) or a strict ISO-8601 string from %aI. As flagged in the utils.ts comment, the normalizeSqliteTimestamp helper is designed exclusively for SQLite's CURRENT_TIMESTAMP output (YYYY-MM-DD HH:MM:SS, no timezone).

If gitGetLog returns dates in a format with a trailing offset (e.g. "2024-01-01 12:00:00 +0000"), the current regex (without a $ anchor) will match and produce "2024-01-01T12:00:00 +0000Z" — an invalid date string — causing the isNaN guard to fall back to displaying the raw timestamp text.

It is worth verifying what exact format window.electronAPI.gitGetLog returns for commit.date. If it already emits proper ISO-8601 (e.g. "2024-01-01T12:00:00.000Z"), the normalization is a no-op and harmless; if it emits a space-separated datetime without a timezone offset, the fix is necessary. Adding a short comment noting the expected format would make the intent clear and prevent future confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted for both commits and comments

@arnestrickmann
Copy link
Contributor

Great improvement!

@arnestrickmann arnestrickmann merged commit fbfc8da into generalaction:main Mar 6, 2026
2 of 3 checks passed
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.

[bug]: task timer shows wrong elapsed time in sidebar

2 participants