Repository navigation
fix(core): honor TR35 quoted literals and EEE in formatDate - #3787
Open
karolkulesza wants to merge 5 commits into
Open
karolkulesza wants to merge 5 commits into
karolkulesza wants to merge 5 commits into
Conversation
The formatDate tokenizers in web_core, Python a2ui_core (v0.9 and v1.0) and Dart a2ui_core did not know TR35 quoted literals or EE/EEE, so "MMM d 'at' h:mm a" rendered "Feb 2 'PMt' 3:17 PM" and "EEE" rendered "MonMonMon". Each token regex now matches '' as an apostrophe and '...' as a literal (with '' inside it as an apostrophe; an unclosed quote runs to the end, as in date-fns), and maps EEE and EE to the short weekday. Add time-zone-neutral functions.yaml cases for a quoted literal, an escaped apostrophe and EEE/EE, plus unit tests in each SDK. Swift uses DateFormatter and passes the new cases unchanged. Fixes a2ui-project#2937
1 task done
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the formatDate function across Dart, Python, and TypeScript implementations to support TR35 pattern tokens, quoted literals (where text in single quotes is copied through literally and '' is rendered as a single apostrophe), and short weekday tokens (EEE and EE). Unit tests and conformance tests have been added to verify these changes, and the changelogs have been updated accordingly. There are no review comments, so I have no additional feedback to provide.
This branch has not been deployed
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.
Description
formatDatetakes a Unicode TR35 pattern, but the hand-written tokenizers in web_core, Pythona2ui_core(v0.9 and v1.0) and Darta2ui_coredidn't know quoted literals orEE/EEE. With2026-02-02T15:17:09Z:"MMM d 'at' h:mm a"gaveFeb 2 'PMt' 3:17 PM: theain'at'was read as AM/PM and the quotes were kept."EEE, MMM d"gaveMonMonMon, Feb 2."h 'o''clock'"gave3 'o''clock'.Two v0.9.1 basic catalog examples use a quoted literal (16_workout-summary.json, 30_live-invitation-builder.json), so both render wrong today. Swift uses
DateFormatterand was already correct.Changes:
''(an apostrophe) and'...'(a literal, where''inside stands for an apostrophe) before any pattern letter. An unclosed quote runs to the end of the pattern, as in date-fns, which web_core used before 0.12.0.EEEandEEgive the abbreviated weekday, likeE.src/common/basic_functions.tsbasic_catalog/v0_9/function_impls.pyandbasic_catalog/v1_0/function_impls.pylib/src/basic_catalog/locale_formatting.dartconformance/core/functions.yaml: three new cases,test_evaluate_function_format_date_quoted_literal,..._escaped_apostropheand..._short_weekday. They use noon UTC values and keep hour tokens inside the quotes, so they give the same result in any host time zone (Swift still formats in the local zone, see fix(swift): keep the written wall-clock time in formatDate and accept timestamps without an offset #3380).## Unreleasedentries in the web_core, Pythona2ui_coreand Darta2ui_corechangelogs.The
formatdescription in the basic catalog doesn't mention quoting orEEE. Changing it regenerates fixtures in every SDK, so I left it for a follow-up.Testing:
yarn test(0 failures),node tests/conformance/conformance_test.mjs, eslint and prettier on the touched files.uv run pytestfrom the repo root (3783 passed),uv run pyink --check .,uv run --all-packages mypy ..dart/a2ui_core):dart test,dart analyze,dart format --set-exit-if-changed.swift/core):swift test --filter BasicCatalogConformancepasses the new cases unchanged withTZset to UTC, Europe/Warsaw, America/Los_Angeles and Asia/Tokyo.Fixes #2937
Pre-launch Checklist
One time:
For this PR:
formatDateis documented as taking a TR35 pattern, which already includes quoting andEEE.)If you need help, consider asking for advice on the discussion board.