Repository navigation
feat(core): read typed dates in every calendar - #9792
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Approval is on hold for a spec decision, and five fixes are needed either way.
This parser implements draft spec:AST-111 FR9–FR13 and DEC-4. On main, architecture:internationalization INV10 still keeps date parsing Gregorian, and INV8's Owning code does not list the new module. So an engineering owner needs to approve this addition ahead of those records, or identify the current record that governs it. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner.
Required fixes:
- The parser reads its own text back as a different date: several European locales write the Chinese and Korean hint with the 60-year cycle number (
2/12/41for 1 Jan 2025) or with no year, and Hungarian and Serbian Islamic month names contain a digit (Réb. 1) (calendarDateParser.ts:1284–1288,:427–437). - Committed text that cannot be read back: Spanish, French, Italian and Romanian
date_weekdaytext fails on Tuesdays becausemaris also a month name, Vietnamese weekday digits (Thứ 4) count as date numbers, and the parser never learns some era spellings in hints, such as FrenchEBandH. - The new RuleTester cases are spliced into two existing objects without closing them, so two
calendarSystem.tsboundary cases are overwritten (no-raw-intl-locale.test.mjs:155–158,:310–316). normalizeDateTextcopies the digit folding and invisible-character stripping thatutils/unicodeDigits.tsalready givesnumberParser.tsandtimeFormat.ts; importtoAsciiDigitsandINVISIBLE_CHARSinstead.- The changeset says the parser reads a date "the way a locale writes it", but the round-trip matrix covers only native locales,
enandsv-SE; extend the matrix to the shipped locales or narrow the wording.
[Automated review]
| if (!parts.some(p => partType(p) === 'relatedYear' || p.type === 'year')) { | ||
| // Some locales write only the cycle year name; the long form also has | ||
| // the Gregorian year. | ||
| resolved = options.weekday ? LONG_WITH_WEEKDAY : LONG; | ||
| parts = partsOf(locale, calendar, resolved, mid); |
There was a problem hiding this comment.
In ca-ES, cs-CZ, de-DE, fi-FI, fr-FR, it-IT, nl-NL, pl-PL, pt-PT and ru-RU, the numeric year part here is the 60-year cycle number. The hint is 2/12/41 for 1 Jan 2025, and the parser reads it back as 24 Dec 2041. In de-DE, pt-BR and pt-PT the long form also has only yearName (2. M12 jia-chen), so the text reads back in the current year. Always write the related Gregorian year.
| if (/\d/.test(name)) { | ||
| // A month number with affixes: "11月", "9:e mån", "윤6", "6bis". | ||
| const match = /^(\D*)(\d+)(\D*)$/.exec(name); | ||
| if (match != null && (match[1] || match[3])) { | ||
| templates.set(`${match[1]}#${match[3]}`, { | ||
| pre: match[1], | ||
| post: match[3], | ||
| isLeap: code.endsWith('L'), | ||
| }); | ||
| } | ||
| return; |
There was a problem hiding this comment.
Hungarian and Serbian Islamic month abbreviations contain a digit (Réb. 1, Реб. 1 = Rabīʿ I). They become a numeric template here, so MF 1447. Réb. 1 2. (26 Aug 2025) reads as month 1 (28 Jun 2025). Treat the name as a month name unless the digit is that month's own number.
| for (const word of [ | ||
| ...months.keys(), | ||
| ...eras.keys(), | ||
| ...yearAliases.keys(), | ||
| ]) { | ||
| skip.delete(word); | ||
| } |
There was a problem hiding this comment.
Month names win over weekday words, and every lexicon includes English (line 403). So mar (Tuesday in es, fr, it, ro) becomes a second month, and every Tuesday's date_weekday text is unreadable; no-NO tir. and pt-BR ter. collide the same way. Read a weekday word as a weekday when a month is already present, or when it sits at the pattern's weekday position.
| .replace(BIDI_MARKS, '') | ||
| .replace(/\p{Nd}/gu, asciiDigit) |
There was a problem hiding this comment.
utils/unicodeDigits.ts already owns this for numberParser.ts and timeFormat.ts (INVISIBLE_CHARS, toAsciiDigits). BIDI_MARKS and asciiDigit have already drifted from it. Import the shared helpers, add U+202A–U+202E to INVISIBLE_CHARS if needed, and delete the copies.
| { | ||
| code: `new Intl.NumberFormat(locale, {useGrouping: false}).format(day);`, | ||
| filename: CALENDAR_SYSTEM_INFRA_FILE, | ||
| code: `new Intl.DateTimeFormat(locale, {calendar, timeZone: 'UTC'}).formatToParts(ms);`, |
There was a problem hiding this comment.
The object above is still open, so this code and filename overwrite the existing calendarSystem.ts NumberFormat case. Close it with }, and open a new { first. The same applies at line 314. The suite runs 111 cases, not 113.
| code: `const {NumberFormat} = Intl;`, | ||
| filename: CALENDAR_SYSTEM_INFRA_FILE, | ||
| errors: [rawIntlReference], | ||
| code: `new Intl.DateTimeFormat(undefined, {calendar: 'persian'});`, |
There was a problem hiding this comment.
Same splice: this overwrites the invalid const {NumberFormat} = Intl; case for calendarSystem.ts. Close the object with }, and open a new { before this line.
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [feat] Core gains an internal parser for dates typed in a calendar system. It reads a date the way a locale writes it in any `CalendarSystem`, in any decimal digits, with month and era names, leap months such as Adar I, and Japanese eras such as `令和元年`, and returns a Gregorian date. A date the calendar does not have is rejected and never adjusted. It also writes the committed text and the format hint. No component uses it yet, and no public API changes. |
There was a problem hiding this comment.
"reads a date the way a locale writes it in any CalendarSystem" is broader than the evidence. The round trip covers each calendar's native locale, en and sv-SE, and the parser cannot read its own text in shipped locales such as es-ES, fr-FR, it-IT, ro-RO and vi-VN. Fix the parser and widen the matrix, or narrow the wording.
There was a problem hiding this comment.
Approval is on hold for a spec decision, and six fixes are needed either way.
This parser implements draft spec:AST-111 FR9–FR13 and DEC-4, and nearestAcceptedDate implements its draft AR2. On main, architecture:internationalization INV10 still keeps date parsing Gregorian, and INV8's Owning code does not list the new module. An engineering owner needs to approve these additions ahead of those records, or identify the current record that governs them; they record that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner.
Required fixes:
- The parser reads its own text back as a different date, because several European locales write the Chinese and Korean hint with the 60-year cycle number (
2/12/41for 1 Jan 2025) or with no year, and Hungarian and Serbian Islamic month names contain a digit (Réb. 1) (calendarDateParser.ts:1283–1288,:427–437). - Nine Unicode property escapes are written as regex literals (
calendarDateParser.ts:129and eight more), sounicodePropertyEscapes.source-build.test.mjsfails and a Next.js source build without a browserslist stops withUnknown property: Nd; build them withnew RegExp(...)asutils/unicodeDigits.tsdoes. - Committed text cannot be read back in several shipped locales: Spanish, French, Italian and Romanian
date_weekdaytext fails on Tuesdays becausemaris also a month name, Vietnamese weekday digits (Thứ 4) count as date numbers, and hints such as FrenchEBandHuse era spellings the parser never learns. - The new RuleTester cases are spliced into two existing objects without closing them, so two
calendarSystem.tsboundary cases are overwritten (no-raw-intl-locale.test.mjs:154–159,:310–317). normalizeDateTextcopies the digit folding and invisible-character stripping thatutils/unicodeDigits.tsalready givesnumberParser.tsandtimeFormat.ts, so importtoAsciiDigitsandINVISIBLE_CHARSinstead.- The changeset says the parser reads a date "the way a locale writes it", but the round-trip matrix covers only native locales,
enandsv-SE, so extend the matrix to the shipped locales or narrow the wording.
[Automated review]
| weekday: 'short', | ||
| }; | ||
| const BIDI_MARKS = /[\u061c\u200b-\u200f\u202a-\u202e\u2066-\u2069]/g; | ||
| const DECIMAL_DIGIT = /\p{Nd}/u; |
There was a problem hiding this comment.
This and eight more \p{…} regex literals (lines 130, 131, 135, 287, 291, 298, 415, 509) fail unicodePropertyEscapes.source-build.test.mjs, and Next.js's bundled Babel stops on the file with Unknown property: Nd when an app sets no browserslist. Build each one once with new RegExp('\\p{Nd}', 'u'), as utils/unicodeDigits.ts does.
53da574 to
fe3c951
Compare
3bfcb3f to
96920a3
Compare
There was a problem hiding this comment.
Approval is on hold for a spec decision, and one fix is needed either way.
The parser and nearestAcceptedDate implement draft spec:AST-111 FR9–FR13, AR2 and DEC-4, while architecture:internationalization INV10 on main still keeps date parsing Gregorian and INV8's Owning code does not list the parser; the widened invisible-character set also lets NumberInput and DateTimeInput's time field accept text that no current clause covers. An engineering owner needs to approve these additions ahead of those records, or identify the current record that governs them, by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.
Required fix:
calendarDateParser.ts:193–227re-implements the UTC date-only formatting path thatplainDateFormatToPartsandplainDateFormatalready provide (andcalendarSystem.tsalready calls), so routepartsOfandformatInCalendarthrough them and deleteepochMs.
The read-back, source-build, lint-case, digit-folding and changeset fixes from the last round all hold at this head.
[Automated review]
| function epochMs(pd: PlainDate): number { | ||
| const date = new Date(0); | ||
| date.setUTCFullYear(pd.year, pd.month - 1, pd.day); | ||
| return date.getTime(); | ||
| } | ||
|
|
||
| function isoToPlainDate(iso: string): PlainDate { | ||
| const match = /^(-?\d+)-(\d+)-(\d+)$/.exec(iso); | ||
| if (match == null) { | ||
| throw new RangeError(`Bad sample date ${iso}`); | ||
| } | ||
| return {year: +match[1], month: +match[2], day: +match[3]}; | ||
| } | ||
|
|
||
| function partsOf( | ||
| locale: Locale, | ||
| calendar: CalendarSystem, | ||
| options: Intl.DateTimeFormatOptions, | ||
| pd: PlainDate, | ||
| ): Intl.DateTimeFormatPart[] { | ||
| return formatter(locale, calendar, options).formatToParts(epochMs(pd)); | ||
| } |
There was a problem hiding this comment.
epochMs and partsOf repeat the date-fields branch of plainDateFormatInput (plainDate.ts:494–500): a cached formatter with timeZone: 'UTC' and UTC midnight. plainDateFormatToParts(pd, {...options, calendar}, locale) already does this, and calendarSystem.ts:300–307 calls it for the same job. Call it here and plainDateFormat in formatInCalendar, then delete epochMs, so the parser always learns from the text the fields show.
| } | ||
| const typedEra = eraCodes.size === 1 ? [...eraCodes][0] : undefined; | ||
|
|
||
| // Assign the numbers to fields. |
There was a problem hiding this comment.
Non-blocking (INV29): this comment and // Resolve the year. at line 969 narrate the code. Delete them, or extract assignFields() and resolveYear().
fe3c951 to
0041c70
Compare
96920a3 to
f81d686
Compare
There was a problem hiding this comment.
Approval is on hold for a spec decision, and one fix is needed either way.
The parser and nearestAcceptedDate implement draft spec:AST-111 FR9–FR13, AR2 and DEC-4, while architecture:internationalization INV10 on main still keeps date parsing Gregorian and INV8's Owning code does not list the parser; the wider invisible-character set also changes what NumberInput and DateTimeInput's time field accept, which no current clause covers. An engineering owner needs to approve these additions ahead of those records, or identify the current record that governs them, by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.
Required fix:
- Miss:
normalizeDateText(calendarDateParser.ts:232) does not mapʻ(U+02BB), the letterIntlwrites in the English namesDhuʻl-QiʻdahandDhuʻl-Hijjah, soDhu'l-Hijjah 10, 1447 AHtyped with a straight or curly apostrophe is unreadable in every Islamic calendar; add U+02BB and U+02BF to that apostrophe class with a test.
The earlier formatting-path finding is fixed.
[Automated review]
| .normalize('NFKC') | ||
| .replace(INVISIBLE_CHARS, '') | ||
| // People type an ASCII apostrophe or quote for Hebrew geresh and gershayim. | ||
| .replace(/[\u05f3\u2018\u2019\u02bc`]/g, "'") |
There was a problem hiding this comment.
Miss: ʻ (U+02BB) is missing from this class. Intl writes it in the English Islamic month names Dhuʻl-Qiʻdah and Dhuʻl-Hijjah (and Dhuʻl-Q., Dhuʻl-H.), so Dhu'l-Hijjah 10, 1447 AH and Dhu’l-Hijjah 10, 1447 AH are unreadable in every Islamic calendar. Adding U+02BB and U+02BF here makes both read, and the parser's unit and round-trip suites still pass.
0041c70 to
de34259
Compare
f81d686 to
18150b8
Compare
There was a problem hiding this comment.
Approval is on hold for a spec decision, and one fix is needed either way.
The parser and nearestAcceptedDate implement draft spec:AST-111 FR9–FR13, AR2 and DEC-4, while architecture:internationalization INV10 on main still keeps date parsing Gregorian and INV8's Owning code does not list the parser; the wider invisible-character set also changes what NumberInput and DateTimeInput's time field accept, which no current clause covers. An engineering owner needs to approve these additions ahead of those records, or identify the current records that govern them, by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.
Required fix:
- Miss:
normalizeDateText(calendarDateParser.ts:232) does not foldʻ(U+02BB), the letterIntlwrites in the English namesDhuʻl-QiʻdahandDhuʻl-Hijjah, soDhu'l-Hijjah 10, 1447 AHtyped with a straight or curly apostrophe is unreadable in every Islamic calendar; add U+02BB and U+02BF to that class with a test.
[Automated review]
| .normalize('NFKC') | ||
| .replace(INVISIBLE_CHARS, '') | ||
| // People type an ASCII apostrophe or quote for Hebrew geresh and gershayim. | ||
| .replace(/[\u05f3\u2018\u2019\u02bc`]/g, "'") |
There was a problem hiding this comment.
Miss: ʻ (U+02BB) is missing from this class. Intl writes it in the English Islamic month names Dhuʻl-Qiʻdah and Dhuʻl-Hijjah (and Dhuʻl-Q., Dhuʻl-H.), so Dhu'l-Hijjah 10, 1447 AH and Dhu’l-Hijjah 10, 1447 AH are unreadable in every Islamic calendar. Adding U+02BB and U+02BF here makes both spellings read and keeps the parser's tests passing:
.replace(/[\u05f3\u2018\u2019\u02bb\u02bc\u02bf`]/g, "'")Please add a test that Dhu'l-Hijjah 10, 1447 AH reads in en with islamic-umalqura.
| } | ||
|
|
||
| function windowedYear(twoDigits: number, current: number): number { | ||
| // Eighty years back and nineteen ahead of the calendar's current year. |
There was a problem hiding this comment.
Non-blocking (INV29): this comment restates the two comparisons below. Delete it, or move the window into a JSDoc on windowedYear: "Resolves a two-digit year to the century that puts it at most 80 years before and 19 years after the current year."
de34259 to
babf230
Compare
18150b8 to
f02913f
Compare
|
/approve-spec f02913f |
There was a problem hiding this comment.
Changes requested. An engineering owner approved the calendar parser's direction at this head, and two fixes remain.
- Miss:
formatLunisolarinpackages/core/src/utils/calendarDateParser.ts(lines 1241–1280) copies the lunisolar branch offormatCalendarDateinutils/calendarSystem.tsinstead of extending it, so Calendar's formatter and the field already write different Chinese and Dangi text for the same day (24. M09 bing-wuagainst24. M09 2026inde-DE); giveformatCalendarDatea related-year option, call it fromformatInCalendar, and delete the copy. - The description still says that the shared
INVISIBLE_CHARSset drops U+202A–U+202E and that NumberInput and the time fields now ignore those characters, butunicodeDigits.tsis unchanged at this head and only the calendar parser strips them, so please remove those two statements.
The inline comments add two non-blocking points: the ASCII fast path in normalizeDateText skips the backtick fold, and two comments only label the next block.
[Automated review]
| * names. Intl and a polyfilled Temporal can start a month one day apart, so the | ||
| * month's name comes from its middle day and the day number from Temporal. | ||
| */ | ||
| function formatLunisolar( |
There was a problem hiding this comment.
Miss: this copies the lunisolar branch of formatCalendarDate (calendarSystem.ts:330–377). Both take the middle-of-month Intl parts, write Temporal's day through plainDateFormatDayNumber with the resolved numbering system, and take the weekday from the date. Only the related-year swap (lines 1258–1260 and 1273–1276) is new. With the same options, Calendar's formatter writes 24. M09 bing-wu and this function writes 24. M09 2026 for 2 Nov 2026 in de-DE. Give formatCalendarDate an option that writes the related Gregorian year, call it from formatInCalendar for every non-Gregorian calendar, and delete this function.
| /** Text in one comparable form: ASCII digits, lower case, no Latin accents. */ | ||
| export function normalizeDateText(text: string, locale: Locale): string { | ||
| // Most typed text is printable ASCII; skip the Unicode passes it does not need. | ||
| if (/^[\u0020-\u007e]*$/.test(text)) { |
There was a problem hiding this comment.
Non-blocking: this returns before the apostrophe fold at line 235, so the backtick there is folded only when the text also has a non-ASCII character. Dhu`l-Hijjah 10, 1447 AH is unreadable in en with islamic-umalqura, but the same text with a trailing U+200F reads as 27 May 2026. Fold the backtick here too, or drop it from the class.
| } | ||
| } | ||
|
|
||
| // Literals, weekday names and year names: words to read past. |
There was a problem hiding this comment.
Non-blocking (INV29): this comment and the one at line 494 only label the next block. Extract collectSkipWords() and collectEras(), or delete the comments.
babf230 to
5ec2dc4
Compare
There was a problem hiding this comment.
Approval is on hold for a spec decision at this head, and one fix is needed either way.
The calendar parser, its raw-Intl lint admission and nearestAcceptedDate implement spec:AST-111 FR9–FR13, AR2 and DEC-4, which is still draft on main, and architecture:internationalization INV8's Owning code does not list the parser; the earlier /approve-spec names the previous head, and an approval counts only at its exact head. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner.
- Miss:
formatLunisolarinpackages/core/src/utils/calendarDateParser.ts(lines 1241–1280) copies the lunisolar branch offormatCalendarDateinutils/calendarSystem.tsinstead of extending it, so the Calendar label and the field already write different Chinese and Dangi text for the same day (24. M09 bing-wuagainst24. M09 2026inde-DE); giveformatCalendarDatea related-year option, call it fromformatInCalendar, and delete the copy.
Two earlier non-blocking points still apply: the ASCII fast path in normalizeDateText skips the backtick fold, and the comments at lines 428 and 494 only label the next block.
[Automated review]
e38dac1 to
0d0e06d
Compare
There was a problem hiding this comment.
Approval is on hold for a spec decision at this head, and one fix is needed either way.
The calendar parser, its raw-Intl lint admission and nearestAcceptedDate implement spec:AST-111 FR9–FR13, AR2 and DEC-4, which is still draft on main, and architecture:internationalization INV8's Owning code does not list the parser. The earlier /approve-spec names a previous head, and an approval counts only at its exact head, so an engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.
- Miss:
formatLunisolarinpackages/core/src/utils/calendarDateParser.ts(lines 1241–1280) copies the lunisolar branch offormatCalendarDateinutils/calendarSystem.tsinstead of extending it, so the Calendar label and the field already write different Chinese and Dangi text for the same day (24. M09 bing-wuagainst24. M09 2026inde-DE); giveformatCalendarDatea related-year option, call it fromformatInCalendar, and delete the copy.
Two earlier non-blocking points still apply: the ASCII fast path in normalizeDateText skips the backtick fold, and the comments at lines 428 and 494 only label the next block.
[Automated review]
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC |
|---|---|---|
| PowerSearch | 249.7 kB (+155 B) · 22.3 kB CSS (0) | — |
| DateRangeInput | 75.7 kB (+119 B) · 11.2 kB CSS (0) | — |
| DateTimeInput | 177.1 kB (+117 B) · 17.2 kB CSS (0) | — |
6 more components
| Component | Size | LoC |
|---|---|---|
| Calendar | 57.4 kB (+98 B) · 9.3 kB CSS (0) | — |
| DateInput | 155.0 kB (+96 B) · 15.5 kB CSS (0) | — |
| Timestamp | 22.9 kB (+4 B) · 8.9 kB CSS (0) | — |
| lab/Comments | 271.3 kB (0) · 2.5 kB CSS (0) | — |
| lab/CommentThread | 266.2 kB (0) · 2.4 kB CSS (0) | — |
| lab/Schedule | 63.5 kB (0) · 3.9 kB CSS (0) | — |
Package size: @astryxdesign/core 6.51 MB packed (+21.5 kB); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 9 rows, core 3 rows; run pnpm api:report.
Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.
Generated by PR Enrichment workflow | View full report
0d0e06d to
ce48c99
Compare
|
/approve-spec ce48c99 |
There was a problem hiding this comment.
Approval is on hold for one spec decision, and two fixes are needed either way.
The engineering owner's /approve-spec on this head covers the calendar parser, its raw-Intl lint admission, nearestAcceptedDate and the new Owning-code line. One change has no governing record: Calendar in the Chinese and Dangi calendars now names days and announces picks with the related Gregorian year where the locale writes only the cycle year (de-DE: Montag, 24. M09 bing-wu becomes Montag, 24. M09 2026), while the month heading and grid name keep M09 bing-wu. An engineering owner needs to settle whether Calendar's day names and announcements take the related year while its heading keeps the cycle year, and records that by commenting /approve-spec <full head SHA> on the rebased head; the author may do so as an engineering owner.
- The branch conflicts with
maininpackages/core/src/utils/calendarSystem.tsandpackages/core/src/Calendar/Calendar.calendarSystems.test.tsx, because #9639 rewroteformatCalendarDateintoformatCalendarDateToPartsandwithTemporalDay, so the pull request cannot land and CI has not run; rebase, carry therelatedYearsubstitution into the parts path, and rerun the round-trip suite. - The description says "No record changes in this PR", "No knowledge record is touched" and "No rendered output changes", but this head adds the parser to
docs/architecture/internationalization.mdOwning code and changes Calendar's day names, and the changeset's claim that Calendar's names "match the text a date field writes" holds only for the testedde-DEcase (jagives2026年九月24日月曜日against2026(丙午)年九月24日); list the record line with its rubric results and the Calendar change, and drop the match claim.
[Automated review]
| return formatCalendarDate(calendar, date, DATE_FORMAT_WITH_WEEKDAY, locale, { | ||
| relatedYear: true, | ||
| }); |
There was a problem hiding this comment.
This changes Calendar's Chinese and Dangi day names and announcements in de-DE, pt-BR and ja from the cycle year to the related Gregorian year (Montag, 24. M09 bing-wu becomes Montag, 24. M09 2026), while the month heading and grid name keep M09 bing-wu. No record states this year form, so it waits for an engineering owner's decision.
| {day: 'numeric'}, | ||
| 'en-u-nu-latn', | ||
| ).find(part => part.type === 'day')?.value; | ||
| const writesRelatedYear = |
There was a problem hiding this comment.
main rewrote this function in #9639 (formatCalendarDateToParts and withTemporalDay), and the branch now conflicts here. After the rebase, carry the related-year substitution into the parts path and rerun the round-trip suite.
Add calendarDateParser: per-locale lexicons, a typed-date parser with distinct rejection kinds, committed text, the format hint, and calendar display names. Unit and round-trip tests cover every calendar. The raw-Intl lint rule approves the parser at its own path.
…cales Write the related Gregorian year for Chinese and Korean dates, read month names that hold a digit, read weekday words that are also month or era names, learn the era spellings of full dates, and keep a one-digit day open until it exceeds 31. Reuse unicodeDigits for digit folding and invisible characters, and build Unicode property escapes at runtime.
…eParser Build formatters through dateTimeFormatFor instead of a second cache, and fold the new parser cases into the existing tests.
…matToParts partsOf and formatInCalendar call plainDateFormatToParts and plainDateFormat, which already format a date-only PlainDate at UTC midnight in UTC, so epochMs and the local formatter go away. Lunisolar day and year digits use plainDateFormatDayNumber with the formatter's numbering system.
… in typed month names The shared invisible-character set stays as on main, so NumberInput and time text read as before. The calendar parser strips U+202A-U+202E itself, and reads a straight or curly apostrophe for the ʻ that Intl writes in Islamic month names such as Dhuʻl-Hijjah.
…Date formatCalendarDate and formatCalendarDateToParts gain a relatedYear option. The date field's text uses it, so a Chinese or Dangi year that the locale names only by its place in the 60-year cycle becomes the related Gregorian year, which reads back. Calendar does not pass it, so its day names and announcements do not change. The parser's copy of the lunisolar formatting is gone. The ASCII fast path in normalizeDateText also folds a backtick to an apostrophe, and the internationalization record lists the parser among the shared locale-sensitive parsers.
ce48c99 to
295c13c
Compare
|
/approve-spec 295c13c |
There was a problem hiding this comment.
Approved pending CI: CI has not finished on this head yet.
The engineering owner's /approve-spec for this head covers the calendar parser, its Owning-code line and lint admission, and nearestAcceptedDate, and the parser keeps PlainDate values Gregorian as architecture:internationalization INV10 requires. The earlier findings are resolved: Calendar's day names are unchanged, the branch merges cleanly, and the description matches the change. When #9643 wires the parser into DateInput and DateTimeInput, it needs to amend INV10, which still says those fields show Gregorian dates.
[Automated review]
This implements the parser behind
spec:AST-111(approved in #9605) FR9–FR13: reading dates written in a calendar, years of the calendar, rejecting dates the calendar does not have, completeness for FR12, and committed text that reads back as the same date. It also adds the helper for AR2's example date. No component reads typed text with it yet; #9643 wires it into the fields.User need
People who use a calendar other than the Gregorian calendar need to type dates the way their locale writes them in that calendar:
۱۴۰۵/۸/۱۱,1 Adar 5784,令和元年5月1日. The existingparseDateInputreads English month names and ASCII digits in Gregorian only. One parser that works for every calendar keeps the fields' behavior the same across calendars.Problem and solution fit
utils/calendarDateParser.ts, built fromIntloutput (through Core'splainDateFormatandplainDateFormatToParts) and validated byTemporal:2026is Buddhist year 2026. The committed text and the format hint add the short era where the locale's format omits it and the era keeps the field order, in every calendar with eras other than the Chinese and Dangi calendars. fix(utils): read back calendar text in Latvian, Amharic and Hindi #9840 adds the narrow-era and earlier-era cases that FR10 needs for the Japanese and Minguo calendars.formatCalendarDate:formatCalendarDateandformatCalendarDateToPartsinutils/calendarSystem.tsgain arelatedYearoption. With it, a Chinese or Dangi year that the locale writes only by its place in the 60-year cycle becomes the related Gregorian year, because a typed year must be a number to read back. The parser's committed text and format hint call it, so the parser keeps no copy of that formatting. Inde-DE, the field writes 2 November 2026 in the Chinese calendar as24. M09 2026.Calendardoes not pass the option: its day names and announcements stay as they are, such asMontag, 24. M09 bing-wu, and match its heading.calendarDateFromFieldsrejects 30 Esfand in a common Persian year.nearestAcceptedDateinutils/plainDate.ts: today when a field accepts it, else the nearest date withinmin,maxand the disabled days. feat(DateInput, DateTimeInput, DateRangeInput): type, pick and show dates in the active calendar #9643's format hint uses it. It is not exported from@astryxdesign/core/utils.parseDateInputis unchanged.INVISIBLE_CHARSand, for pasted text, the bidi embedding and override characters (U+202A–U+202E). The shared set inutils/unicodeDigits.tsis unchanged, so NumberInput's number parser and the time parser inutils/timeFormat.tsread text as before.ʻ(U+02BB) thatIntlwrites in the English Islamic month names, such asDhuʻl-Hijjah; U+02BF folds the same way.Intlrule approves the parser at its own path, with valid and invalid cases.Current specification
spec:AST-111FR9–FR13, AR2 and DEC-4 (approved in spec(AST-111): date components use the calendar the application chooses #9605). The component records take these requirements in feat(DateInput, DateTimeInput, DateRangeInput): type, pick and show dates in the active calendar #9643, where the fields use the parser.architecture:internationalizationlistscalendarDateParser.tsunder Owning code, among the shared locale-sensitive parsers that INV8 names.Public delta and caller burden
nearestAcceptedDateand therelatedYearoption are internal and not exported. NumberInput and time text read as before.Calendaroutput is unchanged, and so is every other component's: no component writes or reads text with the parser yet. The changeset says that Calendar output does not change.Design and alternatives
spec:AST-111DEC-4). DEC-4 rejects segmented fields.Intlfor the locale and calendar, so the parser reads what the same runtime writes.formatCalendarDate, the helper behind Calendar's day names, with therelatedYearoption:Temporal's day,Intl's names, and the related Gregorian year. Display and parsing agree in one runtime, and one code path writes both Calendar's names and the field's text.Evidence
enandsv-SE, with zero failures.calendarDateParser.roundtrip.test.tssamples this matrix in CI, plus locales with weekday words that name months or eras, month names with digits, and cycle years. Dates before 1900 are best effort.Dhu'l-Hijjah 10, 1447 AHtyped with a straight, curly orʻapostrophe or a backtick inislamic-umalqura.calendarDateParser.test.tschecks that the field'sdate_longtext in the Chinese and Dangi calendars, inde-DEandja, carries the related year2026and reads back as the same date (FR13). Without the option, thede-DEcase fails: the text is24. M09 bing-wu.Scope
Testing
pnpm exec vitest run --maxWorkers=4over the parser, its round trip,calendarSystem,plainDateandCalendar.calendarSystems.test.tsx, on currentmain: 5 files, 294 tests pass. CI runs the full suites.pnpm exec tsc --noEmit -p packages/core: clean.pnpm check:knowledge,pnpm check:changesets: pass.node scripts/pre-review.mjs --base origin/main: 1,995 authored lines.Writing rubric results
Record:
architecture:internationalization. One line changes: Owning code addspackages/core/src/utils/calendarDateParser.tsto the shared locale-sensitive formatters, parsers, and collation that INV8 names.