Skip to main content
cngx-src documentation

dateTimeFormatterFor

Functioncore/utilsv0.1.0

projects/core/utils/intl-format.util.ts

Description#

Bounded Intl.DateTimeFormat cache keyed on locale + options. Constructing an Intl formatter is the expensive half of formatting; this makes repeated formatting allocation-free. Consumers bind static option literals, so the key space stays tiny; the FIFO cap guards a consumer generating per-row options (e.g. varying timeZone) from growing the cache for the app's lifetime.

Keys serialize via JSON.stringify, so two option objects with different property order occupy two (bounded) cache slots - they still format identically.

Signature#

dateTimeFormatterFor(locale: string, options)

Parameters#

@paramlocalestring
@paramoptions

Returns#

Intl.DateTimeFormat