Skip to main content

03 - Extensions

1. Why​

Every app carries a file of small helpers: formatting money and dates, debouncing input, null-or-empty checks. Copied from project to project, they collect bugs: a currency hard-coded to one country, a date format that ignores the user's locale, a null check with its condition inverted.

sinew_extensions would hold a small, tested set of these helpers, written fresh with locale awareness. It would never be ported as-is from older code.

2. Shape​

Shrunk in review to the two helpers the platforms don't already provide:

HelperDoesRule
toMoney(locale, currency)formats an amount in minor units (cents) as moneyThe currency is always passed in, never assumed. Amounts are minor units, never floating point.
toRelative(now, locale)formats an instant as relative time ("3 minutes ago")Always in the user's locale. Formatting happens only in presentation.

Dates, plain numbers, debouncing and null checks use the platforms' own locale-aware formatters and the languages' built-in helpers.

RuleWhy
No helper hard-codes a locale or currencyAn app ships in more than one market
Every helper has tests, including zero, negative, the largest value and every supported localeThese helpers run on every screen that shows money or time

3. API​

NameSignature (pseudocode)
toMoneyLong.toMoney(locale: Locale, currency: Currency): String
toRelativeInstant.toRelative(now: Instant, locale: Locale): String

4. Open questions​

None left. Settled in review (2026-10-02):

  • Shrunk to toMoney and toRelative. For dates, numbers and null checks, the platforms' own locale-aware formatters and the languages' null helpers are enough. A short "how to format" section in the presentation docs covers them.