Skip to the content

Hikidashi引き出し

Era dates (和暦) and kanji numerals both ways, the dictionary forms of a conjugated word, a reading shared out over its kanji, words pulled from pasted text, and how hard a sentence is to read.

Hikidashi (引き出し) is a drawer: each tool is pulled out when it is wanted. About the name

Contents

Reference

Era years

import { … } from "@johnmorrisdotca/hikidashi/wareki";

1.3 kB minified and gzipped, with everything it imports (measured with esbuild)

和暦: Japanese era years, and the Western years and dates they name, both ways.

Working out what 平成3年 is means knowing where the era started and subtracting one, which is exactly the arithmetic nobody wants to do in their head while reading a form, a coin or somebody's birth year. This goes from an era year to a Western year (parseEraYear), from a Western year or a date to the era year it falls in (eraYearOf, eraYearsOf, eraOnDate), and writes the answer (formatEraYearJapanese).

Five eras, back to 明治. Not because the earlier ones do not exist, since there are two hundred and more, but because 1868 is where the modern calendar begins, and a date before it is a history question rather than a reading one. Every date here is in the Gregorian calendar.

An era changes partway through a Western year, so a year can belong to two of them: 1989 is 昭和64 until 7 January and 平成1 from the 8th. eraYearsOf answers with both; eraOnDate says which one a day is in.

Exports

NameKindWhat it is
eraOnDatefunctionThe era year a day is in, from YYYY-MM-DD or a Date.
EraYeartypeAn era year that parsed or was found, and the Western year it names: what parseEraYear, eraYearOf, eraYearsOf and eraOnDate give.
eraYearOffunctionThe era year a Western year is usually written as: the newest era's, so 1989 is 平成1 and 2019 is 令和1.
eraYearsOffunctionEvery era year that falls in a Western year, the newest era first.
formatEraYearJapanesefunctionThe era year as it is written in Japanese: 平成3年.
formatEraYearRomajifunctionThe era year as it is written in Latin letters: Heisei 3.
JAPANESE_ERASconstantThe five modern eras, oldest first: 明治, 大正, 昭和, 平成 and 令和.
JapaneseEratypeAn era, as it is written, said and counted: one row of JAPANESE_ERAS.
parseEraYearfunctionThe era year a text names, or null when it does not name one.
westernYearForfunctionThe Western year an era year falls in, or null when the era never had that year.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/hikidashi 1.1.0.