zakuro 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -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/gengou/internal/counter.rb +129 -0
- data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
- data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
- data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
- data/lib/zakuro/calculation/gengou/scroll.rb +262 -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 +65 -103
- data/lib/zakuro/calculation/range/operated_range.rb +13 -8
- 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/single_day.rb +13 -35
- data/lib/zakuro/calculation/summary/single.rb +5 -2
- data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/version/version.rb +24 -0
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
- data/lib/zakuro/era/japan/gengou/type.rb +148 -41
- data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
- data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou.rb +5 -5
- 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 +12 -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 +1 -1
- data/lib/zakuro/output/response.rb +5 -5
- 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/daien.rb +1 -26
- data/lib/zakuro/version/genka/genka.rb +1 -26
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- 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/senmyou.rb +1 -30
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/zakuro.gemspec +1 -3
- metadata +25 -17
- 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/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
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../base/gengou'
|
3
4
|
require_relative './first_day'
|
4
5
|
require_relative './month_label'
|
5
6
|
|
@@ -21,6 +22,8 @@ module Zakuro
|
|
21
22
|
attr_reader :first_day
|
22
23
|
# @return [Array<SolarTerm>] 二十四節気
|
23
24
|
attr_reader :solar_terms
|
25
|
+
# @return [Base::Gengou] 元号
|
26
|
+
attr_reader :gengou
|
24
27
|
|
25
28
|
#
|
26
29
|
# 初期化
|
@@ -29,13 +32,25 @@ module Zakuro
|
|
29
32
|
# @param [MonthLabel] month_label 月表示名
|
30
33
|
# @param [FirstDay] first_day 月初日(朔日)
|
31
34
|
# @param [Array<SolarTerm>] solar_terms 二十四節気
|
35
|
+
# @param [Base::Gengou] gengou 元号
|
32
36
|
#
|
33
|
-
def initialize(context
|
34
|
-
solar_terms: [])
|
37
|
+
def initialize(context: Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
|
38
|
+
solar_terms: [], gengou: Base::Gengou.new)
|
35
39
|
@context = context
|
36
40
|
@month_label = month_label
|
37
41
|
@first_day = first_day
|
38
42
|
@solar_terms = solar_terms
|
43
|
+
@gengou = gengou
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# 不正か
|
48
|
+
#
|
49
|
+
# @return [True] 不正
|
50
|
+
# @return [False] 不正なし
|
51
|
+
#
|
52
|
+
def invalid?
|
53
|
+
@context.invalid?
|
39
54
|
end
|
40
55
|
|
41
56
|
#
|
@@ -181,6 +196,38 @@ module Zakuro
|
|
181
196
|
def same?(other:)
|
182
197
|
number == other.number && leaped? == other.leaped?
|
183
198
|
end
|
199
|
+
|
200
|
+
#
|
201
|
+
# 月の終了日を返す
|
202
|
+
#
|
203
|
+
# @return [Western::Calendar] 月の終了日
|
204
|
+
#
|
205
|
+
def end_date
|
206
|
+
return Western::Calendar.new if western_date.invalid?
|
207
|
+
|
208
|
+
western_date.clone + days - 1
|
209
|
+
end
|
210
|
+
|
211
|
+
#
|
212
|
+
# 範囲内か
|
213
|
+
#
|
214
|
+
# @param [Western::Calendar] date 日付
|
215
|
+
#
|
216
|
+
# @return [True] 範囲内
|
217
|
+
# @return [False] 範囲外
|
218
|
+
#
|
219
|
+
def include?(date:)
|
220
|
+
return false if invalid?
|
221
|
+
|
222
|
+
start_date = western_date
|
223
|
+
return false if start_date.invalid?
|
224
|
+
|
225
|
+
return false if date < start_date
|
226
|
+
|
227
|
+
return false if date > end_date
|
228
|
+
|
229
|
+
true
|
230
|
+
end
|
184
231
|
end
|
185
232
|
end
|
186
233
|
end
|
@@ -34,10 +34,10 @@ module Zakuro
|
|
34
34
|
# @param [Operation::MonthHistory] history 変更履歴(月)
|
35
35
|
#
|
36
36
|
def initialize(context:, operated_solar_terms:, month_label: MonthLabel.new,
|
37
|
-
first_day: FirstDay.new, solar_terms: [],
|
37
|
+
first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
|
38
38
|
history: Operation::MonthHistory.new)
|
39
39
|
super(context: context, month_label: month_label, first_day: first_day,
|
40
|
-
solar_terms: solar_terms)
|
40
|
+
solar_terms: solar_terms, gengou: gengou)
|
41
41
|
@history = history
|
42
42
|
@operated_solar_terms = operated_solar_terms
|
43
43
|
@moved = false
|
@@ -1,13 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../../
|
3
|
+
require_relative '../../version/context'
|
4
|
+
|
5
|
+
require_relative '../../era/western/calendar'
|
4
6
|
require_relative '../../output/logger'
|
5
7
|
|
6
|
-
require_relative '../
|
8
|
+
require_relative '../gengou/scroll'
|
9
|
+
|
10
|
+
require_relative '../base/gengou'
|
7
11
|
require_relative '../base/year'
|
8
12
|
|
13
|
+
require_relative '../version/version'
|
14
|
+
|
9
15
|
require_relative './transfer/year_boundary'
|
10
|
-
|
16
|
+
|
17
|
+
require_relative './transfer/gengou_scroller'
|
11
18
|
|
12
19
|
# :nodoc:
|
13
20
|
module Zakuro
|
@@ -37,11 +44,7 @@ module Zakuro
|
|
37
44
|
# @return [Western::Calendar] 終了日
|
38
45
|
attr_reader :end_date
|
39
46
|
# @return [MultiGengouRoller] 改元処理
|
40
|
-
attr_reader :
|
41
|
-
# @return [Western::Calendar] 最過去の元旦
|
42
|
-
attr_reader :new_year_date
|
43
|
-
# @return [Integer] 西暦年
|
44
|
-
attr_reader :western_year
|
47
|
+
attr_reader :scroll
|
45
48
|
|
46
49
|
# @return [Output::Logger] ロガー
|
47
50
|
LOGGER = Output::Logger.new(location: 'full_range')
|
@@ -58,12 +61,9 @@ module Zakuro
|
|
58
61
|
@end_date = end_date
|
59
62
|
return if invalid?
|
60
63
|
|
64
|
+
# TODO: 現時点では使用していない。特定の暦を指定できるようになった状態で使用する
|
61
65
|
@context = context
|
62
|
-
@
|
63
|
-
start_date: start_date, end_date: end_date
|
64
|
-
)
|
65
|
-
@new_year_date = @multi_gengou_roller.oldest_date.clone
|
66
|
-
@western_year = @new_year_date.year
|
66
|
+
@scroll = Gengou::Scroll.new(start_date: start_date, end_date: end_date)
|
67
67
|
end
|
68
68
|
|
69
69
|
#
|
@@ -79,130 +79,92 @@ module Zakuro
|
|
79
79
|
#
|
80
80
|
# 完全範囲を取得する
|
81
81
|
#
|
82
|
-
# @return [Array<Year>] 完全範囲
|
82
|
+
# @return [Array<Base::Year>] 完全範囲
|
83
83
|
#
|
84
84
|
def get
|
85
85
|
return [] if invalid?
|
86
86
|
|
87
|
-
years =
|
88
|
-
context: @context, annual_ranges: annual_ranges
|
89
|
-
)
|
90
|
-
years = update_gengou(years: years)
|
91
|
-
|
92
|
-
Transfer::WesternDateAllocation.update_first_day(
|
93
|
-
context: @context, years: years
|
94
|
-
)
|
95
|
-
|
96
|
-
years
|
97
|
-
end
|
87
|
+
years = version_ranges
|
98
88
|
|
99
|
-
|
100
|
-
|
101
|
-
#
|
102
|
-
# 完全範囲内の年データを取得する
|
103
|
-
#
|
104
|
-
# @return [Array<Year>] 年データ(冬至基準)
|
105
|
-
#
|
106
|
-
def annual_ranges
|
107
|
-
oldest_date = @new_year_date
|
108
|
-
newest_date = @multi_gengou_roller.newest_date
|
109
|
-
annual_range = context.resolver.annual_range
|
89
|
+
years.each(&:commit)
|
110
90
|
|
111
|
-
years
|
112
|
-
((oldest_date.year)..(newest_date.year + 2)).each do |year|
|
113
|
-
years.push(
|
114
|
-
annual_range.get(
|
115
|
-
context: @context, western_year: year
|
116
|
-
)
|
117
|
-
)
|
118
|
-
end
|
91
|
+
Transfer::GengouScroller.set(scroll: scroll, years: years)
|
119
92
|
|
120
93
|
years
|
121
94
|
end
|
122
95
|
|
123
|
-
|
96
|
+
private
|
124
97
|
|
125
98
|
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
# @param [Array<Year>] years 年データ(元旦基準)
|
99
|
+
# 暦別範囲
|
129
100
|
#
|
130
|
-
# @return [Array<Year>]
|
101
|
+
# @return [Array<Base::Year>] 完全範囲
|
131
102
|
#
|
132
|
-
def
|
133
|
-
|
103
|
+
def version_ranges
|
104
|
+
result = []
|
134
105
|
|
135
|
-
|
106
|
+
start_year = @scroll.western_start_year
|
107
|
+
end_year = @scroll.western_end_year
|
136
108
|
|
137
|
-
|
138
|
-
next_year(years: updated_years, year: year)
|
109
|
+
versions = Version.get(start_year: start_year, end_year: end_year)
|
139
110
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
updated_years
|
148
|
-
end
|
111
|
+
versions.each_with_index do |version, index|
|
112
|
+
context = Context.new(version_name: version.name)
|
113
|
+
start_year = version.start_year
|
114
|
+
end_year = version.end_year
|
115
|
+
# 最後の暦だけ1年足す(次の元号の開始年まで計算するケースあり)
|
116
|
+
end_year += 1 if (index + 1) == versions.size
|
149
117
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
# @param [Array<Year>] years 元号処理済み年データ(元旦基準)
|
156
|
-
# @param [Year] year 元号処理前の年(元旦基準)
|
157
|
-
#
|
158
|
-
def next_year(years:, year:)
|
159
|
-
updated_year = update_year(year: year)
|
160
|
-
|
161
|
-
years.push(updated_year)
|
162
|
-
|
163
|
-
next_new_year_date(total_days: updated_year.total_days)
|
118
|
+
years = boundary_resolved_ranges(
|
119
|
+
context: context, start_year: start_year, end_year: end_year
|
120
|
+
)
|
121
|
+
result.concat(years)
|
122
|
+
end
|
164
123
|
|
165
|
-
|
124
|
+
result
|
166
125
|
end
|
167
126
|
|
168
127
|
#
|
169
|
-
#
|
128
|
+
# 年境界解決済みの範囲
|
170
129
|
#
|
171
|
-
# @param [
|
130
|
+
# @param [Context] context 暦コンテキスト
|
131
|
+
# @param [Integer] start_year 開始西暦年
|
132
|
+
# @param [Integer] end_year 終了西暦年
|
172
133
|
#
|
173
|
-
# @return [Year]
|
134
|
+
# @return [Array<Base::Year>] 年境界解決済みの範囲
|
174
135
|
#
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
updated_year = Base::Year.new(
|
179
|
-
multi_gengou: multi_gengou, new_year_date: @new_year_date.clone,
|
180
|
-
months: year.months
|
136
|
+
def boundary_resolved_ranges(context:, start_year:, end_year:)
|
137
|
+
ranges = annual_ranges(
|
138
|
+
context: context, start_year: start_year, end_year: end_year
|
181
139
|
)
|
182
|
-
updated_year.commit
|
183
140
|
|
184
|
-
|
141
|
+
Transfer::YearBoundary.get(
|
142
|
+
context: context, annual_ranges: ranges
|
143
|
+
)
|
185
144
|
end
|
186
145
|
|
187
146
|
#
|
188
|
-
#
|
147
|
+
# 完全範囲内の年データを取得する
|
189
148
|
#
|
190
|
-
# @param [
|
149
|
+
# @param [Context] context 暦コンテキスト
|
150
|
+
# @param [Integer] start_year 開始西暦年
|
151
|
+
# @param [Integer] end_year 終了西暦年
|
191
152
|
#
|
192
|
-
|
193
|
-
|
194
|
-
|
153
|
+
# @return [Array<Base::Year>] 年データ(冬至基準)
|
154
|
+
#
|
155
|
+
def annual_ranges(context:, start_year:, end_year:)
|
156
|
+
annual_range = context.resolver.annual_range
|
195
157
|
|
196
|
-
|
197
|
-
|
158
|
+
years = []
|
159
|
+
(start_year..(end_year + 1)).each do |year|
|
160
|
+
years.push(
|
161
|
+
annual_range.get(
|
162
|
+
context: context, western_year: year
|
163
|
+
)
|
164
|
+
)
|
165
|
+
end
|
198
166
|
|
199
|
-
|
200
|
-
# 現在日からみて直近の未来に対する元号の切替前日を求める
|
201
|
-
#
|
202
|
-
# @return [Western::Calendar] 元号の切替前日
|
203
|
-
#
|
204
|
-
def choise_nearest_end_date
|
205
|
-
@multi_gengou_roller.choise_nearest_end_date
|
167
|
+
years
|
206
168
|
end
|
207
169
|
end
|
208
170
|
end
|
@@ -4,6 +4,7 @@ require_relative './operated_solar_terms'
|
|
4
4
|
require_relative '../../operation/operation'
|
5
5
|
require_relative '../base/operated_year'
|
6
6
|
require_relative '../../calculation/monthly/operated_month'
|
7
|
+
require_relative './transfer/gengou_scroller'
|
7
8
|
|
8
9
|
# :nodoc:
|
9
10
|
module Zakuro
|
@@ -27,11 +28,15 @@ module Zakuro
|
|
27
28
|
# 初期化
|
28
29
|
#
|
29
30
|
# @param [Context] context 暦コンテキスト
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] end_date 終了日
|
30
33
|
# @param [Array<Year>] years 年データ(完全範囲)
|
31
34
|
#
|
32
|
-
def initialize(context:,
|
35
|
+
def initialize(context:, start_date: Western::Calendar.new, end_date: Western::Calendar.new,
|
36
|
+
years: [])
|
33
37
|
@context = context
|
34
38
|
@years = years
|
39
|
+
@scroll = Gengou::Scroll.new(start_date: start_date, end_date: end_date)
|
35
40
|
@operated_solar_terms = OperatedSolarTerms.new(context: context, years: @years)
|
36
41
|
@operated_solar_terms.create
|
37
42
|
end
|
@@ -48,6 +53,8 @@ module Zakuro
|
|
48
53
|
|
49
54
|
OperatedRange.commit(operated_years: operated_years)
|
50
55
|
|
56
|
+
Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
|
57
|
+
|
51
58
|
operated_years
|
52
59
|
end
|
53
60
|
|
@@ -61,7 +68,7 @@ module Zakuro
|
|
61
68
|
|
62
69
|
years.each do |year|
|
63
70
|
operated_year = OperatedRange.rewrite_year(
|
64
|
-
|
71
|
+
year: year,
|
65
72
|
operated_solar_terms: @operated_solar_terms
|
66
73
|
)
|
67
74
|
operated_years.push(operated_year)
|
@@ -121,16 +128,14 @@ module Zakuro
|
|
121
128
|
#
|
122
129
|
# 年を書き換える
|
123
130
|
#
|
124
|
-
# @param [Context] context 暦コンテキスト
|
125
131
|
# @param [Year] year 年
|
126
132
|
# @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
|
127
133
|
#
|
128
134
|
# @return [OperatedYear] 年
|
129
135
|
#
|
130
|
-
def self.rewrite_year(
|
131
|
-
|
132
|
-
|
133
|
-
)
|
136
|
+
def self.rewrite_year(year:, operated_solar_terms:)
|
137
|
+
context = year.context
|
138
|
+
result = Base::OperatedYear.new(context: context)
|
134
139
|
year.months.each do |month|
|
135
140
|
result.push(month: resolve_month(
|
136
141
|
context: context, month: month,
|
@@ -175,7 +180,7 @@ module Zakuro
|
|
175
180
|
operated_month = Monthly::OperatedMonth.new(
|
176
181
|
context: context,
|
177
182
|
month_label: month.month_label, first_day: month.first_day,
|
178
|
-
solar_terms: month.solar_terms, history: history,
|
183
|
+
solar_terms: month.solar_terms, history: history, gengou: month.gengou,
|
179
184
|
operated_solar_terms: operated_solar_terms
|
180
185
|
)
|
181
186
|
|
@@ -57,6 +57,8 @@ module Zakuro
|
|
57
57
|
# @return [SolarTerm] 二十四節気
|
58
58
|
#
|
59
59
|
def get(western_date: Western::Calendar.new)
|
60
|
+
context = current_context(western_date: western_date)
|
61
|
+
|
60
62
|
solar_term_class = context.resolver.solar_term
|
61
63
|
solar_term = @directions.fetch(western_date.format, solar_term_class.new)
|
62
64
|
|
@@ -68,23 +70,6 @@ module Zakuro
|
|
68
70
|
[true, solar_term]
|
69
71
|
end
|
70
72
|
|
71
|
-
#
|
72
|
-
# 二十四節気の移動元/移動先を生成する
|
73
|
-
#
|
74
|
-
# @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
75
|
-
#
|
76
|
-
def create_directions
|
77
|
-
directions = {}
|
78
|
-
|
79
|
-
years.each do |year|
|
80
|
-
OperatedSolarTerms.create_directions_with_months(
|
81
|
-
context: context, directions: directions, months: year.months
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
directions
|
86
|
-
end
|
87
|
-
|
88
73
|
# :reek:TooManyStatements { max_statements: 6 }
|
89
74
|
|
90
75
|
#
|
@@ -195,6 +180,40 @@ module Zakuro
|
|
195
180
|
index: destination.index
|
196
181
|
)
|
197
182
|
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
#
|
187
|
+
# 日付に対応する暦コンテキストを取得する
|
188
|
+
#
|
189
|
+
# @param [Western::Calendar] western_date 西暦日
|
190
|
+
#
|
191
|
+
# @return [Context] 暦コンテキスト
|
192
|
+
#
|
193
|
+
def current_context(western_date: Western::Calendar.new)
|
194
|
+
@years.each do |year|
|
195
|
+
return year.context if western_date >= year.new_year_date
|
196
|
+
end
|
197
|
+
|
198
|
+
Context.new
|
199
|
+
end
|
200
|
+
|
201
|
+
#
|
202
|
+
# 二十四節気の移動元/移動先を生成する
|
203
|
+
#
|
204
|
+
# @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
|
205
|
+
#
|
206
|
+
def create_directions
|
207
|
+
directions = {}
|
208
|
+
|
209
|
+
years.each do |year|
|
210
|
+
OperatedSolarTerms.create_directions_with_months(
|
211
|
+
context: year.context, directions: directions, months: year.months
|
212
|
+
)
|
213
|
+
end
|
214
|
+
|
215
|
+
directions
|
216
|
+
end
|
198
217
|
end
|
199
218
|
end
|
200
219
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../monthly/month'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Range
|
11
|
+
# :nodoc:
|
12
|
+
module Transfer
|
13
|
+
#
|
14
|
+
# GengouScroller 元号スクロール
|
15
|
+
#
|
16
|
+
module GengouScroller
|
17
|
+
#
|
18
|
+
# 元号を年に設定する
|
19
|
+
#
|
20
|
+
# @param [Gengou::Scroll] scroll 元号スクロール
|
21
|
+
# @param [Array<Base::Year>] years 年
|
22
|
+
#
|
23
|
+
def self.set(scroll:, years: [])
|
24
|
+
years.each do |year|
|
25
|
+
update_gengou_year(scroll: scroll, year: year)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# 年の元号を更新する
|
31
|
+
#
|
32
|
+
# @param [Base::Year] year 年
|
33
|
+
#
|
34
|
+
def self.update_gengou_year(scroll:, year:)
|
35
|
+
year.months.each_with_index do |month, index|
|
36
|
+
scroll.run(month: month)
|
37
|
+
gengou = scroll.to_gengou
|
38
|
+
year.months[index] = Monthly::Month.new(
|
39
|
+
context: month.context,
|
40
|
+
month_label: month.month_label,
|
41
|
+
first_day: Monthly::FirstDay.new(
|
42
|
+
remainder: month.first_day.remainder,
|
43
|
+
western_date: gengou.start_date.clone
|
44
|
+
),
|
45
|
+
solar_terms: month.solar_terms, gengou: gengou
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
private_class_method :update_gengou_year
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../../../calculation/base/multi_gengou_roller'
|
4
3
|
require_relative '../../../calculation/base/year'
|
5
4
|
|
6
|
-
require_relative '../../../era/western'
|
5
|
+
require_relative '../../../era/western/calendar'
|
7
6
|
|
8
7
|
# :nodoc:
|
9
8
|
module Zakuro
|
@@ -21,27 +20,30 @@ module Zakuro
|
|
21
20
|
# 年間範囲内の年データの開始月を変更する
|
22
21
|
#
|
23
22
|
# @param [Context] context 暦コンテキスト
|
24
|
-
# @param [Array<Year>] annual_ranges 年データ(冬至基準)
|
23
|
+
# @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
|
25
24
|
#
|
26
|
-
# @return [Array<Year>] 年データ(元旦基準)
|
25
|
+
# @return [Array<Base::Year>] 年データ(元旦基準)
|
27
26
|
#
|
28
27
|
def self.get(context:, annual_ranges:)
|
29
28
|
categorize(context: context, annual_ranges: annual_ranges)
|
30
|
-
rearranged_years(annual_ranges: annual_ranges)
|
29
|
+
rearranged_years(context: context, annual_ranges: annual_ranges)
|
31
30
|
end
|
32
31
|
|
33
32
|
#
|
34
33
|
# 年間範囲内の年データの開始月を変更する
|
35
34
|
#
|
36
|
-
# @param [
|
35
|
+
# @param [Context] context 暦コンテキスト
|
36
|
+
# @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
|
37
37
|
#
|
38
|
-
# @return [Array<Year>] 年データ(元旦基準)
|
38
|
+
# @return [Array<Base::Year>] 年データ(元旦基準)
|
39
39
|
#
|
40
|
-
def self.rearranged_years(annual_ranges:)
|
40
|
+
def self.rearranged_years(context:, annual_ranges:)
|
41
41
|
years = []
|
42
42
|
|
43
43
|
(0..(annual_ranges.size - 2)).each do |index|
|
44
|
-
year = rearranged_year(
|
44
|
+
year = rearranged_year(
|
45
|
+
context: context, annual_ranges: annual_ranges, index: index
|
46
|
+
)
|
45
47
|
years.push(year)
|
46
48
|
end
|
47
49
|
|
@@ -53,7 +55,7 @@ module Zakuro
|
|
53
55
|
# 年間範囲を昨年/今年で分類する
|
54
56
|
#
|
55
57
|
# @param [Context] context 暦コンテキスト
|
56
|
-
# @param [Array<Year>] annual_range 1年データ
|
58
|
+
# @param [Array<Base::Year>] annual_range 1年データ
|
57
59
|
#
|
58
60
|
def self.categorize(context:, annual_ranges:)
|
59
61
|
annual_ranges.each do |annual_range|
|
@@ -86,16 +88,17 @@ module Zakuro
|
|
86
88
|
#
|
87
89
|
# 年データの開始月を変更する
|
88
90
|
#
|
89
|
-
# @param [
|
91
|
+
# @param [Context] context 暦コンテキスト
|
92
|
+
# @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
|
90
93
|
# @param [Integer] index 対象年の要素番号
|
91
94
|
#
|
92
|
-
# @return [Year] 年データ(元旦基準)
|
95
|
+
# @return [Base::Year] 年データ(元旦基準)
|
93
96
|
#
|
94
|
-
def self.rearranged_year(annual_ranges:, index:)
|
97
|
+
def self.rearranged_year(context:, annual_ranges:, index:)
|
95
98
|
current_annual_range = annual_ranges[index]
|
96
99
|
next_annual_range = annual_ranges[index + 1]
|
97
100
|
|
98
|
-
year = push_current_year(annual_range: current_annual_range)
|
101
|
+
year = push_current_year(context: context, annual_range: current_annual_range)
|
99
102
|
push_last_year(annual_range: next_annual_range, year: year)
|
100
103
|
|
101
104
|
year
|
@@ -105,12 +108,13 @@ module Zakuro
|
|
105
108
|
#
|
106
109
|
# 当年データを生成する
|
107
110
|
#
|
108
|
-
# @param [
|
109
|
-
# @param [
|
111
|
+
# @param [Context] context 暦コンテキスト
|
112
|
+
# @param [Array<Month>] annual_range 1年データ
|
110
113
|
#
|
111
|
-
# @return [Year] 当年月ありの対象年
|
114
|
+
# @return [Base::Year] 当年月ありの対象年
|
112
115
|
#
|
113
|
-
def self.push_current_year(
|
116
|
+
def self.push_current_year(context:, annual_range:)
|
117
|
+
year = Base::Year.new(context: context)
|
114
118
|
annual_range.each do |month|
|
115
119
|
next if month.is_last_year
|
116
120
|
|
@@ -124,10 +128,10 @@ module Zakuro
|
|
124
128
|
#
|
125
129
|
# 昨年データを生成する
|
126
130
|
#
|
127
|
-
# @param [Array<
|
128
|
-
# @param [Year] year 対象年
|
131
|
+
# @param [Array<Month>] annual_range 1年データ
|
132
|
+
# @param [Base::Year] year 対象年
|
129
133
|
#
|
130
|
-
# @return [Year] 昨年月ありの対象年
|
134
|
+
# @return [Base::Year] 昨年月ありの対象年
|
131
135
|
#
|
132
136
|
def self.push_last_year(annual_range:, year: Base::Year.new)
|
133
137
|
annual_range.each do |month|
|