wareki 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23992b6b4cd96544832ea1db1e843279eddabc6d205d2a7af87c30e29079fc7b
4
- data.tar.gz: 706f0a880da6c9a05a3fa013450aa04dbd15993d5144df7aeef92d9f49b19f4e
3
+ metadata.gz: 1559659acd73e0b2e1760b9d5d889f59f7ac592ec6ff357ebe17e9631398cd18
4
+ data.tar.gz: 9c2271acf0e4522b2bc69b00abe579e6ae10299d6d560bbd987bd88581ad578a
5
5
  SHA512:
6
- metadata.gz: d03b898c5bd3efc4087d9a9b6cfdb54526b30c7088e2a051b3bc31ae9c3994acca5607a8920ddd44f6acc1b9331ac4e62a6a82943689e3e41beb5633f165a5bc
7
- data.tar.gz: 77d82b574ff6fee3fee4c19f27faf532ac040b2fb933b9c33d86ffd1fd6deb32a6aa9c5a2c08eb4ee039594e60032c97a2a0e95d26a9489b2790d7290480073c
6
+ metadata.gz: b6e16627c6d96af8128ecba167c59c077970373f1f37dfac0f156b88478869a29d8fe04e0bcf91c77dacd482c32cc1493b6aaa2cd065915b5a6c1696a293d450
7
+ data.tar.gz: bc6ba557cff73de604dc895f95b60f0baa4ecd82c8796b1b8e3c23cb9f6395c004c213d01ea781a92a7c72145e53772cdaba0d0302ccf2585a3a20e6a2cb9c8f
data/ChangeLog CHANGED
@@ -1,3 +1,25 @@
1
+ 2026-07-13 Tatsuki Sugiura <sugi@nemui.org>
2
+
3
+ * Version: 2.1.0
4
+ * Shrink in-memory kyuureki calendar table to ~1/48 (bit-packed
5
+ one-integer-per-year representation in new internal module
6
+ Wareki::Calendar); calendar definitions now load ~30x faster
7
+ * Era definitions are now generated from manakai/data-locale
8
+ era-defs.json instead of the Wikipedia era list page
9
+ (build-util/gen-era-def.rb); corrects 正平/建徳/文中 boundaries,
10
+ 白雉/朱鳥 now cover until the end of their last kyuureki year,
11
+ and ERA_NORTH_DEFS 元徳 now ends at 正慶 transition
12
+ * Wareki.parse_to_date and patched Date.parse/_parse no longer
13
+ fall back to stdlib parsing on UnsupportedDateRange; the error
14
+ propagates again as in 1.x (reverts a 2.0.0 change)
15
+ * Cache kansuji conversion of small numbers for %J format
16
+ directives; Utils.to_simple_kan delegates non-Integer values
17
+ to YaKansuji
18
+ * Fast-path ASCII-only strings in patched Date.parse/Date._parse
19
+ * Remove internal constants Wareki::YEAR_DEFS, Wareki::YEAR_BY_NUM,
20
+ Wareki::Year and Wareki::Utils.find_year
21
+ * required_ruby_version is now >= 2.3
22
+
1
23
  2026-07-13 Tatsuki Sugiura <sugi@nemui.org>
2
24
 
3
25
  * Version: 2.0.0
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  日本の和暦をサポートするライブラリです。
12
12
  旧暦は445年から、元号は大化から全て処理できます。
13
- 元号はWikipedia、暦は日本暦日原典由来のデータを元にしています。
13
+ 元号・暦とも [manakai/data-locale](https://github.com/manakai/data-locale) のデータを元にしています (暦は日本暦日原典由来)。
14
14
 
15
15
  ## 機能
16
16
 
@@ -210,8 +210,8 @@ strftime が拡張されるので、 `config/locale/ja.yml` にそのままフ
210
210
  作成には以下のデータを参照しました。
211
211
 
212
212
  * Wakaba 氏による https://github.com/manakai/data-locale のデータを利用しています
213
- * 旧暦: [suikawiki - 旧暦](http://wiki.suikawiki.org/n/%E6%97%A7%E6%9A%A6#section-%E5%AF%BE%E7%85%A7%E8%A1%A8%E3%81%A8%E5%A4%89%E6%8F%9B%E3%83%84%E3%83%BC%E3%83%AB) にある「日本暦日原典」第4版準拠の先発グレゴリオ暦対照表
214
- * 元号: [Wikipedia - 元号一覧_(日本)](https://ja.wikipedia.org/wiki/%E5%85%83%E5%8F%B7%E4%B8%80%E8%A6%A7_%28%E6%97%A5%E6%9C%AC%29) のユリウス歴とグレゴリオ暦表記の物に基づいています
213
+ * 旧暦: [suikawiki - 旧暦](http://wiki.suikawiki.org/n/%E6%97%A7%E6%9A%A6#section-%E5%AF%BE%E7%85%A7%E8%A1%A8%E3%81%A8%E5%A4%89%E6%8F%9B%E3%83%84%E3%83%BC%E3%83%AB) にある「日本暦日原典」第4版準拠の先発グレゴリオ暦対照表 (kyuureki-map.txt)
214
+ * 元号: 同リポジトリの元号定義データ (era-defs.json)
215
215
 
216
216
  ## ライセンス
217
217
 
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'wareki/calendar_def'
4
+
5
+ module Wareki
6
+ # 旧暦テーブルの参照ロジック。1年分の旧暦情報は整数1個 (40bit) に
7
+ # ビットパックされている。PACKED[西暦年 - YEAR_MIN]:
8
+ # bits 0..21 : その年の最初の月の初日のユリウス通日 (JD)
9
+ # bits 22..34 : 月の大小マスク (bit i = i 番目の月が大の月 = 30日)
10
+ # bit 35 : 閏月を含む13ヶ月の年なら1
11
+ # bits 36..39 : 閏月の月番号 (1..12、閏月がなければ0)
12
+ # 明治5年12月 (テーブル最終月) はグレゴリオ暦切替のため LAST_MONTH_DAYS
13
+ # (= 2) 日で打ち切られており、大小マスクには反映されていない。
14
+ module Calendar
15
+ module_function
16
+
17
+ def covers_year?(year)
18
+ year.between?(YEAR_MIN, YEAR_MAX)
19
+ end
20
+
21
+ def covers_jd?(jd)
22
+ jd.between?(JD_MIN, JD_MAX)
23
+ end
24
+
25
+ # 閏月の月番号。閏月のない年・範囲外の年は nil
26
+ def leap_month(year)
27
+ covers_year?(year) or return nil
28
+ lp = PACKED[year - YEAR_MIN] >> 36
29
+ lp == 0 ? nil : lp
30
+ end
31
+
32
+ # 月番号 (1始まり) を月配列添字 (閏月込み・0始まり) に変換する。
33
+ # year がテーブル範囲内であることは呼び出し側が保証すること。
34
+ def month_index(year, month, is_leap)
35
+ lp = leap_month(year)
36
+ idx = month - 1
37
+ is_leap || (lp && month > lp) and idx += 1
38
+ idx
39
+ end
40
+
41
+ def last_day_of_month(year, month, is_leap)
42
+ covers_year?(year) or return nil
43
+ packed = PACKED[year - YEAR_MIN]
44
+ idx = month_index(year, month, is_leap)
45
+ months = 12 + ((packed >> 35) & 1)
46
+ return LAST_MONTH_DAYS if year == YEAR_MAX && idx == months - 1
47
+
48
+ 29 + ((packed >> (22 + idx)) & 1)
49
+ end
50
+
51
+ def to_jd(year, month, day, is_leap)
52
+ covers_year?(year) or return nil
53
+ packed = PACKED[year - YEAR_MIN]
54
+ idx = month_index(year, month, is_leap)
55
+ jd = packed & 0x3fffff
56
+ i = 0
57
+ while i < idx
58
+ jd += 29 + ((packed >> (22 + i)) & 1)
59
+ i += 1
60
+ end
61
+ jd + day - 1
62
+ end
63
+
64
+ # jd を [西暦年, 月, 日, 閏月フラグ] に変換する。範囲外は nil
65
+ def find_date_ary(jd)
66
+ covers_jd?(jd) or return nil
67
+ i = PACKED.bsearch_index { |packed| (packed & 0x3fffff) > jd }
68
+ if i.nil?
69
+ i = PACKED.size - 1
70
+ else
71
+ i -= 1
72
+ end
73
+ packed = PACKED[i]
74
+ month_start = packed & 0x3fffff
75
+ months = 12 + ((packed >> 35) & 1)
76
+ lp = packed >> 36
77
+ idx = 0
78
+ while idx < months - 1
79
+ next_start = month_start + 29 + ((packed >> (22 + idx)) & 1)
80
+ break if jd < next_start
81
+
82
+ month_start = next_start
83
+ idx += 1
84
+ end
85
+ month = idx + 1
86
+ month -= 1 if lp != 0 && lp < month
87
+ [YEAR_MIN + i, month, jd - month_start + 1, lp != 0 && lp == idx]
88
+ end
89
+ end
90
+ end