zakuro 0.4.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -3
- data/VERSION +1 -0
- data/doc/operation/csv/month.csv +21 -0
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/gengou.rb +82 -0
- data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
- data/lib/zakuro/calculation/base/operated_year.rb +5 -15
- data/lib/zakuro/calculation/base/year.rb +26 -14
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +0 -13
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
- data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/era/version/version.rb +24 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
- data/lib/zakuro/calculation/monthly/month.rb +49 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
- data/lib/zakuro/calculation/range/full_range.rb +68 -107
- data/lib/zakuro/calculation/range/operated_range.rb +13 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
- data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
- data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
- data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
- data/lib/zakuro/calculation/summary/range.rb +120 -0
- data/lib/zakuro/calculation/summary/single.rb +45 -64
- data/lib/zakuro/condition.rb +14 -0
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
- data/lib/zakuro/era/japan/gengou.rb +35 -74
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
- data/lib/zakuro/merchant.rb +50 -3
- data/lib/zakuro/operation/month/parser.rb +1 -1
- data/lib/zakuro/operation/month/type.rb +1 -1
- data/lib/zakuro/operation/month/validator.rb +2 -2
- data/lib/zakuro/operation/yaml/month.yaml +672 -0
- data/lib/zakuro/output/response.rb +5 -5
- data/lib/zakuro/result/result.rb +17 -0
- data/lib/zakuro/tools/typeconv.rb +38 -0
- data/lib/zakuro/tools/typeof.rb +4 -1
- data/lib/zakuro/version/context.rb +24 -3
- data/lib/zakuro/version/daien/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/genka/const/number.rb +43 -0
- data/lib/zakuro/version/genka/const/remainder.rb +33 -0
- data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
- data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
- data/lib/zakuro/version/genka/genka.rb +1 -9
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
- data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
- data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
- data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
- data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
- data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
- data/lib/zakuro/version/kansei/kansei.rb +1 -9
- data/lib/zakuro/version/senmyou/README.md +11 -7
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/lib/zakuro/version/version_class_resolver.rb +4 -0
- data/zakuro.gemspec +1 -3
- metadata +45 -16
- data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
- data/lib/zakuro/era/japan/gengou/type.rb +0 -178
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
- data/lib/zakuro/era/japan/reki.rb +0 -91
- data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
- data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
- data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
- data/lib/zakuro/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3e4e967b105b46ffc94cc792328a5020aa0535f797dbf5bc5bc1a8eb2786cd8
|
4
|
+
data.tar.gz: 71f0fce3e9592469062df9ef667b2e146754c79bde93647a020c942b21cf3fb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4acc827cebcebad50f33b3c255a23b28ebab62b05fc322ec0e304fa7d738df9479f3aded5e776e6d741d31f2c8812a30bde7ee777f3841eb140be3f44479ce8
|
7
|
+
data.tar.gz: c3a8304e0afdd13b2bc31d7107594816d185114bd7b67701bc3d2f1a395cc7dfeb7c19ff653febe57fc654f8f0feaac0857a0fa2ba2db6aba5d48f2ae87231f8
|
data/README.md
CHANGED
@@ -30,7 +30,25 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
開発途中です。
|
32
32
|
|
33
|
-
|
33
|
+
1日検索/期間検索に対応しております。
|
34
|
+
|
35
|
+
下記表で対応済の暦は使用可能です。
|
36
|
+
|
37
|
+
|開始日|暦 |計算方法|対応|
|
38
|
+
|:----|:----|:----|:----|
|
39
|
+
|445/01/24|元嘉暦| |✓|
|
40
|
+
|698/02/16|儀鳳暦|A|✓|
|
41
|
+
| | |B|-|
|
42
|
+
| | |C|-|
|
43
|
+
|764/02/07|大衍暦|A|✓|
|
44
|
+
| | |B|-|
|
45
|
+
| | |C|-|
|
46
|
+
|862/02/03|宣明暦| |✓|
|
47
|
+
|1685/02/04|貞享暦| |-|
|
48
|
+
|1755/02/11|宝暦暦| |-|
|
49
|
+
|1798/02/16|寛政暦| |-|
|
50
|
+
|1844/02/18|天保暦| |-|
|
51
|
+
|1872/12/09|グレゴリオ暦| |-|
|
34
52
|
|
35
53
|
# 使用方法
|
36
54
|
|
@@ -55,6 +73,11 @@ western_date = Date.new(1685, 2, 3)
|
|
55
73
|
merchant.offer(condition: { date: western_date })
|
56
74
|
puts merchant.commit.to_json
|
57
75
|
# => {"data":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"甲子","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"甲子","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"}}}}
|
76
|
+
|
77
|
+
# 期間検索
|
78
|
+
merchant = Zakuro::Merchant.new(condition: { range: {start: Date.new(862, 2, 3), last: Date.new(862, 2, 4)}})
|
79
|
+
puts merchant.commit.to_json
|
80
|
+
{"list":[{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}}}},{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"}}}}]}
|
58
81
|
```
|
59
82
|
|
60
83
|
# 条件
|
@@ -103,6 +126,12 @@ puts merchant.commit.to_json
|
|
103
126
|
| 日付情報 | data | | | Zakuro::Result::Data::SingleDay | - | 運用値(計算値は運用情報内を参照のこと)|
|
104
127
|
| 運用情報 | operation | | | Zakuro::Result::Operation::Bundle | - | - |
|
105
128
|
|
129
|
+
### Zakuro::Result::Range
|
130
|
+
|
131
|
+
| 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
|
132
|
+
|----------|-----------|---|---|---------------------------------------|--------|---------------------------------------|
|
133
|
+
| 日リスト | list | | | Array\<Zakuro::Result::Data::Single\> | - | 範囲内の日付情報すべて |
|
134
|
+
|
106
135
|
### Zakuro::Result::SingleDay
|
107
136
|
|
108
137
|
| 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
|
@@ -160,8 +189,8 @@ puts merchant.commit.to_json
|
|
160
189
|
| 月初日の西暦日 | | western_date | | String | 0937-02-13 | 計算値 |
|
161
190
|
| 原文頁数 | | page | | Integer | 178 | |
|
162
191
|
| 原文注釈番号 | | number | | Integer | 1 | |
|
163
|
-
| 注釈 | | annotations | | Array
|
164
|
-
| 注釈内容 | | | description | String | 計算は51乙卯であるが,
|
192
|
+
| 注釈 | | annotations | | Array\<Zakuro::Result::Operation::MonthAnnotation\> | | |
|
193
|
+
| 注釈内容 | | | description | String | 計算は51乙卯であるが, 日本紀略に甲寅朔とある。<br>正月甲寅朔のユリウス暦日は2月13日となる。(元旦日食 をさけるための変更か) | |
|
165
194
|
| 注釈補記 | | | note | String | - | 原文訂正 |
|
166
195
|
|
167
196
|
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.6.1
|
data/doc/operation/csv/month.csv
CHANGED
@@ -1,4 +1,25 @@
|
|
1
1
|
,ID,関連注釈ID,親注釈ID,頁数,注番,西暦,和暦,内容,補足(zakuro),有効行,分類,月(計),月(実),月大小(計),月大小(実),中気番号(計),中気番号(実),中気(計),中気(実),中気移動先,中気移動元,干支(計),干支(実),西暦(計),西暦(実),干支番(計),干支番(実),日差分(補正なし),日差分,中気(計),中気(実),中気差分
|
2
|
+
,49-1-1,-,-,49,1,553-5-28,欽明天皇 14年 5 大 壬戌 58.5997,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
3
|
+
,54-1-1,-,-,54,1,570-5-21,欽明天皇 31年 閏4 小 甲申 20.0226,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
4
|
+
,56-1-1,-,-,56,1,575-2-26,敏達天皇 4年 2 小 丙戌 22.3271,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
5
|
+
,72-1-1,-,-,72,1,623-2-5,推古天皇 31年 1 大 丁丑 13.9641,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
6
|
+
,72-1-2,-,-,72,1,624-1-26,推古天皇 32年 1 小 壬申 8.3311,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
7
|
+
,74-1-1,-,-,74,1,628-5-9,推古天皇 36年 4 小 丁丑 13.4521,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
8
|
+
,74-2-1,-,-,74,2,628-10-4,推古天皇 36年 9 小 乙巳 41.1051,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
9
|
+
,81-1-1,-,-,81,1,649-5-17,大化 5年 4 小 乙亥 11.4043,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
10
|
+
,81-2-1,-,-,81,2,649-6-15,大化 5年 5 大 甲辰 40.9348,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
11
|
+
,95-1-0,-,95-1-1,95,-,692-11-14,持統 6年 10 小 壬戌 58.8590,-,-,true,-,-,-,大,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
12
|
+
,95-1-1,-,-,95,1,692-12-14,持統 6年 11 大 辛卯 28.3896,計算(元嘉暦による)では28壬辰となるが,書紀は11月辛卯朔,したがってユリウス暦は12月13日。,-,true,-,-,-,小,大,-,-,-,-,-,-,壬辰,辛卯,692-12-14,692-12-13,28,27,-1,-1,-,-,-
|
13
|
+
,96-1-0,-,96-1-1,96,-,696-11-30,持統 10年 11 大 己亥 35.3893,-,-,true,-,-,-,小,大,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
14
|
+
,96-1-1,-,-,96,1,696-12-29,持統 10年 12 小 己巳 4.9189,元嘉暦では4戊辰となるが,書紀は12月己巳朔,したがってユリウス暦は12月30日。,-,true,-,-,-,大,小,-,-,-,-,-,-,戊辰,己巳,696-12-29,696-12-30,4,5,1,1,-,-,-
|
15
|
+
,97-1-0,-,97-1-1,97,-,697-3-28,文武 1年 3 小 丁酉 33.5106,-,-,true,-,-,-,大,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
16
|
+
,97-1-1,97-0-1,-,97,1,697-4-27,文武 1年 4 大 丙寅 3.0412,元嘉暦では3丁卯となるが,書紀は4月丙寅朔,したがって4月朔のユリウス暦は4月26日。,-,true,-,-,-,小,大,-,-,-,-,-,-,丁卯,丙寅,697-4-27,697-4-26,3,2,-1,-1,-,-,-
|
17
|
+
,97-2-0,-,97-2-1,97,-,697-7-24,文武 1年 7 小 乙未 31.6330,-,-,true,-,-,-,大,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
18
|
+
,97-2-1,97-0-1,-,97,2,697-8-23,文武 1年 8 大 甲子 1.1636,元嘉暦では1乙丑,書紀も乙丑朔とあるが,ここは続日本紀にしたがって甲子とする。したがってユリウス暦は8月22日。,-,true,-,-,-,小,大,-,-,-,-,-,-,乙丑,甲子,697-8-23,697-8-22,1,0,-1,-1,-,-,-
|
19
|
+
,97-3-1,97-0-1,-,97,3,698-1-17,文武 1年 閏12 小 癸巳 28.8165,元嘉暦では28壬辰であるが,続日本紀に閏12月癸巳朔とある。したがってユリウス暦は1月18日となる。,-,true,-,12,閏12,大,小,-,-,-,-,-,-,壬辰,癸巳,698-1-17,698-1-18,28,29,1,1,-,-,-
|
20
|
+
,97-4-1,97-0-1,-,97,4,697-11-19,文武 1年 11 大 癸巳 29.7553,元嘉暦では閏10月と推算されるが,続日本紀により閏12月。,-,true,-,閏10,11,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
21
|
+
,97-4-2,97-0-1,97-4-1,97,4,697-12-19,文武 1年 12 大 癸亥 59.2859,-,-,true,-,11,12,小,大,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
22
|
+
,97-0-1,-,-,97,-,-,-,註. 1)〜4)は、儀鳳暦によればすべて合うものである。(儀鳳暦による計算値は本文529頁参照),-,false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
2
23
|
,98-1-1,-,-,98,1,698-10-10,文武 2年 9 大 戊午 54-325,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
3
24
|
,100-1-1,-,-,100,1,704-5-9,慶雲 1年 4 小 丙辰 52-3,-,改変なし(内容転記せず),false,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
4
25
|
,102-1-a,-,102-1-1,102,-,711-9-17,和銅 4年 8 大 癸卯 39-756,-,-,true,次月大小,-,-,小,大,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
|
Binary file
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../era/western/calendar'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Base
|
11
|
+
#
|
12
|
+
# Gengou 元号
|
13
|
+
#
|
14
|
+
class Gengou
|
15
|
+
# @return [Western::Calendar] 開始日
|
16
|
+
attr_reader :start_date
|
17
|
+
# @return [Western::Calendar] 終了日
|
18
|
+
attr_reader :last_date
|
19
|
+
# @return [Array<LinearGengou>] 1行目元号
|
20
|
+
attr_reader :first_line
|
21
|
+
# @return [Array<LinearGengou>] 2行目元号
|
22
|
+
attr_reader :second_line
|
23
|
+
|
24
|
+
#
|
25
|
+
# 初期化
|
26
|
+
#
|
27
|
+
# @param [Western::Calendar] start_date 開始日
|
28
|
+
# @param [Western::Calendar] last_date 終了日
|
29
|
+
# @param [Array<LinearGengou>] first_line 1行目元号
|
30
|
+
# @param [Array<LinearGengou>] second_line 2行目元号
|
31
|
+
#
|
32
|
+
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
33
|
+
first_line: [], second_line: [])
|
34
|
+
@start_date = start_date
|
35
|
+
@last_date = last_date
|
36
|
+
@first_line = first_line
|
37
|
+
@second_line = second_line
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# 1行目元号を取得する
|
42
|
+
#
|
43
|
+
# @param [Western::Calendar] date 西暦日
|
44
|
+
#
|
45
|
+
# @return [LinearGengou] 1行目元号
|
46
|
+
#
|
47
|
+
def match_first_line(date: Western::Calendar)
|
48
|
+
@first_line.each do |line|
|
49
|
+
return line.clone if line.include?(date: date)
|
50
|
+
end
|
51
|
+
|
52
|
+
LinearGengou.new
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# 2行目元号を取得する
|
57
|
+
#
|
58
|
+
# @param [Western::Calendar] date 西暦日
|
59
|
+
#
|
60
|
+
# @return [LinearGengou] 2行目元号
|
61
|
+
#
|
62
|
+
def match_second_line(date: Western::Calendar)
|
63
|
+
@second_line.each do |line|
|
64
|
+
return line.clone if line.include?(date: date)
|
65
|
+
end
|
66
|
+
|
67
|
+
LinearGengou.new
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# 不正か
|
72
|
+
#
|
73
|
+
# @return [True] 不正
|
74
|
+
# @return [False] 不正なし
|
75
|
+
#
|
76
|
+
def invalid?
|
77
|
+
@first_line.size.zero? && @second_line.size.zero?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../era/western/calendar'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Base
|
11
|
+
#
|
12
|
+
# LinearGengou 直列元号
|
13
|
+
#
|
14
|
+
class LinearGengou
|
15
|
+
INVALID_YEAR = -1
|
16
|
+
|
17
|
+
# @return [Western::Calendar] 開始日
|
18
|
+
attr_reader :start_date
|
19
|
+
# @return [Western::Calendar] 終了日
|
20
|
+
attr_reader :last_date
|
21
|
+
# @return [String] 元号名
|
22
|
+
attr_reader :name
|
23
|
+
# @return [Integer] 年
|
24
|
+
attr_reader :year
|
25
|
+
|
26
|
+
#
|
27
|
+
# 初期化
|
28
|
+
#
|
29
|
+
# @param [Western::Calendar] start_date 開始日
|
30
|
+
# @param [Western::Calendar] last_date 終了日
|
31
|
+
# @param [String] name 元号名
|
32
|
+
# @param [Integer] 元号年
|
33
|
+
#
|
34
|
+
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
35
|
+
name: '', year: INVALID_YEAR)
|
36
|
+
@start_date = start_date
|
37
|
+
@last_date = last_date
|
38
|
+
@name = name
|
39
|
+
@year = year
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 不正か
|
44
|
+
#
|
45
|
+
# @return [True] 不正
|
46
|
+
# @return [False] 不正なし
|
47
|
+
#
|
48
|
+
def invalid?
|
49
|
+
@name == '' || @year == INVALID_YEAR
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# 範囲内か
|
54
|
+
#
|
55
|
+
# @param [Western::Calendar] date 西暦日
|
56
|
+
#
|
57
|
+
# @return [True] 範囲内
|
58
|
+
# @return [False] 範囲外
|
59
|
+
#
|
60
|
+
def include?(date: Western::Calendar.new)
|
61
|
+
return false if invalid?
|
62
|
+
|
63
|
+
return false if @start_date.invalid?
|
64
|
+
|
65
|
+
return false if @last_date.invalid?
|
66
|
+
|
67
|
+
return false if date < @start_date
|
68
|
+
|
69
|
+
return false if date > @last_date
|
70
|
+
|
71
|
+
true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative './year'
|
4
|
-
|
4
|
+
|
5
|
+
require_relative '../../version/context'
|
5
6
|
|
6
7
|
# :nodoc:
|
7
8
|
module Zakuro
|
@@ -16,23 +17,12 @@ module Zakuro
|
|
16
17
|
#
|
17
18
|
# 初期化
|
18
19
|
#
|
19
|
-
# @param [
|
20
|
+
# @param [Context] context 暦コンテキスト
|
20
21
|
# @param [Array<OperatedMonth>] months 年内の全ての月
|
21
22
|
# @param [Integer] total_days 年の日数
|
22
|
-
# @param [Western::Calendar] new_year_date 元旦
|
23
23
|
#
|
24
|
-
def initialize(
|
25
|
-
|
26
|
-
super(multi_gengou: multi_gengou, new_year_date: new_year_date,
|
27
|
-
months: months, total_days: total_days)
|
28
|
-
end
|
29
|
-
|
30
|
-
def commit
|
31
|
-
super
|
32
|
-
|
33
|
-
return if months.empty?
|
34
|
-
|
35
|
-
@new_year_date = months[0].first_day.western_date
|
24
|
+
def initialize(context: Context.new, months: [], total_days: 0)
|
25
|
+
super(context: context, months: months, total_days: total_days)
|
36
26
|
end
|
37
27
|
|
38
28
|
#
|
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
require_relative '../cycle/zodiac'
|
4
4
|
|
5
|
+
require_relative '../../era/western/calendar'
|
6
|
+
|
7
|
+
require_relative '../../version/context'
|
8
|
+
|
5
9
|
# :nodoc:
|
6
10
|
module Zakuro
|
7
11
|
# :nodoc:
|
@@ -12,28 +16,23 @@ module Zakuro
|
|
12
16
|
# Year 年
|
13
17
|
#
|
14
18
|
class Year
|
15
|
-
# @return [
|
16
|
-
attr_reader :
|
19
|
+
# @return [Context] 暦コンテキスト
|
20
|
+
attr_reader :context
|
17
21
|
# @return [Array<Month>] 年内の全ての月
|
18
22
|
attr_reader :months
|
19
23
|
# @return [Integer] 年の日数
|
20
24
|
attr_reader :total_days
|
21
|
-
# @return [Western::Calendar] 元旦
|
22
|
-
attr_reader :new_year_date
|
23
25
|
|
24
26
|
#
|
25
27
|
# 初期化
|
26
28
|
#
|
27
|
-
# @param [
|
29
|
+
# @param [Context] context 暦コンテキスト
|
28
30
|
# @param [Array<Month>] months 年内の全ての月
|
29
31
|
# @param [Integer] total_days 年の日数
|
30
|
-
# @param [Western::Calendar] new_year_date 元旦
|
31
32
|
#
|
32
|
-
def initialize(
|
33
|
-
|
34
|
-
@multi_gengou = multi_gengou
|
33
|
+
def initialize(context: Context.new, months: [], total_days: 0)
|
34
|
+
@context = context
|
35
35
|
@months = months
|
36
|
-
@new_year_date = new_year_date
|
37
36
|
@total_days = total_days
|
38
37
|
end
|
39
38
|
|
@@ -58,21 +57,34 @@ module Zakuro
|
|
58
57
|
# @return [MultiGengou] 自身
|
59
58
|
#
|
60
59
|
def next_year
|
61
|
-
@multi_gengou.next_year
|
62
|
-
|
63
|
-
@new_year_date += @total_days
|
64
60
|
@total_days = 0
|
65
61
|
|
66
62
|
self
|
67
63
|
end
|
68
64
|
|
65
|
+
#
|
66
|
+
# 年初を取得する
|
67
|
+
#
|
68
|
+
# @return [Western::Calendar] 年初
|
69
|
+
#
|
70
|
+
def new_year_date
|
71
|
+
return Western::Calendar.new unless months
|
72
|
+
|
73
|
+
return Western::Calendar.new if months.size.zero?
|
74
|
+
|
75
|
+
@months[0].western_date
|
76
|
+
end
|
77
|
+
|
69
78
|
#
|
70
79
|
# 十干十二支を取得する
|
71
80
|
#
|
72
81
|
# @return [String] 十干十二支
|
73
82
|
#
|
74
83
|
def zodiac_name
|
75
|
-
|
84
|
+
date = new_year_date
|
85
|
+
return '' if date.invalid?
|
86
|
+
|
87
|
+
Cycle::Zodiac.year_name(western_year: date.year)
|
76
88
|
end
|
77
89
|
|
78
90
|
#
|
@@ -376,19 +376,6 @@ module Zakuro
|
|
376
376
|
"大余(日): #{@day}, 小余(分): #{@minute}, 小余(秒): #{@second}"
|
377
377
|
end
|
378
378
|
|
379
|
-
#
|
380
|
-
# 特定の文字フォーマットにして出力する
|
381
|
-
#
|
382
|
-
# @param [String] form フォーマット(大余、小余、秒それぞれを%dで指定する)
|
383
|
-
#
|
384
|
-
# @return [String] フォーマットした結果
|
385
|
-
#
|
386
|
-
def format(form: '%d-%d')
|
387
|
-
return '' if invalid?
|
388
|
-
|
389
|
-
super(form, @day, @minute, @second)
|
390
|
-
end
|
391
|
-
|
392
379
|
#
|
393
380
|
# 繰り上げる
|
394
381
|
#
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/japan/gengou/resource'
|
4
|
+
require_relative '../../../../era/japan/calendar'
|
5
|
+
require_relative '../../../../era/western/calendar'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
#
|
14
|
+
# Connector 元号接続器
|
15
|
+
#
|
16
|
+
# 現在は"明徳"のみを解決している
|
17
|
+
# 元中1年4月28日 元中9年閏10月4日 明徳5年7月4日
|
18
|
+
# 1384-05-18 1392-11-18 1394-8-1
|
19
|
+
# [1] |-------------元中---------------|---------明徳------------|
|
20
|
+
# [2] |---------明徳--------|
|
21
|
+
# 明徳1年3月26日
|
22
|
+
# 1390-04-12
|
23
|
+
#
|
24
|
+
# * 明徳は2行目元号から始まる
|
25
|
+
# * 1392-11-19より1行目元号に移行する
|
26
|
+
# * 移行のタイミングで元号年を引き継げるようにする
|
27
|
+
#
|
28
|
+
class Connector
|
29
|
+
# @return [Array<Counter>] 未解決元号
|
30
|
+
attr_reader :unsolved_list
|
31
|
+
|
32
|
+
#
|
33
|
+
# 初期化
|
34
|
+
#
|
35
|
+
def initialize
|
36
|
+
@unsolved_list = []
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# 元号を更新する
|
41
|
+
#
|
42
|
+
# @param [Array<Array<Counter>>] lines 全行元号
|
43
|
+
#
|
44
|
+
def update(lines: [])
|
45
|
+
lines.each do |line|
|
46
|
+
line.each_with_index do |gengou, index|
|
47
|
+
next unless gengou.changed?
|
48
|
+
|
49
|
+
line[index] = replace(gengou: gengou)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# 元号を年を更新した元号に入れ替える
|
56
|
+
#
|
57
|
+
# @param [Counter] gengou 元号
|
58
|
+
#
|
59
|
+
# @return [Counter] 元号/更新済元号
|
60
|
+
#
|
61
|
+
def replace(gengou:)
|
62
|
+
matched_index = -1
|
63
|
+
@unsolved_list.each_with_index do |unsolved, index|
|
64
|
+
next unless unsolved.name == gengou.name
|
65
|
+
|
66
|
+
matched_index = index
|
67
|
+
break
|
68
|
+
end
|
69
|
+
|
70
|
+
if matched_index == -1
|
71
|
+
@unsolved_list.push(gengou)
|
72
|
+
return gengou
|
73
|
+
end
|
74
|
+
|
75
|
+
matched = @unsolved_list[matched_index]
|
76
|
+
|
77
|
+
result = recreate(gengou: gengou, unsolved: matched)
|
78
|
+
|
79
|
+
@unsolved_list[matched_index] = result
|
80
|
+
|
81
|
+
# 分離した元号の末尾まで到達した
|
82
|
+
@unsolved_list.delete_at(matched_index) unless result.change_last_date?
|
83
|
+
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# 年を更新した元号を生成する
|
89
|
+
#
|
90
|
+
# @param [Counter] gengou 元号
|
91
|
+
# @param [Counter] unsolved 未解決元号
|
92
|
+
#
|
93
|
+
# @return [Counter] 更新済元号
|
94
|
+
#
|
95
|
+
def recreate(gengou:, unsolved:)
|
96
|
+
japan_year = gengou.japan_year
|
97
|
+
japan_year = unsolved.japan_year if unsolved.japan_year > gengou.japan_year
|
98
|
+
|
99
|
+
Counter.new(
|
100
|
+
gengou: gengou.gengou, start_date: gengou.start_date,
|
101
|
+
last_date: gengou.last_date, japan_year: japan_year
|
102
|
+
)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|