Four Years and a Day Off — JavaScript Bug Hunt
Modelled on the 1900 and 1904 date systems in Microsoft Excel.
- Language: JavaScript
- Layer: Frontend
- Difficulty: Easy
- Concepts: Dates, Configuration
- Modelled on: Excel · 1904 date system
- Visible tests: a paste within the same date system is unchanged; a Windows date pasted into a Mac workbook keeps its calendar date
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High)
- Ticket: BUG-XL-1462
- Reported by: finance team (Mac + Windows)
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- a Windows date pasted into a Mac workbook keeps its calendar date — expected [{"kind":"date","value":43538}] but got [{"kind":"date","value":45000}]
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Modelled on the 1900 and 1904 date systems in Microsoft Excel. Excel stores a date as a serial day number from a workbook-wide epoch: Excel for Windows uses the 1900 system, while older Excel for Mac workbooks default to the 1904 system. Microsoft's own documentation warns that copying dates between workbooks that use different systems shifts them by four years and one day (1,462 days), because the serial is pasted unchanged and reinterpreted against the other epoch.
paste.js is the clipboard handler of a spreadsheet web app that supports both systems.
Fix pasteCells so a pasted date shows the same calendar date in the target workbook.
Bug report
BUG-XL-1462 · Priority: High · Reported by: finance team (Mac + Windows)
pasteCells(cells, sourceSystem, targetSystem) returns new cells:
- a "date" cell pasted from the "1900" system into a "1904" workbook has its serial reduced by dateSystems.SYSTEM_OFFSET_DAYS (1462); the reverse direction adds it; the same system on both sides leaves it alone
- "number" and "text" cells are never changed
- the input array and its cells are not modified
After a paste, dateSystems.toIso(value, targetSystem) must equal dateSystems.toIso(original, sourceSystem).
Observed: invoice dates pasted from a Windows workbook into a Mac one show up four years and one day later.
Logs
[clipboard] paste 12 cells source=1900 target=1904
[render] A2 serial=45000 -> 2027-03-16 (source showed 2023-03-15)The code as shipped
src/sheet/paste.js (editable)
// Pastes clipboard cells into the target workbook.
// cell: { kind: "date" | "number" | "text", value }
exports.pasteCells = function (cells, sourceSystem, targetSystem) {
return cells.map(function (cell) {
return { kind: cell.kind, value: cell.value };
});
};
Read-only context: src/sheet/dateSystems.js.
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.