Skip to content

Add locale-aware currency and date/time formatting #22

Closed

Description

@khaira777

Summary

Add locale-aware currency and date/time formatting using Intl.NumberFormat and Intl.DateTimeFormat.

Part of epic: #18
Blocked by: #21 (Phase 3 — tenant country config)

Scope

  • Replace formatCurrency() with Intl.NumberFormat
  • Store all timestamps in UTC
  • Display in tenant's timezone using Intl.DateTimeFormat
  • Locale-aware date formats (MM/DD/YYYY vs DD/MM/YYYY)

Files Touched

  • frontend/src/lib/countries.ts (formatting utilities)
  • Various components using currency/date display
  • main/routes/orders.ts (ensure UTC storage)

Acceptance Criteria

  • Currency is formatted using Intl.NumberFormat with tenant's locale
  • Dates display in tenant's timezone
  • Date format matches locale (US: MM/DD/YYYY, EU: DD/MM/YYYY, etc.)
  • Timestamps are stored in UTC in the database
  • No regression in existing currency/date display

Notes

  • This is the "polish" phase — makes the app feel truly worldwide
  • Intl.NumberFormat handles currency symbols, decimal separators, and grouping automatically
  • Timezone handling requires careful testing across DST boundaries

Activity

  1. added
    enhancement
    on Jul 6, 2026
  2. khaira777 commented on Jul 6, 2026

    @khaira777
    ContributorAuthor

    Part of epic #18 — Internationalization

  3. added theissue type on Jul 6, 2026
  4. carvalab commented on Jul 15, 2026

    @carvalab
    Contributor

    Hey @khaira777, ran a quick comparison for the formatCurrency swap in this issue. Note: main/countries.json is the current shared config I'm working on so we keep one implementation for both back and front.

    For each country I formatted a sample amount using the standard Intl call:

    new Intl.NumberFormat(country.locale, {
      style: 'currency',
      currency: country.currency, // ISO code, e.g. 'INR'
    }).format(amount)

    Then compared the resulting symbol against country.currencyCode from main/countries.json. 19 of 36 match, 17 differ.

    CODE | NAME                 | LOCALE   | ISO   | STORED   | INTL     | STATUS
    -----+----------------------+----------+-------+----------+----------+-------
    IN   | India                | en-IN    | INR   | ₹        | ₹        | OK
    AR   | Argentina            | es-AR    | ARS   | AR$      | $        | DIFF
    US   | United States        | en-US    | USD   | $        | $        | OK
    CA   | Canada               | en-CA    | CAD   | C$       | $        | DIFF
    GB   | United Kingdom       | en-GB    | GBP   | £        | £        | OK
    EU   | European Union       | fr-FR    | EUR   | €        | €        | OK
    TH   | Thailand             | th-TH    | THB   | ฿        | ฿        | OK
    SG   | Singapore            | en-SG    | SGD   | S$       | $        | DIFF
    MY   | Malaysia             | ms-MY    | MYR   | RM       | RM       | OK
    ID   | Indonesia            | id-ID    | IDR   | Rp       | Rp       | OK
    PH   | Philippines          | en-PH    | PHP   | ₱        | ₱        | OK
    VN   | Vietnam              | vi-VN    | VND   | ₫        | ₫        | OK
    AU   | Australia            | en-AU    | AUD   | A$       | $        | DIFF
    NZ   | New Zealand          | en-NZ    | NZD   | NZ$      | $        | DIFF
    AE   | United Arab Emirates | ar-AE    | AED   | د.إ      | د.إ.     | DIFF
    SA   | Saudi Arabia         | ar-SA    | SAR   | ﷼        | ر.س.     | DIFF
    ZA   | South Africa         | en-ZA    | ZAR   | R        | R        | OK
    KE   | Kenya                | en-KE    | KES   | KSh      | Ksh      | DIFF
    NG   | Nigeria              | en-NG    | NGN   | ₦        | ₦        | OK
    BR   | Brazil               | pt-BR    | BRL   | R$       | R$       | OK
    MX   | Mexico               | es-MX    | MXN   | MX$      | $        | DIFF
    CL   | Chile                | es-CL    | CLP   | CLP$     | $        | DIFF
    UY   | Uruguay              | es-UY    | UYU   | UYU$     | $        | DIFF
    PY   | Paraguay             | es-PY    | PYG   | ₲        | Gs.      | DIFF
    JP   | Japan                | ja-JP    | JPY   | ¥        | ¥        | DIFF
    KR   | South Korea          | ko-KR    | KRW   | ₩        | ₩        | OK
    CN   | China                | zh-CN    | CNY   | ¥        | ¥        | OK
    HK   | Hong Kong            | zh-HK    | HKD   | HK$      | HK$      | OK
    TW   | Taiwan               | zh-TW    | TWD   | NT$      | $        | DIFF
    PK   | Pakistan             | en-PK    | PKR   | Rs       | Rs       | OK
    BD   | Bangladesh           | bn-BD    | BDT   | ৳        | ৳        | OK
    LK   | Sri Lanka            | en-LK    | LKR   | Rs       | LKR      | DIFF
    NP   | Nepal                | ne-NP    | NPR   | Rs       | नेरू     | DIFF
    EG   | Egypt                | ar-EG    | EGP   | E£       | ج.م.     | DIFF
    IL   | Israel               | he-IL    | ILS   | ₪        | ₪        | OK
    TR   | Turkey               | tr-TR    | TRY   | ₺        | ₺        | OK
    

    Diffs cluster into a few patterns:

    • Multi-$ loses prefix in en-locales: 9 currencies drop to plain $. For the American countries (AR, MX, CL, UY) using plain $ is fine: a receipt for a customer in Buenos Aires, Mexico City, Santiago, or Montevideo already reads as local currency because of the locale and grouping, and the disambiguation prefix only matters when receipts sit side-by-side across countries.
    • PY uses Gs. not ₲: Intl drops the dedicated guaraní sign (U+20B2) and uses the Gs. abbreviation instead. Customers in Asunción read Gs. as guaraní the same way Swedes read kr for krona, so this is fine.
    • Arabic currencies swap glyph: AE د.إ → د.إ., SA ﷼ → ر.س., EG E£ → ج.م.
    • Case/width: KE KSh → Ksh, JP ¥ → ¥
    • Symbol drift in JSON: LK Rs → LKR, NP Rs → नेरू (Intl fixes these)

    The grouping and decimal separators are nice side effects: IN uses lakh style (₹12,34,567.89), AE/SA/EG use Arabic-Indic digits, BR flips to . and ,, PY drops decimals because PYG is conventionally shown without them.

    Net breakdown if we accept the LatAm trade-off: 5 LatAm rows OK as-is (AR, MX, CL, UY with plain $, PY with Gs.), 5 multi-$ still to discuss (CA, SG, AU, NZ, TW), 3 Arabic, 2 case/width, 2 fixed-by-Intl.

    About the American countries (AR, MX, CL, UY, PY): it is fine to use Intl's output there. For AR/MX/CL/UY that means plain $ instead of AR$, MX$, CLP$, UYU$; for PY it means Gs. instead of ₲. Customers in those markets already read these as their local currency thanks to the locale (es-AR, es-MX, es-CL, es-UY, es-PY) and the grouping ($ 1.234.567,89 for AR/UY, $1,234,567.89 for MX/CL, Gs. 1.234.568 for PY). The prefixes and the dedicated ₲ glyph are only useful when receipts sit side-by-side across countries or against a reference document, which is not a real scenario for a single-tenant POS. So those 5 rows can drop the custom symbol without losing meaning.

    Before I swap the implementation: are the remaining 12 symbol differences (CA, SG, AU, NZ, TW, AE, SA, EG, KE, JP, LK, NP) acceptable, or do you want a hybrid that uses Intl for grouping/decimals but falls back to the stored currencyCode for those rows?

  5. khaira777 commented on Jul 15, 2026

    @khaira777
    ContributorAuthor

    Hey @carvalab, your analysis is spot on. I agree that cross-country disambiguation isn't really a concern for local in-person receipts. Feel free to proceed with the pure Intl.NumberFormat implementation. Thanks again with your incredible contribution!

  6. khaira777 commented on Jul 18, 2026

    @khaira777
    ContributorAuthor
    • Hook useFormatDate created. Reads tenant locale + timezone from auth store.
    • Shared pure formatDate util created for non-react encoders.
    • All 20 inline toLocaleString() sites refactored.
    • Tested whatsapp-share, settings, orders, print-test, OrderHistoryGrid.
    • Status: Fully done. Tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions