westernYearForfunction
The Western year an era year falls in, or null when the era never had that year.
Minus one, because an era's first year is year one rather than year zero: 平成1年 is 1989, the year the era began, not the year after it. 昭和65 is null, since 昭和 ended in its 64th year.
Import it
import { westernYearFor } from "@johnmorrisdotca/hikidashi/wareki";
Also exported from: @johnmorrisdotca/hikidashi
Definition
function westernYearFor(era: JapaneseEra, year: number): number | null
Parameters
| Name | Type | Description |
|---|---|---|
era | JapaneseEra | One of |
year | number | The year within the era, counting from 1 (元年 is 1). |
Returns
number | null
The Western year, or null when year is not a whole number from 1 to the era's last year (99 for the era
still running): null means the era never had that year, never "unknown".
Examples
import { JAPANESE_ERAS, westernYearFor } from "@johnmorrisdotca/hikidashi/wareki";
const showa = JAPANESE_ERAS.find((era) => era.kanji === "昭和")!;
console.log(westernYearFor(showa, 64), westernYearFor(showa, 65));1989 nullWhat it prints (run when this page was built)