# Locale-Aware Numbers and Dates

## Objective

Show and read dates, numbers, and money the way each user writes them.

A shared formatting and parsing layer so numbers, currency, percentages, dates, and times render and are read correctly per locale and time zone.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Find every place the app formats a number, currency, percentage, date, or time, and route them through one shared helper instead of scattered format strings.
2. Store and transmit locale-neutral values: ISO 8601 timestamps in UTC, and numbers as numbers. Format only at the point of display.
3. Format currency with the currency's own decimal rules and the locale's symbol placement — some currencies have no decimal places and some put the symbol after the amount.
4. Parse user input against the active locale so that typing 1.000,50 is read as one thousand and a half, and reject ambiguous input with a clear message rather than guessing.
5. Render dates and times in the user's stored time zone, and show the zone anywhere a time is actionable such as a meeting or a deadline.
6. Do NOT use a bare numeric date format like 03/04/2026 anywhere it matters. It reads as two different days on two continents; use an abbreviated month name instead.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Do not assume the browser time zone is the user's — a traveller's laptop lies. Store an explicit preference and let them change it.
- Daylight saving transitions mean a day is not always 24 hours; date arithmetic done in UTC and displayed locally will drift by an hour twice a year.
- Relative times such as 'in 3 hours' go stale on a page left open; refresh them or use an absolute time in tooltips.
- Never do money arithmetic in floating point. Work in minor units and format at the end.
- Right-to-left locales still render digits left to right; do not manually reverse numeric strings.
- A number input on mobile shows a keypad matching the browser locale, which may not match the app's active locale — accept both separators where it is unambiguous.
- Sorting and grouping by date must use the user's time zone, or rows land in the wrong day bucket near midnight.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] All display formatting goes through one shared layer.
- [ ] Stored and transmitted values are locale-neutral, UTC where applicable.
- [ ] Currency respects per-currency decimal rules and per-locale symbol placement.
- [ ] Typed input is parsed against the active locale, and ambiguous input is rejected with a clear message.
- [ ] Times display in the user's stored time zone, with the zone shown for actionable times.
- [ ] No ambiguous all-numeric date format appears in the interface.
- [ ] Monetary calculations use minor units, not floats.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
