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:
| Helper | Does | Rule |
|---|---|---|
toMoney(locale, currency) | formats an amount in minor units (cents) as money | The 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.
| Rule | Why |
|---|---|
| No helper hard-codes a locale or currency | An app ships in more than one market |
| Every helper has tests, including zero, negative, the largest value and every supported locale | These helpers run on every screen that shows money or time |
3. API
| Name | Signature (pseudocode) |
|---|---|
toMoney | Long.toMoney(locale: Locale, currency: Currency): String |
toRelative | Instant.toRelative(now: Instant, locale: Locale): String |
4. Open questions
None left. Settled in review (2026-10-02):
- Shrunk to
toMoneyandtoRelative. 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.