Expand description
Round 2 (docs/round-2-contract.md §3): FORMATTING through a host-supplied
Formatter. Every number, currency, percent, date and relative time a
surface shows (Table cells, NumberField, chart ticks, calendar names, the
format* bind functions) goes through ONE formatter per surface, in the
surface’s locale and the host’s time zone. The default is
EnglishFormatter (catalog/locale.json englishFallback, = Intl
en-US, instants in UTC); ZonedEnglishFormatter = the same at the
host’s UTC offset (the core has no zone database: the zone reaches it
ONLY through the formatter); an FFI host passes its own (Foundation,
android.icu).
The core does the PARSING and the DECISIONS (what a date value names,
which relative-time unit, which plural arm) so every platform agrees;
a Formatter only localizes the result. Mirrors src/format.ts;
fixtures/format.json locks it.
Structs§
- Date
Fields - The calendar fields of an instant (in UTC; a host shifts by its zone first).
- Date
Names - Month, weekday and day-period names a pattern prints.
- Date
Options - Date options:
format(a TR35 pattern, wins) orstyle(default medium) +time(append the short time). - Date
Value - The instant a date value names (
parse_date_value): epoch ms, and whether it was a calendar day (yyyy-mm-dd, UTC midnight: format it in UTC, never shifted into the surface zone). - English
Formatter - The formatter a surface uses without a host one: Intl en-US decided by
data (
englishFallback), instants in UTC. Equal to Intl en-US on every case offixtures/format.json. - Number
Options - Number options:
decimals= fixed fraction digits (min = max;None= 0..3 for numbers, the currency’s minor digits, 0 for percents);grouping= locale separators (default true). - Zoned
English Formatter EnglishFormatterin a surface zone: instants shift by the host’sZoneOffset, ayyyy-mm-ddday never does (englishFormatter(zone)).
Enums§
- Byte
Unit - A byte-size unit (
Formatter::bytes; the CLDR unit ids). - Date
Style - A date preset (
style). - Plural
Category - A CLDR plural category.
- Relative
Unit - The unit a relative time is shown in (
relative_time_unit).
Constants§
- ENGLISH_
DATE_ PATTERNS - The en-US preset patterns (
style) and the time a preset appends. - ENGLISH_
TIME_ PATTERN - FORMAT_
FUNCTION_ NAMES - The bind-time format functions (A2UI basic
formatNumber,formatCurrency,formatDate,pluralize+ coreformatPercent,formatRelativeTime), all through ONE formatter.
Statics§
- ENGLISH
- The shared English formatter.
Traits§
- Formatter
- What a host supplies per surface (in
SurfaceSettings.localeand its own time zone). The core parses date values and picks the relative unit; the formatter localizes.EnglishFormatteris the default.
Functions§
- call_
format_ function - One format function over
formatter;now= the clockformatRelativeTimereads without anowargument.None= not a format function,Some(None)= an undefined result. - currency_
digits - The minor digits of a currency (ISO 4217; 2 when not listed).
- display_
opt display_stringof an optional value (absent = ``).- display_
string - What a
string/markdownprop SHOWS for a bound value: strings as they are, finite numbers as ECMAScriptNumber.prototype.toString(412,1.5,1e-7,1e+21,-0→0), booleanstrue/false; null, non-finite numbers, objects and arrays show nothing. No locale (useformatNumber).src/format.ts displayString. - english_
names - The English names (
englishFallback). - fixed_
digits decimalsas fixed fraction digits: finite → trunc, clamped to 0..20.- format_
date_ value - A date value formatted through
formatter(`` when unreadable). - format_
pattern - A TR35 pattern over fields:
y yy yyyy M MM MMM MMMM d dd E EEE EEEE h hh H HH m mm s ss a,'quoted'literals (''= an apostrophe); any other letter run is copied as written. Digits are ASCII. - format_
relative_ value - A relative time of
valueagainstnow_ms(`` when unreadable). - is_
format_ function - now_ms
- The wall clock in epoch ms.
- parse_
date_ value - The instant a date value names:
yyyy-mm-dd= that calendar day (UTC midnight,date_only), an ISO date-timeyyyy-mm-ddThh:mm[:ss[.f]][Z|±hh:mm](no offset = UTC), or epoch milliseconds; anything else =None. - parse_
number - Typed number text in the formatter’s own separators and digits (the
reference NumberField’s
parseLocaleNumber): the digits, group and decimal separator are read offformatter.number(…); group separators, spaces and bidi marks drop, the decimal becomes.,−/–become-.Nonewhen empty or unreadable. - relative_
time_ unit - The unit a delta (value − now, ms) shows in and its count (truncated toward zero): under a minute seconds, under an hour minutes, under a day hours, under 7 days days, under 30 days weeks, under 365 days months (of 30 days), else years (of 365 days).
- utc_
fields - The UTC fields of epoch
ms.
Type Aliases§
- Zone
Offset - The surface zone as the English fallback sees it: the UTC offset in minutes (east positive) in force at an instant (epoch ms). The core has no zone database: the host passes its platform’s offset (gpui: the local zone; the fixtures pin a fixed one).