# Computing Japanese holidays from the law, a squawk decoder that only lists what it can source, and WCAG ratios that must be truncated

> Three more small tools: Japanese holidays and long weekends, a squawk code decoder, and a WCAG contrast checker. Holidays are computed from the law, squawk lists only sourced codes, and contrast ratios must be truncated.

- Date: 2026-11-30
- Topics: Data, Accessibility
- Chinese original: https://kbs0830.com/blog/holidays-squawk-contrast-tools

I asked myself "what other small tools could I build", made a list, and this time built three at once:

- **Japanese holidays and long weekends**: pick a year and see the national holidays and the long weekends
- **Squawk code decoder**: what is that 4-digit number on an aircraft radar
- **Color contrast checker**: do the text and background colors pass WCAG

(All three tool pages are in Chinese.) What the three share is that **it is very easy to write them so they "look right" while a detail is wrong**. Here is how I handled each.

## 1. Holidays: compute them from the law, don't type a list

The laziest approach is to type each year's holidays into a table. But then it needs editing every year, a mistake goes unnoticed, and how far do you type, to 2099? So I compute them from the rules of the Act on National Holidays (Kokumin no Shukujitsu ni kansuru Horitsu):

| Rule | How it is computed |
|---|---|
| Fixed dates | Ganjitsu (New Year's Day) 1/1, Kenkoku Kinen no Hi (Foundation Day) 2/11, Tenno Tanjobi (Emperor's Birthday) 2/23, Showa no Hi 4/29, Kenpo Kinenbi (Constitution Memorial Day) 5/3, Midori no Hi (Greenery Day) 5/4, Kodomo no Hi (Children's Day) 5/5, Yama no Hi (Mountain Day) 8/11, Bunka no Hi (Culture Day) 11/3, Kinro Kansha no Hi (Labor Thanksgiving Day) 11/23 |
| Nth Monday | Seijin no Hi (Coming of Age Day, 2nd Monday of January), Umi no Hi (Marine Day, 3rd Monday of July), Keiro no Hi (Respect for the Aged Day, 3rd Monday of September), Sports no Hi (Sports Day, 2nd Monday of October) |
| Spring and autumn equinox | The law only says "the day of the spring equinox" and "the day of the autumn equinox", which differ every year, so I use an approximate formula (below) |
| Furikae kyujitsu (substitute holiday) | A holiday falling on a Sunday → the nearest following day that is **not a holiday** is a day off |
| Kokumin no Kyujitsu (citizens' holiday) | A weekday sandwiched between two holidays is a day off (Sundays and substitute holidays do not count) |

**The Nth Monday** uses a small formula: work out the weekday of the 1st of the month, find the first Monday after it, then add 7 days for each further one.

**The equinoxes** use the approximate formula that is valid for 1980–2099:

```ts
const springEquinox = (y: number) => Math.floor(20.8431 + 0.242194 * (y - 1980)) - Math.floor((y - 1980) / 4);
const autumnEquinox = (y: number) => Math.floor(23.2488 + 0.242194 * (y - 1980)) - Math.floor((y - 1980) / 4);
```

This is an approximation, not an astronomical calculation: the actual dates are announced by the National Astronomical Observatory of Japan each February for the following year. So the supported years are limited to 2022–2099, and the page says "the Cabinet Office and the National Astronomical Observatory announcements are authoritative". 2019 (change of era) and 2020–2021 (the Tokyo Olympics moved Marine Day, Sports Day and Mountain Day) had special cases that I did not implement, so those years are not supported.

**For substitute holidays** the key is "look for the first following day that is not a holiday", not just adding one day:

```ts
let d = addDays(x.date, 1);
while (set.has(d)) d = addDays(d, 1); // skip consecutive holidays
```

In 2026, May 3 is a Sunday, and May 4 and 5 are also holidays, so the substitute day is May 6, not May 4.

### Verifying: compare with the Cabinet Office's dates

The Cabinet Office has already published the holidays for 2026 and 2027. The unit tests compare against them directly:

- 2026: Coming of Age Day 1/12, spring equinox 3/20, Marine Day 7/20, Respect for the Aged Day 9/21, autumn equinox 9/23, Sports Day 10/12; the substitute holiday 5/6, the citizens' holiday 9/22; 16 holidays + 1 substitute + 1 citizens' holiday, 18 days in all.
- 2027: the spring equinox 3/21 falls on a Sunday → 3/22 is a substitute holiday; Marine Day 7/19, Sports Day 10/11, autumn equinox 9/23.

I also tested that the fixed dates are all present every year and that a citizens' holiday never falls on a Sunday. **What is not verified is 2028 and later**: for the formula's results I have no official dates to compare against.

### Long weekends: does the year-end and New Year period count?

I define a long weekend as "3 or more consecutive days off". Days off include Saturdays, Sundays and holidays, which nobody disputes. My first test expected "December 2026 will have a year-end and New Year long weekend", and found none, because 12/29–1/3 are **not national holidays**; they are only days when government offices are closed (under the Act on Holidays of Administrative Organs), and most companies follow. In 2026, 12/31 is a Thursday and 1/1 is the holiday, so looking only at weekends plus holidays, December has no long weekend at all.

For trip planning this stretch is the most important of all, so I changed it: **12/29–1/3 is explicitly counted as days off**, labeled "Nenmatsu-nenshi (year-end and New Year, government offices closed)" in the long-weekend description, and the page says "not a national holiday". The results:

- Golden Week 2026: 5/2 (Sat) → 5/6 (Wed), 5 days
- Silver Week 2026: 9/19 (Sat) → 9/23 (Wed), 5 days
- Year-end and New Year: 2026-12-29 (Tue) → 2027-01-03 (Sun), 6 days

A long weekend that crosses the year **counts in the year it starts**, so 2027's list does not count the stretch above a second time. Obon (around 8/13–16) is a break each company decides for itself, and is not counted.

## 2. Squawk: list only what can be sourced

A squawk code is the 4-digit number an aircraft's transponder reports to secondary radar; each digit is only 0–7 (octal), 4,096 codes in all. This tool looks like just a "lookup", and the risk is actually in the table: there are many code tables online, inconsistent with each other, and it is very easy to copy a wrong one.

My approach is to **list only codes I found a source for, where the sources agree**:

| Code | Meaning | Scope |
|---|---|---|
| 7500 | Hijacking (unlawful interference) | Worldwide (ICAO) |
| 7600 | Radio communication failure | Worldwide (ICAO) |
| 7700 | General emergency | Worldwide (ICAO) |
| 1200 | VFR (visual flight rules) | USA, Canada |
| 7400 | Drone that has lost its control link | USA |
| 7000 | VFR (visual flight rules) | Most European countries (common) |

When confirming through searches, I did not find FAA's original regulation, only code tables on aviation websites and wikis. What I **confirmed** is only 7500 / 7600 / 7700 / 1200 / 7400. I also wanted to add 1202, 1255, 1277 and 7777, but not one search result mentioned their use, so I **left them out**. For 7000, the explanation only appeared in an article title; I know it is a commonly used VFR code in Europe but did not find the original regulation, so it is marked "common" instead of stated as certain.

For codes not listed, the tool does not guess; it answers "not a common special code; for most aircraft the squawk is assigned by a controller for the moment and has no meaning in itself". Input containing an 8 or a 9 is simply declared invalid (octal).

## 3. Contrast: the ratio must not be rounded

The WCAG 2.x contrast formula is not complicated: relative luminance L = 0.2126 R + 0.7152 G + 0.0722 B (RGB converted to linear first), and contrast = (lighter L + 0.05) ÷ (darker L + 0.05). The real detail is in the **verdict**: the WCAG threshold is "greater than or equal to 4.5", and **it must not be rounded**. 4.499 does not pass.

So when displaying, always **truncate** to two decimals:

```ts
export const formatRatio = (r: number) => (Math.floor(r * 100 + 1e-9) / 100).toFixed(2);
```

With `toFixed(2)`, 4.499 would show as "4.50"; the user sees "4.50 ≥ 4.5" and thinks it passes, when it does not.

You often see "#777 on white is 4.48" online. My test also expected that at first, but the actual computation is 4.478, which is 4.48 rounded and **4.47** truncated. That is also why I verify the arithmetic when writing tests instead of copying numbers from the web. The values I pinned:

- Black on white 21:1
- #767676 on white 4.54 (just passes AA)
- #777777 on white 4.47 (just misses)
- The site's own accent color, secondary text and the matching dark mode colors are all ≥ 4.5

The last item is a side check of the site's own design: `#2d5a8e` on `#fafaf8`, `#6b6b6b` on `#fafaf8`, and dark mode's `#6295cc` on `#0f0f0d` all pass AA.

The **suggested color** only adjusts the text color's lightness (HSL L), keeping hue and saturation unchanged, so it stays in the same color family: it steps in the direction that increases contrast until the target is met. If it cannot be reached that way it tries the opposite direction, and if neither works it reports "cannot be reached; the background has to change too". The tool does not pretend to solve every color problem, and the page says "contrast is only one part of accessibility, and does not mean the whole page is compliant".

## Tests where I was the one who was wrong

None of the test failures this time was a bug in the code:

1. **I assumed the year-end and New Year period would be counted as a long weekend automatically**: it is not, as explained above; my definition was not thought through.
2. **I wrote #777's ratio as 4.48**: I copied the rounded number from the web.
3. **An assertion that "2027 has no January long weekend" went too far**: 2027 has a three-day weekend from 1/9 to 1/11 for Coming of Age Day; what I should assert is "no stretch starts between 1/1 and 1/3".
4. **E2E `getByText` grabbed explanation text further down the page**: the strings "4.47" and "both sides are holidays" appear in both the result area and the explanation paragraphs, and Playwright's strict mode threw. I changed it to `exact: true` or added surrounding context ("4.47 :").

The lesson of the last two is the same: the explanation text at the bottom of a page often contains the same words as the results, so E2E locators need to be precise.

## What was verified and what was not

- All 619 unit tests in the project pass; type check and eslint are clean.
- 7 new E2E tests, plus the a11y scan, sitemap, tool pages and Ctrl+K, 30 passing in all.
- I measured the holiday, contrast and squawk pages at phone width (375px) and there is no horizontal scrolling.
- **Not verified:** for 2028 and later holidays there are no official dates to compare against; years before 2022 are unsupported; squawk has no original regulation to cite, only "the sources agree"; contrast covers only WCAG 2.x, not WCAG 3's APCA.

## Summary

- For things whose rules change and differ every year (holidays), computing from the rules is more reliable than typing a list, but an approximate formula must state its limits and be checked against the years officially announced.
- The risk of a lookup tool is in the table: list only what has a source, write "not sure" when you cannot find one, and do not fill in something that looks plausible.
- If the spec says "must not be rounded", display must truncate; compute test expectations yourself instead of copying numbers from the web.
- For a question of definition like long weekends, first think about what the user wants to plan, then decide whether the year-end and New Year period counts.
- The explanation text at the bottom of a page may contain the same words as the results, so E2E locators must be precise.

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/holidays-squawk-contrast-tools
