# Fix Thai locale date format with the wrong Buddhist era offset

## TL;DR

Thai dates use the Buddhist calendar, 543 years ahead, so set the calendar explicitly instead of doing the math by hand. Intl with calendar buddhist handles the offset, the era name, and formatting. Hand-adding 543 breaks on edge cases like the era boundary.

## The error

```text
Thai date shows 2026 instead of the Buddhist year 2569
or a hand-rolled +543 produces the wrong era label
```

## Fix it

### Step 1: Format with the Buddhist calendar

```bash
node -e "console.log(new Intl.DateTimeFormat('th-TH-u-ca-buddhist',{dateStyle:'long'}).format(new Date()))"
```

Expected: The date shows the Buddhist year with the right era.

### Step 2: Find the hand-rolled offset code

```bash
grep -rn "543" src/utils/dates.js | head -5
```

Expected: You see where the manual math lives.

### Step 3: Replace manual math with the calendar option

```bash
node -e "console.log('use locale th-TH-u-ca-buddhist or the calendar option, delete the +543')"
```

Expected: One formatter handles year, era, and month names.

### Step 4: Check parsing too if you parse Thai input

```bash
node -e "console.log('parsing Buddhist years needs the same calendar, otherwise 2569 reads as year 2569 CE')"
```

Expected: Round-trips work.

## When to use this

- Thai dates show the wrong year or era
- You add 543 manually to get the Buddhist year

## When NOT to use this

- The year is right but the format is wrong, check dateStyle options
- You need the Gregorian year in Thailand, use the default calendar deliberately

## Tool and version compatibility

- Intl.DateTimeFormat with Unicode calendar extension
- th-TH with ca-buddhist

## Variant phrasings

### Japanese era dates

Same pattern with ca-japanese. Era boundaries there are trickier, definitely use Intl.

### other Buddhist-calendar locales

lo-LA and km-KH also use it. The calendar option works the same.

## Why it happens

Thailand's official calendar counts years from the Buddhist era, 543 ahead of Gregorian. Intl implements the calendar including era names and month handling, while hand math only shifts the number and gets eras and formatting wrong.

## Edge cases

- Year 1 Buddhist has no year zero issues in Intl, hand math can stumble there
- Date pickers need the calendar too, not just display formatting
- Sorting by formatted strings breaks across eras, sort by timestamp

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_OjtM33LByntLgeLCrY44QA
