Skip to content

Open zero and negative date/time cells as numbers (#241) - #242

Merged
SuruchBoss merged 2 commits into
mainfrom
claude/new-session-m6mehm
Oct 5, 2026
Merged

SuruchBoss merged 2 commits into
mainfrom
claude/new-session-m6mehm

Conversation

@SuruchBoss

Copy link
Copy Markdown
Owner

What this changes

Closes #241.

The bug: ExcelJS hands a date-formatted cell over as a JS Date, and rawForDate in src/lib/excelIO.ts turned it into ISO text with isoFromSerial. For a serial of 0 or below, that text is a year-1899 day (1899-12-31, 1899-12-30, 1899-12-29 12:00). dateLiteral refuses any year before 1900, so the cell kept the string as text. As a result:

  • SUM skipped those cells without a word;
  • =A2+2 gave #VALUE!;
  • export wrote the text over the number in the file.

The fix: rawForDate keeps a serial below 0, or a 0 that is not midnight under a time-only format, as the number itself. The cell's format comes in exactly as before, so the grid shows it the way #219 does: 00/01/1900 for 0, and ######## for a negative. Export writes the number back with its format. Midnight under a time-only format still opens as 00:00, the case the issue notes is already fine.

Reproduced on main first

The issue's file: A1 0 (dd/mm/yyyy), A2 -1 (dd/mm/yyyy), A3 -1.5 ([h]:mm), A4 1.5 ([h]:mm), A5 45366 (dd/mm/yyyy), B2 =A2+2, A8 =SUM(A2:A4) ([h]:mm).

main this PR
A1, A2, A3 hold 1899-12-31, 1899-12-30, 1899-12-29 12:00 (text) 0, -1, -1.5 (numbers)
A1 / A2 / A3 shown the ISO text 00/01/1900 / ######## / ########
=A2+2 #VALUE! 1
=SUM(A2:A4) 36:00, i.e. 1.5 (A2 and A3 skipped), per the issue -1
Exported A1:A3 the strings the numbers, with dd/mm/yyyy / [h]:mm
A4 1.5 and A5 45366 36:00, 15/03/2024 unchanged

How it was verified

Gate Result
lint · check:readme · check:screens pass
check:deps every advisory fixed or accounted for
test 2028 passed (2017 by the README's static count)
check:mutants 32/32 killed
build · check:bundle 3804/4200 KB, largest chunk 934/1300 KB
check:a11y 121 checks passed
check:e2e 60 flows passed
  • excelIO.test.ts (+3), on a real .xlsx written with ExcelJS in the issue's layout:
    • the cells open as the numbers, shown as Excel shows them, with the positive date and time unchanged;
    • formulas read them: =A2+2 is 1 and the SUM is -1;
    • export writes the numbers back with their formats, read back with ExcelJS, and A2 is not a string cell.
  • Re-checked against the old code: with main's excelIO.ts, all three fail. The first finds 1899-12-31 and 1899-12-30 where the numbers should be, and the second gets #VALUE! for =A2+2.
  • Not tried by eye on a production build. The tests drive the real importer and exporter on a real .xlsx, but I did not open the file in the app.
  • READMEs, both languages:
  • Recounted: 2017 tests in 145 files. Picture 27 retaken in both languages and checked by eye, blessed after the retake. Social card rebuilt and checked by eye.

The branch

This is the session's branch claude/new-session-m6mehm. The work was written on a local branch on top of #59's head 6f54079, so the counts already included #59's test, with main 726af92 (#240) merged in.

🤖 Generated with Claude Code

https://claude.ai/code/session_013pmWZsbmugfpqtYazrzfjj


Generated by Claude Code

claude added 2 commits October 5, 2026 05:03
ExcelJS hands a date-formatted cell over as a Date, and rawForDate wrote
it as ISO text. A serial of 0 or below became a year-1899 day that no
date reading accepts, so the cell turned into text: SUM skipped it, =A2+2
gave #VALUE!, and export wrote the text over the number in the file.
rawForDate now keeps such a serial as the number. Its format came in as
before, so the grid shows it as #219 does (00/01/1900, ########) and
export writes the number back with its format. Midnight under a
time-only format still opens as 00:00.

Three tests in excelIO.test.ts on a real .xlsx (import, a formula
reading the cells, export), all red on the old excelIO.ts. Built on #59's
head; recounted to 2017 tests, picture 27 retaken in both languages and
the social card rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013pmWZsbmugfpqtYazrzfjj
@vercel

vercel Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
excel-to-go Ready Ready Preview Oct 5, 2026 5:21am UTC

@SuruchBoss
SuruchBoss merged commit 448a5b2 into main Oct 5, 2026
18 checks passed

Copy link
Copy Markdown
Owner Author

PO review: merged at 8cc1b64 (merge commit 448a5b2).

  • npm run verify locally on 8cc1b64: all ten gates green. 2028 tests passed, mutants 32/32, a11y 121 checks, e2e 60 flows.
  • CI: 17 checks green, CodeQL included.
  • Tried in the app, since the PR said it had not been opened there yet. I used a production build at 1280 and 390 with the same .xlsx that found Opening an .xlsx turns 0 and negative date/time cells into text ("1899-12-31"), and export writes the text back #241. All of it now matches what Microsoft Excel shows:
    • 0 under dd/mm/yyyy shows 00/01/1900.
    • -1 under dd/mm/yyyy and -1.5 under [h]:mm show ########.
    • =SUM(A2:A4) under [h]:mm is −1, so it shows ########. Before this PR it was 36:00 because the text cells were skipped.
    • The formula bar on A2 reads -1.
    • =A2+2 is 1. IFERROR(TEXT(A2,"dd/mm/yyyy"),…) takes the fallback.
    • Typing 5 into A2 shows 05/01/1900, and the total goes to 120:00. Undo puts back ########, and typing after the undo lands where it should.
    • Positive values are unchanged: 1.5 → 36:00, 45366 → 15/03/2024, and 0.5 under date+time → 00/01/1900 12:00.
    • Export writes the numbers 0, −1 and −1.5 back with dd/mm/yyyy, dd/mm/yyyy and [h]:mm, read back with ExcelJS.
    • No page errors, alerts or overflow at 390.

This was the last status:sprint-final ticket in the hold set.


Generated by Claude Code

This branch was successfully deployed

1 active deployment
Preview — 8cc1b645 Deployed Oct 5, 2026 by vercel[bot]
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.

Opening an .xlsx turns 0 and negative date/time cells into text ("1899-12-31"), and export writes the text back

2 participants