#98 · Read comparison offsets in the time display's difference units
- timeline-app
- pull request
Closes #73. Each time display now defines the units it reads **time differences** in (`createDifference(presentation)` in `src/difference.ts`). It returns the units, what a plain number means, and an exact `parse`/`print` in stored coordinates. Comparison offsets are the first use. | Display | Units | Plain number | | --- | --- | --- | | Gregorian | `years`, `months`, `weeks`, `days`, `h`, `min`, `s`, `ms`, `µs`, `ns`, `ps`, `fs`, `as` (plus singular, abbreviated and any-case words) | seconds | | Rational / float / scientific, no unit | none | stored coordinates | | … with a fixed time unit (`s`, `minutes`, `days`, …) | that unit and the other fixed time units | the display's unit | | … with another unit (`million years`) | that unit, read whole | the display's unit | | SI | the unit with every prefix, case-sensitive (`ms` ≠ `Ms`); time units add `weeks`…`min` | the display's unit | | Custom | optional `parseDifference` / `printDifference` functions | stored coordinates | - A difference can combine several amounts (`2 years 3 days`, `-1 h 30 min`, `1.5 weeks`, `1/3 s`). A leading sign applies to the whole difference. - Years and months are the Gregorian mean year (365.2425 days, which 400 years repeat exactly) and a twelfth of it, since an offset must be a fixed length. Differences print in years, days, h, min and s, or in one unit below a second. Months and weeks are read but not printed. - The display's scale applies to every unit, so a Gregorian display of milliseconds reads `1 s` as 1000 coordinates. - Custom source may define `printDifference(difference: Rational, api)` and `parseDifference(text: string, api)`. The server's syntax validation accepts them. - In the comparison panel, the Offset field is read with the comparison display's units. A hint lists those units and follows changes to the display settings. Applying an offset reports it, for example "Shifted earlier by 2 years 3 days." ## Tests - `test/presentation.test.mjs` covers round trips and errors for every display kind, scaled displays, SI case sensitivity, multi-word labels and custom difference functions. - `test/comparison-browser.mjs` checks the units hint, the error for a unit on a display without units, and that an exact rational offset moves the track. - Locally, `npm test` (227 tests) and the Chromium browser suite pass. - Docs: `docs/time-presentation.md#time-differences` and `docs/comparison.md`.
Sources
Open #98 · Read comparison offsets in the time display's difference units in the timeline