Repository navigation
JSE-57: opt-in two-digit years for numeric text dates (locale.twoDigitYearPivot) - #134
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new opt-in locale member,
ImportLocale.twoDigitYearPivot, and the same option onparseDate. It reads numeric text dates with a two-digit year, for CSV fields and xlsx text cells:Why
A text date with a two-digit year (
31.10.26underdateOrder: 'DMY',10/31/26under'MDY') is not converted today, so a field of type'date'fails with aTYPEissue. Meter-service and bank exports use two-digit years.API shape
One flat number on
ImportLocale, next todecimal,groupanddateOrder:twoDigitYearPivot?: number. A yearyybelow the pivot is20yy, the rest19yy. 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 throwsTypeError(inimportDataset,inferColumnTypes,coerceColumns,detectHeaderandparseDate).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
'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).HH:mm[:ss]works as with four-digit years:31.10.26 13:45gives adatetimecolumn.26.10.31is ambiguous with a day first, so it stays text.dateOrder: 'auto'never guesses:31.10.26may be D.M.YY or YY.MM.DD. A column with a two-digit-year date stays text with oneDATE_ORDER_AMBIGUOUSissue telling the user to setdateOrder(without the option the column is text with no issue, as before).31.02.26fails;29.02.00is a date with pivot 30 (2000) but not with pivot 0 (1900).1.234withgroup: '.'stays a number;31.10.26is never a number, and a forcednumbertype on it still givesTYPE.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) typeslocaleas javascript-excel's ownImportLocaleand copiesoptions.localeby reference into the engine options (ENGINE_KEYS), so the new member reachesimportDatasetunchanged. Its dependency range isjavascript-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 underdeandenlocales.importDataset: a CSV with a schemadatefield (twoTYPEissues without the option, none with it), CSV inference, xlsx text cells,'auto'with and without the option, option validation.detectHeaderwith1.3.26values.inferColumnTypes,coerceColumnswith forced types,detectHeader,parseDatewith each order, andimportDatasetfor CSV and xlsx: identical results. With the option set in one locale, the same harness reports differences, so it does detect a change.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 andparseDate's option), docs:check, test:release, the dependency guard and the API reference build pass.