Skip to content

fix(stats): correct hourly bucket timezone parsing in stats module - #217

Merged
devJaja merged 1 commit into
Epta-Node:mainfrom
JamesVictor-O:fix/issue-164-stats-sqlite-dialect
Jul 30, 2026
Merged

fix(stats): correct hourly bucket timezone parsing in stats module#217
devJaja merged 1 commit into
Epta-Node:mainfrom
JamesVictor-O:fix/issue-164-stats-sqlite-dialect

Conversation

@JamesVictor-O

Copy link
Copy Markdown

Summary

Closes #164.

The stats module's SQL (? placeholders, strftime, status = 'completed') had already been converted to SQLite syntax in a prior fix for the duplicate issue #175, but backend/src/db/stats.test.ts was still failing:

Expected: 2
Received: 0

Root cause: strftime('%Y-%m-%d %H:00:00', "createdAt") returns a naive, space-separated datetime string with no timezone marker (e.g. "2026-06-16 13:00:00"). Since createdAt is stored as UTC ISO strings, this value represents UTC time — but new Date("2026-06-16 13:00:00") in JS parses zone-less, space-separated strings as local time, not UTC. On any host not running in the UTC timezone, the hourly bucket keys drift by the host's UTC offset and no longer match the UTC-based series timestamps built in buildHourlySeries, so tasksLast24h / xlmLast24h values silently come back as 0.

Fix

Append a literal Z to the strftime format string in getTasksHourlyCounts and getXLMHourlyTotals (backend/src/db/stats.ts), so SQLite returns a valid UTC ISO8601 string (e.g. "2026-06-16 13:00:00Z") that Date parses correctly regardless of host timezone.

Test plan

  • npx jest src/db/stats.test.ts — both tests pass (previously 1 failing)
  • npx jest --runInBand --forceExit — full backend suite passes (251 passed, 2 skipped, unrelated)
  • npx tsc -p tsconfig.json --noEmit — no type errors

SQLite's strftime() returns naive datetime strings ("YYYY-MM-DD HH:00:00")
with no timezone marker, but the values are computed in UTC since
createdAt is stored as UTC ISO strings. JS's `new Date(...)` parses that
space-separated, zone-less format as local time, so on any host not
running in UTC the hourly bucket keys drift and fail to match the
UTC-based series timestamps, leaving tasksLast24h/xlmLast24h values at 0.

Append a literal "Z" to the strftime format so the returned string is a
valid UTC ISO8601 string that Date parses correctly regardless of the
host timezone.

Closes Epta-Node#164
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

@codeX-james is attempting to deploy a commit to the Jaja's projects Team on Vercel.

A member of the Team first needs to authorize it.

@devJaja
devJaja self-requested a review July 30, 2026 04:37
@devJaja

devJaja commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Solid Implementation @JamesVictor-O

I can see All CI checks Passed

@devJaja devJaja left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@devJaja
devJaja merged commit 9f86f7f into Epta-Node:main Jul 30, 2026
6 of 7 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.

[Backend] Fix Stats Module PostgreSQL/SQLite Dialect Mismatch (stats.ts Uses PostgreSQL Syntax)

3 participants