zakuro 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +25 -0
  5. data/doc/operation/csv/month.csv +1 -1
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/doc/vanished_date.md +26 -0
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +26 -0
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +1 -1
  10. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +6 -2
  11. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +5 -5
  12. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +12 -5
  13. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +9 -3
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -2
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +4 -2
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +5 -3
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +9 -4
  18. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
  19. data/lib/zakuro/calculation/monthly/initialized_month.rb +4 -2
  20. data/lib/zakuro/calculation/monthly/meta/all_solar_term.rb +64 -0
  21. data/lib/zakuro/calculation/monthly/meta/meta_collector.rb +80 -0
  22. data/lib/zakuro/calculation/monthly/meta.rb +60 -0
  23. data/lib/zakuro/calculation/monthly/month.rb +60 -5
  24. data/lib/zakuro/calculation/monthly/operated_month.rb +5 -19
  25. data/lib/zakuro/calculation/option/dropped_date/location.rb +12 -23
  26. data/lib/zakuro/calculation/option/vanished_date/location.rb +9 -2
  27. data/lib/zakuro/calculation/range/abstract_full_range.rb +19 -2
  28. data/lib/zakuro/calculation/range/abstract_operation_range.rb +20 -2
  29. data/lib/zakuro/calculation/range/dated_full_range.rb +3 -1
  30. data/lib/zakuro/calculation/range/dated_operation_range.rb +3 -1
  31. data/lib/zakuro/calculation/range/medieval_annual_range.rb +1 -1
  32. data/lib/zakuro/calculation/range/named_full_range.rb +3 -1
  33. data/lib/zakuro/calculation/range/named_operation_range.rb +3 -1
  34. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +2 -1
  35. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +10 -8
  36. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +8 -34
  37. data/lib/zakuro/calculation/summary/internal/option.rb +24 -5
  38. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +1 -1
  39. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +1 -1
  40. data/lib/zakuro/era/japan/gengou/alignment.rb +14 -2
  41. data/lib/zakuro/era/japan/gengou/resource/parser.rb +83 -25
  42. data/lib/zakuro/era/japan/gengou/resource/type.rb +81 -26
  43. data/lib/zakuro/era/japan/gengou/resource/validator.rb +100 -21
  44. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1123 -375
  45. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +487 -163
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +30 -10
  47. data/lib/zakuro/era/japan/gengou/resource.rb +16 -0
  48. data/lib/zakuro/era/japan/gengou.rb +7 -4
  49. data/lib/zakuro/operation/yaml/month.yaml +1 -1
  50. data/lib/zakuro/output/logger.rb +21 -3
  51. data/lib/zakuro/tools/remainder_comparer.rb +97 -0
  52. metadata +6 -2
@@ -2,7 +2,9 @@
2
2
 
3
3
  require_relative '../base/gengou'
4
4
  require_relative './first_day'
5
+ require_relative './meta'
5
6
  require_relative './month_label'
7
+ require_relative './meta/meta_collector'
6
8
 
7
9
  # :nodoc:
8
10
  module Zakuro
@@ -20,10 +22,14 @@ module Zakuro
20
22
  attr_reader :month_label
21
23
  # @return [FirstDay] 月初日(朔日)
22
24
  attr_reader :first_day
23
- # @return [Array<SolarTerm>] 二十四節気
25
+ # @return [Array<AbstractSolarTerm>] 二十四節気
24
26
  attr_reader :solar_terms
25
27
  # @return [Base::Gengou] 元号
26
28
  attr_reader :gengou
29
+ # @return [Meta] 付加情報
30
+ attr_reader :meta
31
+
32
+ # rubocop:disable Metrics/ParameterLists
27
33
 
28
34
  #
29
35
  # 初期化
@@ -31,18 +37,23 @@ module Zakuro
31
37
  # @param [Context::Context] context 暦コンテキスト
32
38
  # @param [MonthLabel] month_label 月表示名
33
39
  # @param [FirstDay] first_day 月初日(朔日)
34
- # @param [Array<SolarTerm>] solar_terms 二十四節気
40
+ # @param [Array<AbstractSolarTerm>] solar_terms 二十四節気
35
41
  # @param [Base::Gengou] gengou 元号
42
+ # @param [Meta] meta 付加情報
36
43
  #
37
44
  def initialize(context: Context::Context.new, month_label: MonthLabel.new,
38
- first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new)
45
+ first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
46
+ meta: Meta.new)
39
47
  @context = context
40
48
  @month_label = month_label
41
49
  @first_day = first_day
42
50
  @solar_terms = solar_terms
43
51
  @gengou = gengou
52
+ @meta = meta
44
53
  end
45
54
 
55
+ # rubocop:enable Metrics/ParameterLists
56
+
46
57
  #
47
58
  # 不正か
48
59
  #
@@ -153,7 +164,7 @@ module Zakuro
153
164
  #
154
165
  # 中気を返す
155
166
  #
156
- # @return [SolarTerm] 中気
167
+ # @return [Cycle::AbstractSolarTerm] 中気
157
168
  #
158
169
  def even_term
159
170
  solar_terms.each do |term|
@@ -166,7 +177,7 @@ module Zakuro
166
177
  #
167
178
  # 節気を返す
168
179
  #
169
- # @return [SolarTerm] 節気
180
+ # @return [Cycle::AbstractSolarTerm] 節気
170
181
  #
171
182
  def odd_term
172
183
  solar_terms.each do |term|
@@ -250,6 +261,50 @@ module Zakuro
250
261
  same_by_japan_date?(date: date)
251
262
  end
252
263
 
264
+ #
265
+ # 大余に対応する二十四節気
266
+ #
267
+ # @param [Integer] day 大余
268
+ #
269
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
270
+ #
271
+ def solar_term_by_day(day:)
272
+ # TODO: refactor
273
+ target = context.resolver.remainder.new(day: day, minute: 0, second: 0)
274
+
275
+ meta.all_solar_terms.each_cons(2) do |current_solar_term, next_solar_term|
276
+ in_range = Tools::RemainderComparer.in_range?(
277
+ target: target, start: current_solar_term.remainder, last: next_solar_term.remainder
278
+ )
279
+ return current_solar_term if in_range
280
+ end
281
+
282
+ last_solar_term = meta.all_solar_terms[-1]
283
+
284
+ empty_solar_term = context.resolver.solar_term.new
285
+
286
+ return empty_solar_term unless last_solar_term
287
+ # NOTE: 大余20を上限として範囲チェックする
288
+ if Tools::RemainderComparer.in_limit?(target: target, start: last_solar_term.remainder,
289
+ limit: 20)
290
+ return last_solar_term
291
+ end
292
+
293
+ empty_solar_term
294
+ end
295
+
296
+ #
297
+ # メタ情報を再設定する
298
+ #
299
+ # @param [Month] last 前月
300
+ #
301
+ def reset_meta(last: Month.new)
302
+ @meta = MetaCollector.get(
303
+ before_month: last,
304
+ current_month: self
305
+ )
306
+ end
307
+
253
308
  private
254
309
 
255
310
  #
@@ -33,12 +33,13 @@ module Zakuro
33
33
  # @param [FirstDay] first_day 月初日(朔日)
34
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
35
35
  # @param [Operation::MonthHistory] history 変更履歴(月)
36
+ # @param [Meta] meta 付加情報
36
37
  #
37
38
  def initialize(context:, operated_solar_term:, month_label: MonthLabel.new,
38
39
  first_day: FirstDay.new, solar_terms: [], gengou: Base::Gengou.new,
39
- history: Operation::MonthHistory.new)
40
+ history: Operation::MonthHistory.new, meta: Meta.new)
40
41
  super(context: context, month_label: month_label, first_day: first_day,
41
- solar_terms: solar_terms, gengou: gengou)
42
+ solar_terms: solar_terms, gengou: gengou, meta: meta)
42
43
  @history = history
43
44
  @operated_solar_term = operated_solar_term
44
45
  @moved = false
@@ -102,7 +103,8 @@ module Zakuro
102
103
  @first_day = FirstDay.new(
103
104
  western_date: rewrite_western_date(days: days),
104
105
  remainder: rewrite_remainder(days: days),
105
- average_remainder: rewrite_average_remainder(days: days)
106
+ # NOTE: 『日本暦日便覧』では滅日を計算値で求めている。運用値への書き換えは実施しない
107
+ average_remainder: first_day.average_remainder.clone
106
108
  )
107
109
  end
108
110
 
@@ -122,22 +124,6 @@ module Zakuro
122
124
  remainder
123
125
  end
124
126
 
125
- #
126
- # 月初日の大余小余を日差分で書き換える(経朔)
127
- #
128
- # @param [Integer] days 日差分
129
- #
130
- # @return [Remainder] 月初日の大余小余
131
- #
132
- def rewrite_average_remainder(days:)
133
- remainder = first_day.average_remainder.clone
134
- remainder.add!(
135
- context.resolver.remainder.new(day: days, minute: 0, second: 0)
136
- )
137
-
138
- remainder
139
- end
140
-
141
127
  #
142
128
  # 月初日の西暦日を日差分で書き換える
143
129
  #
@@ -24,8 +24,8 @@ module Zakuro
24
24
  attr_reader :limit
25
25
  # @return [Integer] 年
26
26
  attr_reader :year
27
- # @return [Array<Cycle::AbstractSolarTerm>] 二十四節気
28
- attr_reader :solar_terms
27
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
28
+ attr_reader :solar_term
29
29
  # @return [Class] 没余クラス
30
30
  attr_reader :remainder_class
31
31
 
@@ -33,16 +33,16 @@ module Zakuro
33
33
  # 初期化
34
34
  #
35
35
  # @param [Context::Context] context 暦コンテキスト
36
- # @param [Array<Cycle::AbstractSolarTerm>] solar_terms 二十四節気
36
+ # @param [Cycle::AbstractSolarTerm] solar_term 二十四節気
37
37
  #
38
- def initialize(context:, solar_terms: [])
38
+ def initialize(context:, solar_term:)
39
39
  parameter = context.resolver.dropped_date_parameter.new
40
40
  @context = context
41
41
  @valid = parameter.valid
42
42
  @limit = parameter.limit
43
43
  @year = parameter.year
44
44
  @remainder_class = parameter.remainder_class
45
- @solar_terms = solar_terms
45
+ @solar_term = solar_term
46
46
  end
47
47
 
48
48
  #
@@ -73,36 +73,25 @@ module Zakuro
73
73
  def get
74
74
  # 1. 二十四節気の大余小余を取り出す
75
75
  remainder = solar_term_remainder
76
+
77
+ # p "remainder: #{remainder.format(form: '%d-%d.%.5f')}"
78
+
76
79
  # 2. 小余360、秒45(360/8)で乗算する
77
80
  total = multiple_ideal_year(remainder: remainder)
81
+ # p "total: #{total}"
78
82
  # 3. 上記2と章歳(3068055)の差を求める
79
83
  diff = (year - total).abs
84
+ # p "year: #{year}"
85
+ # p "diff: #{diff}"
80
86
  # 4. 上記3を通余で徐算する
81
87
  result = remainder_class.new(total: diff)
88
+ # p "result: #{result.format(form: '%d-%d.%.5f')}"
82
89
  # 5. 上記4の商と上記1の大余が没日大余、余りが小余(没余)
83
90
  day = remainder_class.new(day: remainder.day, minute: 0, second: 0)
84
91
 
85
92
  day.add(result)
86
93
  end
87
94
 
88
- #
89
- # 該当の二十四節気を取得する
90
- #
91
- # @return [Cycle::AbstractSolarTerm] 二十四節気
92
- #
93
- def solar_term
94
- solar_terms.each do |solar_term|
95
- remainder = solar_term.remainder.clone
96
- minute_later = remainder.class.new(
97
- day: 0, minute: remainder.minute, second: remainder.second
98
- )
99
-
100
- return solar_term if minute_later >= limit
101
- end
102
-
103
- context.resolver.solar_term.new
104
- end
105
-
106
95
  private
107
96
 
108
97
  #
@@ -72,10 +72,17 @@ module Zakuro
72
72
  #
73
73
  def get
74
74
  # 経朔の小余 * 30
75
- minute = remainder_class.new(day: 0, minute: IDEAL_MONTH * average_remainder.minute, second: 0)
75
+ minute = remainder_class.new(
76
+ day: 0, minute: IDEAL_MONTH * average_remainder.minute, second: 0
77
+ )
78
+
76
79
  day = remainder_class.new(day: average_remainder.day, minute: 0, second: 0)
77
80
 
78
- minute.add(day)
81
+ minute.add!(day)
82
+
83
+ # p "location.minute: #{minute.format}"
84
+
85
+ minute
79
86
  end
80
87
  end
81
88
  end
@@ -20,8 +20,6 @@ module Zakuro
20
20
  module Calculation
21
21
  # :nodoc:
22
22
  module Range
23
- # :reek:TooManyInstanceVariables { max_instance_variables: 6 }
24
-
25
23
  #
26
24
  # FullRange 完全範囲
27
25
  # ある日からある日の範囲を計算可能な年月範囲
@@ -89,6 +87,8 @@ module Zakuro
89
87
 
90
88
  Transfer::GengouScroller.set(scroll: scroll, years: years)
91
89
 
90
+ reset_meta(years: years)
91
+
92
92
  years
93
93
  end
94
94
 
@@ -104,6 +104,7 @@ module Zakuro
104
104
  last_year = scroll.western_last_year
105
105
 
106
106
  # TODO: context にデフォルト暦名が設定されている場合は使用しない
107
+ # 現在は暦ごとの元号情報がないため使用できない
107
108
  versions = Version.get(start_year: start_year, last_year: last_year)
108
109
 
109
110
  collect_version_ranges(versions: versions, start_year: start_year, last_year: last_year)
@@ -181,6 +182,22 @@ module Zakuro
181
182
 
182
183
  result
183
184
  end
185
+
186
+ #
187
+ # メタ情報を更新する
188
+ #
189
+ # @param [Array<Base::Year>] years 完全範囲
190
+ #
191
+ def reset_meta(years: [])
192
+ months = []
193
+ years.each do |year|
194
+ months |= year.months
195
+ end
196
+
197
+ months.each_cons(2) do |last, current|
198
+ current.reset_meta(last: last)
199
+ end
200
+ end
184
201
  end
185
202
  end
186
203
  end
@@ -53,6 +53,8 @@ module Zakuro
53
53
 
54
54
  Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
55
55
 
56
+ self.class.reset_meta(years: operated_years)
57
+
56
58
  operated_years
57
59
  end
58
60
 
@@ -172,20 +174,36 @@ module Zakuro
172
174
  # @param [Operation::MonthHistory] history 変更履歴
173
175
  # @param [OperatedSolarTerm] operated_solar_term 運用時二十四節気
174
176
  #
175
- # @return [Month] 月(運用結果)
177
+ # @return [Monthly::Month] 月(運用結果)
176
178
  #
177
179
  def rewrite_month(context:, month:, history:, operated_solar_term:)
178
180
  operated_month = Monthly::OperatedMonth.new(
179
181
  context: context,
180
182
  month_label: month.month_label, first_day: month.first_day,
181
183
  solar_terms: month.solar_terms, history: history, gengou: month.gengou,
182
- operated_solar_term: operated_solar_term
184
+ operated_solar_term: operated_solar_term, meta: month.meta
183
185
  )
184
186
 
185
187
  operated_month.rewrite unless history.invalid?
186
188
 
187
189
  operated_month
188
190
  end
191
+
192
+ #
193
+ # メタ情報を更新する
194
+ #
195
+ # @param [Array<Base::Year>] years 完全範囲
196
+ #
197
+ def reset_meta(years: [])
198
+ months = []
199
+ years.each do |year|
200
+ months |= year.months
201
+ end
202
+
203
+ months.each_cons(2) do |last, current|
204
+ current.reset_meta(last: last)
205
+ end
206
+ end
189
207
  end
190
208
  end
191
209
  end
@@ -22,7 +22,9 @@ module Zakuro
22
22
  #
23
23
  def initialize(context:,
24
24
  start_date: Western::Calendar.new, last_date: Western::Calendar.new)
25
- scroll = Gengou::DatedScroll.new(start_date: start_date, last_date: last_date)
25
+ scroll = Gengou::DatedScroll.new(
26
+ start_date: start_date, last_date: last_date, operated: false
27
+ )
26
28
 
27
29
  super(context: context, scroll: scroll, start_date: start_date, last_date: last_date)
28
30
  end
@@ -24,7 +24,9 @@ module Zakuro
24
24
  #
25
25
  def initialize(context:, start_date: Western::Calendar.new,
26
26
  last_date: Western::Calendar.new, years: [])
27
- scroll = Gengou::DatedScroll.new(start_date: start_date, last_date: last_date)
27
+ scroll = Gengou::DatedScroll.new(
28
+ start_date: start_date, last_date: last_date, operated: true
29
+ )
28
30
  super(context: context, scroll: scroll, years: years)
29
31
  end
30
32
  end
@@ -63,7 +63,7 @@ module Zakuro
63
63
  result = []
64
64
 
65
65
  # 14ヶ月分を生成する(閏年で最大13ヶ月 + 末月の大小/二十四節気を求めるために必要な月)
66
- (0..13).each do |_index|
66
+ 14.times.each do |_index|
67
67
  average_remainder = lunar_phase.average_remainder.clone
68
68
  adjusted = lunar_phase.next_month
69
69
 
@@ -24,7 +24,9 @@ module Zakuro
24
24
  # @param [String] last_name 終了元号名
25
25
  #
26
26
  def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME)
27
- scroll = Gengou::NamedScroll.new(start_name: start_name, last_name: last_name)
27
+ scroll = Gengou::NamedScroll.new(
28
+ start_name: start_name, last_name: last_name, operated: false
29
+ )
28
30
  range = scroll.range
29
31
 
30
32
  super(
@@ -26,7 +26,9 @@ module Zakuro
26
26
  # @param [Array<Year>] years 年データ(完全範囲)
27
27
  #
28
28
  def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME, years: [])
29
- scroll = Gengou::NamedScroll.new(start_name: start_name, last_name: last_name)
29
+ scroll = Gengou::NamedScroll.new(
30
+ start_name: start_name, last_name: last_name, operated: true
31
+ )
30
32
 
31
33
  super(context: context, scroll: scroll, years: years)
32
34
  end
@@ -46,7 +46,8 @@ module Zakuro
46
46
  average_remainder: month.first_day.average_remainder,
47
47
  western_date: gengou.start_date.clone
48
48
  ),
49
- solar_terms: month.solar_terms, gengou: gengou
49
+ solar_terms: month.solar_terms, gengou: gengou,
50
+ meta: month.meta
50
51
  )
51
52
  end
52
53
  end
@@ -21,12 +21,13 @@ module Zakuro
21
21
  # 年間範囲内の年データの開始月を変更する
22
22
  #
23
23
  # @param [Context::Context] context 暦コンテキスト
24
- # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
24
+ # @param [Array<Array<Monthly::Month>>] annual_ranges 年データ(冬至基準)
25
25
  #
26
26
  # @return [Array<Base::Year>] 年データ(元旦基準)
27
27
  #
28
28
  def get(context:, annual_ranges:)
29
29
  categorize(context: context, annual_ranges: annual_ranges)
30
+
30
31
  rearranged_years(context: context, annual_ranges: annual_ranges)
31
32
  end
32
33
 
@@ -36,7 +37,7 @@ module Zakuro
36
37
  # 年間範囲内の年データの開始月を変更する
37
38
  #
38
39
  # @param [Context::Context] context 暦コンテキスト
39
- # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
40
+ # @param [Array<Array<Monthly::Month>>] annual_ranges 年データ(冬至基準)
40
41
  #
41
42
  # @return [Array<Base::Year>] 年データ(元旦基準)
42
43
  #
@@ -57,7 +58,7 @@ module Zakuro
57
58
  # 年間範囲を昨年/今年で分類する
58
59
  #
59
60
  # @param [Context::Context] context 暦コンテキスト
60
- # @param [Array<Base::Year>] annual_range 1年データ
61
+ # @param [Array<Array<Monthly::Month>>] annual_range 1年データ
61
62
  #
62
63
  def categorize(context:, annual_ranges:)
63
64
  annual_ranges.each do |annual_range|
@@ -69,7 +70,7 @@ module Zakuro
69
70
  # 各月を昨年/今年で分類する
70
71
  #
71
72
  # @param [Context::Context] context 暦コンテキスト
72
- # @param [Array<Month>] annual_range 1年データ
73
+ # @param [Array<Monthly::Month>] annual_range 1年データ
73
74
  #
74
75
  def categorize_year(context:, annual_range:)
75
76
  is_last_year = true
@@ -80,7 +81,8 @@ module Zakuro
80
81
  context: context,
81
82
  month_label: month.month_label, first_day: month.first_day,
82
83
  solar_terms: month.solar_terms, phase_index: month.phase_index,
83
- is_last_year: is_last_year
84
+ is_last_year: is_last_year,
85
+ meta: month.meta
84
86
  )
85
87
  end
86
88
  end
@@ -89,7 +91,7 @@ module Zakuro
89
91
  # 年データの開始月を変更する
90
92
  #
91
93
  # @param [Context::Context] context 暦コンテキスト
92
- # @param [Array<Base::Year>] annual_ranges 年データ(冬至基準)
94
+ # @param [Array<Array<Monthly::Month>>] annual_ranges 年データ(冬至基準)
93
95
  # @param [Integer] index 対象年の要素番号
94
96
  #
95
97
  # @return [Base::Year] 年データ(元旦基準)
@@ -108,7 +110,7 @@ module Zakuro
108
110
  # 当年データを生成する
109
111
  #
110
112
  # @param [Context::Context] context 暦コンテキスト
111
- # @param [Array<Month>] annual_range 1年データ
113
+ # @param [Array<Monthly::Month>] annual_range 1年データ
112
114
  #
113
115
  # @return [Base::Year] 当年月ありの対象年
114
116
  #
@@ -126,7 +128,7 @@ module Zakuro
126
128
  #
127
129
  # 昨年データを生成する
128
130
  #
129
- # @param [Array<Month>] annual_range 1年データ
131
+ # @param [Array<Monthly::Month>] annual_range 1年データ
130
132
  # @param [Base::Year] year 対象年
131
133
  #
132
134
  # @return [Base::Year] 昨年月ありの対象年
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../monthly/meta/meta_collector'
4
+
5
+ require_relative '../../../tools/remainder_comparer'
6
+
3
7
  # :nodoc:
4
8
  module Zakuro
5
9
  # :nodoc:
@@ -42,36 +46,6 @@ module Zakuro
42
46
  annual_range
43
47
  end
44
48
 
45
- # :reek:TooManyStatements { max_statements: 7 }
46
-
47
- class << self
48
- #
49
- # 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか
50
- # @note 大余60で一巡するため 以下2パターンがある
51
- # * current_month <= next_month : (二十四節気) >= current_month && (二十四節気) < next_month
52
- # * current_month > next_month : (二十四節気) >= current_month || (二十四節気) < next_month
53
- #
54
- # @param [Cycle::AbstractRemainder] solar_term 二十四節気
55
- # @param [Cycle::AbstractRemainder] current_month 月初
56
- # @param [Cycle::AbstractRemainder] next_month 月末
57
- #
58
- # @return [True] 対象の二十四節気がある
59
- # @return [False] 対象の二十四節気がない
60
- #
61
- def in_solar_term?(solar_term:, current_month:, next_month:)
62
- # 大余で比較する
63
- target_time = solar_term.day
64
- current_month_time = current_month.day
65
- next_month_time = next_month.day
66
- current_month_over = (target_time >= current_month_time)
67
- next_month_under = (target_time < next_month_time)
68
-
69
- return current_month_over && next_month_under if current_month_time <= next_month_time
70
-
71
- current_month_over || next_month_under
72
- end
73
- end
74
-
75
49
  private
76
50
 
77
51
  # :reek:TooManyStatements { max_statements: 8 }
@@ -87,10 +61,10 @@ module Zakuro
87
61
  # * 最大試行回数:4回(設定なし => 設定あり => 設定あり => 設定なし)
88
62
  # * 閏月は1回しか設定しない
89
63
  # * 最大2回設定する(中気・節気)
90
- (0..3).each do |_index|
91
- in_range = self.class.in_solar_term?(
92
- solar_term: solar_term.remainder, current_month: current_month.remainder,
93
- next_month: next_month.remainder
64
+ 4.times.each do |_index|
65
+ in_range = Tools::RemainderComparer.in_range?(
66
+ target: solar_term.remainder, start: current_month.remainder,
67
+ last: next_month.remainder
94
68
  )
95
69
 
96
70
  # 範囲外
@@ -34,17 +34,32 @@ module Zakuro
34
34
  context = month.context
35
35
 
36
36
  if context.option.dropped_date?
37
+ solar_term = month.solar_term_by_day(day: day.remainder.day)
38
+
37
39
  remainder = day.remainder
38
- solar_terms = month.solar_terms
39
40
  option = dropped_date(
40
- context: context, remainder: remainder, solar_terms: solar_terms
41
+ context: context, remainder: remainder, solar_term: solar_term
41
42
  )
42
43
  options[Context::Option::DROPPED_DATE_KEY] = option
43
44
  end
44
45
 
46
+ # TODO: refactor
45
47
  if context.option.vanished_date?
46
48
  remainder = day.remainder
47
49
  average_remainder = month.first_day.average_remainder
50
+ # p "remainder: #{remainder.format}"
51
+ # p "last_average_remainder: #{month.meta.last_average_remainder.format}"
52
+
53
+ if day.number == 1
54
+ option = vanished_date(
55
+ context: context, remainder: remainder,
56
+ average_remainder: month.meta.last_average_remainder
57
+ )
58
+ options[Context::Option::VANISHED_DATE_KEY] = option
59
+
60
+ return options if option.matched
61
+ end
62
+
48
63
  option = vanished_date(
49
64
  context: context, remainder: remainder, average_remainder: average_remainder
50
65
  )
@@ -61,19 +76,21 @@ module Zakuro
61
76
  #
62
77
  # @param [Context::Context] context 暦コンテキスト
63
78
  # @param [Cycle::AbstractRemainder] remainder 当日和暦日
64
- # @param [Array<Cycle::AbstractSolarTerm>] solar_terms 二十四節気
79
+ # @param [Cycle::AbstractSolarTerm] solar_terms 二十四節気
65
80
  #
66
81
  # @return [Result::Data::Option::DroppedDate::Option] 没日
67
82
  #
68
- def dropped_date(context:, remainder:, solar_terms:)
83
+ def dropped_date(context:, remainder:, solar_term:)
69
84
  option = Result::Data::Option::DroppedDate::Option.new
70
85
 
71
86
  return option if remainder.invalid?
72
87
 
73
88
  location = Calculation::Option::DroppedDate::Location.new(
74
- context: context, solar_terms: solar_terms
89
+ context: context, solar_term: solar_term
75
90
  )
76
91
 
92
+ return option if location.invalid?
93
+
77
94
  return option unless location.exist?
78
95
 
79
96
  dropped_date = location.get
@@ -122,6 +139,8 @@ module Zakuro
122
139
  context: context, average_remainder: average_remainder
123
140
  )
124
141
 
142
+ return Result::Data::Option::VanishedDate::Option.new if location.invalid?
143
+
125
144
  unless location.exist?
126
145
  # 結果確認のため経朔だけは設定する
127
146
  return Result::Data::Option::VanishedDate::Option.new(
@@ -30,7 +30,7 @@ module Zakuro
30
30
  #
31
31
  # 取得する
32
32
  #
33
- # @param [Array<Calculation::Base::Year>] years 範囲
33
+ # @param [Array<Base::Year>] years 範囲
34
34
  # @param [Western::Calendar] date 西暦日
35
35
  #
36
36
  # @return [Result::Data::SingleDay] 和暦日
@@ -175,7 +175,7 @@ module Zakuro
175
175
  # @return [Western::Calendar]設定された元号の開始日
176
176
  #
177
177
  def native_start_date
178
- gengou.both_start_date.western
178
+ gengou.start_date.western
179
179
  end
180
180
 
181
181
  #