Skip to main content

Module format

Module format 

Source
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§

DateFields
The calendar fields of an instant (in UTC; a host shifts by its zone first).
DateNames
Month, weekday and day-period names a pattern prints.
DateOptions
Date options: format (a TR35 pattern, wins) or style (default medium) + time (append the short time).
DateValue
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).
EnglishFormatter
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 of fixtures/format.json.
NumberOptions
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).
ZonedEnglishFormatter
EnglishFormatter in a surface zone: instants shift by the host’s ZoneOffset, a yyyy-mm-dd day never does (englishFormatter(zone)).

Enums§

ByteUnit
A byte-size unit (Formatter::bytes; the CLDR unit ids).
DateStyle
A date preset (style).
PluralCategory
A CLDR plural category.
RelativeUnit
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 + core formatPercent, formatRelativeTime), all through ONE formatter.

Statics§

ENGLISH
The shared English formatter.

Traits§

Formatter
What a host supplies per surface (in SurfaceSettings.locale and its own time zone). The core parses date values and picks the relative unit; the formatter localizes. EnglishFormatter is the default.

Functions§

call_format_function
One format function over formatter; now = the clock formatRelativeTime reads without a now argument. 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_string of an optional value (absent = ``).
display_string
What a string/markdown prop SHOWS for a bound value: strings as they are, finite numbers as ECMAScript Number.prototype.toString (412, 1.5, 1e-7, 1e+21, -0 → 0), booleans true/false; null, non-finite numbers, objects and arrays show nothing. No locale (use formatNumber). src/format.ts displayString.
english_names
The English names (englishFallback).
fixed_digits
decimals as 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 value against now_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-time yyyy-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 off formatter.number(…); group separators, spaces and bidi marks drop, the decimal becomes ., −/– become -. None when 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§

ZoneOffset
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).