Skip to content

Instantly share code, notes, and snippets.

@tadd
Last active November 9, 2025 08:08
Show Gist options
  • Select an option

  • Save tadd/cb4276e57fbf21fa4dd3bba453c4285e to your computer and use it in GitHub Desktop.

Select an option

Save tadd/cb4276e57fbf21fa4dd3bba453c4285e to your computer and use it in GitHub Desktop.
大化の改新が二回起こる件について(蘇我入鹿は二度死ぬ)
const [localeYear, localeLongDate] = [{year: 'numeric'}, {dateStyle: 'long'}].map(o =>
d => d?.toLocaleString("ja-JP-u-ca-japanese", o));
const isoDate = d => d?.toISOString().slice(0, "yyyy-mm-dd".length);
const d = new Date(643, 0, 1); // 643-01-01
const n = 365 * 4; // ~ 4 years
let yPrev, dPrev;
for (let i = 0; i < n; i++) {
const y = localeYear(d);
if (y !== yPrev) {
const l = [dPrev, d].map(e => e && `${localeLongDate(e)} (${isoDate(e)})`);
console.log(l.join(' -> '));
yPrev = y;
}
dPrev = new Date(d); // clone
d.setDate(d.getDate() + 1);
}
$ node -v
v25.1.0
$ node taika.js
-> 大化-2年12月29日 (0642-12-31)
大化-2年12月31日 (0643-01-02) -> 大化元年1月1日 (0643-01-03)
大化元年12月31日 (0644-01-02) -> 大化0年1月1日 (0644-01-03)
大化0年12月31日 (0645-01-02) -> 大化元年1月1日 (0645-01-03)
大化元年12月31日 (0646-01-02) -> 大化2年1月1日 (0646-01-03)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment