Skip to content

JSE-57: opt-in two-digit years for numeric text dates (locale.twoDigitYearPivot) - #134

Merged
securedeveloper merged 4 commits into
mainfrom
feat/jse-57-two-digit-years
Dec 1, 2026
Merged

securedeveloper merged 4 commits into
mainfrom
feat/jse-57-two-digit-years

Conversation

@securedeveloper

Copy link
Copy Markdown
Owner

What

A new opt-in locale member, ImportLocale.twoDigitYearPivot, and the same option on parseDate. It reads numeric text dates with a two-digit year, for CSV fields and xlsx text cells:

await importDataset(file, { locale: { decimal: ",", group: ".", dateOrder: "DMY", twoDigitYearPivot: 30 } });
// "31.10.26" -> 2026-10-31, "1.3.26" -> 2026-03-01, "31.12.99" -> 1999-12-31

parseDate("10/31/26", { order: "MDY", twoDigitYearPivot: 30 }); // 2026-10-31

Why

A text date with a two-digit year (31.10.26 under dateOrder: 'DMY', 10/31/26 under 'MDY') is not converted today, so a field of type 'date' fails with a TYPE issue. Meter-service and bank exports use two-digit years.

API shape

One flat number on ImportLocale, next to decimal, group and dateOrder: twoDigitYearPivot?: number. A year yy below the pivot is 20yy, the rest 19yy. It is an integer from 0 to 100: 30 is Excel's rule (00–29 → 2000s, 30–99 → 1900s), 0 makes every two-digit year 19yy and 100 makes every one 20yy. Anything else throws TypeError (in importDataset, inferColumnTypes, coerceColumns, detectHeader and parseDate).

Why this shape: a single number states the whole rule, it matches the flat style of the other locale members, it crosses into the worker unchanged, and a later named rule ('excel') can still be added without a break. A nested { pivot } object adds nothing today.

Off by default: without the member, results are those of 2.2.0. A later major could turn it on with 30 as the default (Excel's behaviour), but that changes results for files that use two-digit numbers in date-shaped text, so it stays opt-in for 2.x.

Semantics

  • Only the last part may have two digits, and only under an explicit 'DMY' or 'MDY' order. Separators as today: /, ., -, one throughout. One-digit day and month work (1.3.26, 6 characters, which the scanner previously rejected as too short; the shorter form is only scanned when the option is set).
  • An optional time HH:mm[:ss] works as with four-digit years: 31.10.26 13:45 gives a datetime column.
  • YMD never takes a two-digit leading year: 26.10.31 is ambiguous with a day first, so it stays text.
  • dateOrder: 'auto' never guesses: 31.10.26 may be D.M.YY or YY.MM.DD. A column with a two-digit-year date stays text with one DATE_ORDER_AMBIGUOUS issue telling the user to set dateOrder (without the option the column is text with no issue, as before).
  • The calendar is checked in the century the pivot gives: 31.02.26 fails; 29.02.00 is a date with pivot 30 (2000) but not with pivot 0 (1900).
  • One- and three-digit years are not dates. Four-digit years read exactly as before.
  • Number parsing still comes first and is untouched: 1.234 with group: '.' stays a number; 31.10.26 is never a number, and a forced number type on it still gives TYPE.
  • ISO 8601 text is read first, whatever the options.
  • Header detection counts such dates (also 1.3.26) as values when the option is set.

Documented in docs/api.md §5.6 (ImportLocale, Type rules, parseDate), with a README line and a minor changeset.

react-data-import

react-data-import 1.0.0 (src/import.ts) types locale as javascript-excel's own ImportLocale and copies options.locale by reference into the engine options (ENGINE_KEYS), so the new member reaches importDataset unchanged. Its dependency range is javascript-excel: ^2.0.0, so a consumer can use the option after updating javascript-excel, without a react-data-import release.

Tests

  • test/import/two-digit-years.test.ts (45 tests, written first and seen failing: 26 failed before the change):
    • parseDate: DMY and MDY, all three separators, one-digit day/month, pivot boundaries (29/30 with 30, 49/50 with 50, 0 and 100), time of day, leap years by century, YMD, one- and three-digit years, mixed separators, invalid pivots.
    • inferColumnTypes / coerceColumns: explicit orders, datetime, invalid days, forced types with and without the option, 'auto', number/date interaction under de and en locales.
    • importDataset: a CSV with a schema date field (two TYPE issues without the option, none with it), CSV inference, xlsx text cells, 'auto' with and without the option, option validation.
    • detectHeader with 1.3.26 values.
    • A seeded property test (20,000 texts): with the pivot, every text parses as it does without it, except a DMY/MDY two-digit year, which parses as its four-digit expansion.
  • Differential check against the published 2.2.0 tarball with the option unset (not committed: it needs the npm tarball). 40,000 random datasets of date-shaped text, numbers and other cells under eight locales, through inferColumnTypes, coerceColumns with forced types, detectHeader, parseDate with each order, and importDataset for CSV and xlsx: identical results. With the option set in one locale, the same harness reports differences, so it does detect a change.
  • Locally: typecheck, test (all pass apart from test/format/libreoffice.test.ts, which fails the same way on the unchanged 2.2.0 base with the local LibreOffice install), build, lint, smoke, consumer-ts (the fixture now uses the member and parseDate's option), docs:check, test:release, the dependency guard and the API reference build pass.

…tYearPivot)

ImportLocale.twoDigitYearPivot and parseDate's twoDigitYearPivot accept
dates such as 31.10.26 (DMY) and 10/31/26 (MDY): yy below the pivot is
20yy, the rest 19yy; 30 is Excel's rule. Off by default. YMD never takes a
two-digit leading year, and dateOrder 'auto' keeps such columns text with
DATE_ORDER_AMBIGUOUS. An integer from 0 to 100, else TypeError.

Tests: parseDate cases, inference and coercion, CSV and xlsx imports,
header detection, and a seeded property test against the four-digit
expansion.
…ates

A 6- or 7-character numeric text counts as a date only with a two-digit
last part (dateParts), so version numbers such as 10.2.1 no longer raise
DATE_ORDER_AMBIGUOUS under 'auto'. Header detection counts such a text
only when it is a valid DMY or MDY two-digit-year date under the locale.

Tests: version columns under 'auto' and in header detection, a property
test of detectHeader against the four-digit expansion, the option unset
against no member for inferColumnTypes, coerceColumns and detectHeader,
the worker path, and detectHeader with an invalid pivot.
…-years

# Conflicts:
#	packages/javascript-excel/src/internal/import/pipeline.ts
#	packages/javascript-excel/test/worker/worker.test.ts
…-years

Keeps JSE-54's 'day' column type and passes twoDigitYearPivot to its text
dates, with a test and matching docs.
@securedeveloper
securedeveloper merged commit bfda3ec into main Dec 1, 2026
9 checks passed
@securedeveloper
securedeveloper deleted the feat/jse-57-two-digit-years branch December 1, 2026 18:05
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.

1 participant