Skip to content

Fix work entry dates being stored as epoch milliseconds - #913

Open
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1786428663-fix-export-date-format
Open

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1786428663-fix-export-date-format

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

CSV and PDF exports rendered the Date column as 1786406400000 instead of a date. Root cause is in persistence, not in the export code: workEntrySchema uses Joi.date(), which coerces the incoming "2024-03-09" string into a JS Date, and the sqlite3 driver binds a Date as epoch milliseconds. The UI happened to hide this because it renders new Date(entry.date), which parses the number fine; the exports write the raw column value.

Fix normalizes the value at the write boundary:

// utils/date.js
toDateOnly(value) => value instanceof Date ? value.toISOString().split('T')[0] : value

// routes/workEntries.js — INSERT and UPDATE
values.push(toDateOnly(value.date));

date is a day-granular DATE column, so this also makes ORDER BY we.date DESC sort lexicographically-correct ISO strings rather than mixing numbers and strings.

Existing rows are unaffected because the database is in-memory and resets on restart. API responses now return "2024-03-09" where they previously returned 1786406400000; the frontend's new Date(entry.date) calls handle both.

Found while adding backend test coverage in #912 (which touches only test files).

Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/b25a5ce29aa043b686d55c72d875b8ef

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Epoch-ms date bug is fixed — verified end-to-end

Backend Jest on this branch: Tests: 169 passed, Test Suites: 10 passed.

Ran the app locally (fresh in-memory DB) and created an entry with an explicit non-today date of 08/09/2026, so a date-parsing bug couldn't hide behind "today".

Exports now contain a real date instead of 1786406400000
PDF export CSV export
PDF CSV

PDF Date cell and CSV Date column both read 2026-08-09, matching the date entered in the UI.

Regression: edit path also normalized, and all UI surfaces agree

Edited the entry's date to 08/05/2026. The edit dialog prefills correctly, the change survives a full page reload (server-side persistence), and every surface renders it:

Edit dialog prefilled Work Entries after edit + F5
edit dialog after reload
Dashboard Reports
dashboard reports

Re-exporting after the edit yields 2026-08-05, proving the UPDATE path normalizes too, not just the insert:

csv after edit

No errors in the backend log; backend/temp/ empty after all exports.

@sonarqubecloud

Copy link
Copy Markdown

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.

0 participants