zakuro 0.1.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/doc/gengou.md +22 -22
  3. data/doc/operation/csv/month.csv +447 -202
  4. data/doc/operation/operation.xlsx +0 -0
  5. data/lib/zakuro/calculation/base/operated_year.rb +114 -0
  6. data/lib/zakuro/calculation/base/year.rb +3 -0
  7. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +44 -19
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +1 -1
  10. data/lib/zakuro/calculation/monthly/operated_month.rb +47 -3
  11. data/lib/zakuro/calculation/range/full_range.rb +1 -1
  12. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  13. data/lib/zakuro/calculation/range/operated_range.rb +61 -16
  14. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +78 -0
  15. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -0
  16. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  17. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  18. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  19. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  20. data/lib/zakuro/era/japan/reki.rb +1 -1
  21. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +22 -22
  22. data/lib/zakuro/operation/month/type.rb +58 -0
  23. data/lib/zakuro/operation/yaml/month.yaml +7840 -0
  24. data/lib/zakuro/version/context.rb +1 -1
  25. data/lib/zakuro/version/daien/const/number.rb +55 -0
  26. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  27. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  28. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  29. data/lib/zakuro/version/daien/daien.rb +36 -0
  30. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  31. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  32. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  33. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  34. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  35. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  36. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  37. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  38. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  39. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  40. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  41. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  42. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  43. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  44. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  45. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  46. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  47. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  48. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  49. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  50. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  51. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  52. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  53. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  54. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  55. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  56. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  57. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  58. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  59. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  60. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  61. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  62. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  63. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  64. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  65. data/lib/zakuro/version/senmyou/cycle/remainder.rb +5 -12
  66. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +4 -1
  67. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +36 -155
  68. data/lib/zakuro/version/senmyou/range/annual_range.rb +7 -135
  69. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  70. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  71. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  72. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  73. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  74. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  75. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  76. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  77. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  78. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  79. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  80. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  81. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  82. data/lib/zakuro/version.rb +1 -1
  83. data/lib/zakuro/version_factory.rb +1 -1
  84. metadata +62 -8
  85. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  86. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  87. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  88. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  89. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  90. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -1,332 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # LunarOrbit 月軌道
9
- #
10
- module LunarOrbit
11
- # @return [Integer] 暦周(1近日点)
12
- ANOMALISTIC_MONTH = 231_458.19
13
- # @return [Integer] 暦中日
14
- # @note ANOMALISTIC_MONTH の半分に相当する
15
- HALF_ANOMALISTIC_MONTH = \
16
- Cycle::LunarRemainder.new(day: 13, minute: 6529, second: 9.5)
17
-
18
- #
19
- # Adjustment 補正値情報
20
- #
21
- module Adjustment
22
- #
23
- # Item 補正値
24
- #
25
- class Item
26
- # @return [Integer] 損益率
27
- attr_reader :per
28
- # @return [Integer] 眺朒(ちょうじく)積
29
- attr_reader :stack
30
-
31
- #
32
- # 初期化
33
- #
34
- # @param [Integer] per 損益率
35
- # @param [Integer] stack 眺朒(ちょうじく)積
36
- #
37
- def initialize(per:, stack:)
38
- @per = per
39
- @stack = stack
40
- end
41
-
42
- #
43
- # 文字化
44
- #
45
- # @return [String] 文字
46
- #
47
- def to_s
48
- "per:#{@per}, stack:#{@stack}"
49
- end
50
- end
51
-
52
- # @return [Array<Item>] 月の補正値
53
- # @note キーは複合キーであり、以下のパターンに対応する
54
- # * 進退
55
- # * forward: 進(遠地点より数える)
56
- # * back: 退(近地点より数える)
57
- # * 入暦(1-14)
58
- # * 小余(0-8400)
59
- LIST = {
60
- forward_01_0000_8400: Item.new(per: +830, stack: 0),
61
- forward_02_0000_8400: Item.new(per: +726, stack: +830),
62
- forward_03_0000_8400: Item.new(per: +606, stack: +1556),
63
- forward_04_0000_8400: Item.new(per: +471, stack: +2162),
64
- forward_05_0000_8400: Item.new(per: +337, stack: +2633),
65
- forward_06_0000_8400: Item.new(per: +202, stack: +2970),
66
- forward_07_0000_7465: Item.new(per: +53, stack: +3172),
67
- forward_07_7465_8400: Item.new(per: -7, stack: +3225), # +3172 + 53(初益)
68
- forward_08_0000_8400: Item.new(per: -82, stack: +3218),
69
- forward_09_0000_8400: Item.new(per: -224, stack: +3136),
70
- forward_10_0000_8400: Item.new(per: -366, stack: +2912),
71
- forward_11_0000_8400: Item.new(per: -509, stack: +2546),
72
- forward_12_0000_8400: Item.new(per: -643, stack: +2037),
73
- forward_13_0000_8400: Item.new(per: -748, stack: +1394),
74
- forward_14_0000_6529: Item.new(per: -646, stack: +646), # 14日の小余は常に6529以下
75
- back_01_0000_8400: Item.new(per: -830, stack: 0),
76
- back_02_0000_8400: Item.new(per: -726, stack: -830),
77
- back_03_0000_8400: Item.new(per: -598, stack: -1556),
78
- back_04_0000_8400: Item.new(per: -464, stack: -2154),
79
- back_05_0000_8400: Item.new(per: -329, stack: -2618),
80
- back_06_0000_8400: Item.new(per: -195, stack: -2947),
81
- back_07_0000_7465: Item.new(per: -53, stack: -3142),
82
- back_07_7465_8400: Item.new(per: +7, stack: -3195), # -3142 - 53(初益)
83
- back_08_0000_8400: Item.new(per: +82, stack: -3188),
84
- back_09_0000_8400: Item.new(per: +225, stack: -3106),
85
- back_10_0000_8400: Item.new(per: +366, stack: -2881),
86
- back_11_0000_8400: Item.new(per: +501, stack: -2515),
87
- back_12_0000_8400: Item.new(per: +628, stack: -2014),
88
- back_13_0000_8400: Item.new(per: +740, stack: -1386),
89
- back_14_0000_6529: Item.new(per: +646, stack: -646) # 14日の小余は常に6529以下
90
- }.freeze
91
- end
92
-
93
- #
94
- # 月の運行による補正値を算出する
95
- #
96
- # @param [Remainder] remainder_month 月の大余小余
97
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
98
- #
99
- # @return [Integer] 補正値
100
- #
101
- def self.calc_moon_orbit_value(remainder_month:, is_forward:)
102
- valid?(remainder: remainder_month)
103
-
104
- day, minute = make_calculable_remainder_value(remainder: remainder_month)
105
-
106
- # 引き当て
107
- adjustment, diff, minute = specify_moon_adjustment(
108
- is_forward: is_forward, day: day, minute: minute
109
- )
110
- day = make_cumulative_value_for_days(per: adjustment.per,
111
- denominator: diff, minute: minute)
112
-
113
- adjustment.stack + day
114
- end
115
-
116
- #
117
- # 大余小余を検証する
118
- #
119
- # @param [Remainder] remainder 大余小余
120
- #
121
- # @return [True] 正しい(月の位相計算に使う大余小余)
122
- # @return [True] 正しくない
123
- #
124
- def self.valid?(remainder:)
125
- return if remainder.is_a?(Cycle::LunarRemainder)
126
-
127
- raise ArgumentError, "unmatch parameter type: #{remainder.class}"
128
- end
129
- private_class_method :valid?
130
-
131
- #
132
- # 大余小余を計算可能な値にする
133
- # @note 大余の秒(second)は使わない
134
- #
135
- # @param [LunarRemainder] remainder 大余小余
136
- #
137
- # @return [Integer] 大余
138
- # @return [Integer] 小余
139
- #
140
- def self.make_calculable_remainder_value(remainder:)
141
- day = remainder.day
142
- minute = remainder.minute + (remainder.second / 100)
143
- minute = minute.floor
144
-
145
- [day, minute]
146
- end
147
- private_class_method :make_calculable_remainder_value
148
-
149
- # :reek:TooManyStatements { max_statements: 9 }
150
-
151
- #
152
- # 累計値(大余)を作成する
153
- #
154
- # @param [Integer] per 入暦(1-14)
155
- # @param [Integer] denominator 小余の分母
156
- # @param [Integer] minute 小余
157
- #
158
- # @return [Integer] 累計値(大余)
159
- #
160
- def self.make_cumulative_value_for_days(per:, denominator:, minute:)
161
- remainder_minute = (per * minute).to_f
162
- day = remainder_minute / denominator
163
- # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
164
- day = day.negative? ? day.ceil : day.floor
165
- sign = remainder_minute.negative? ? -1 : 1
166
- remainder_day = (sign * remainder_minute) % denominator
167
- # 四捨五入(8400ならその半分の4200以上を繰り上げる)
168
- day += sign if remainder_day >= (denominator / 2)
169
-
170
- day
171
- end
172
- private_class_method :make_cumulative_value_for_days
173
-
174
- # :reek:TooManyStatements { max_statements: 9 }
175
-
176
- #
177
- # 月軌道の補正に必要な基本値を引き当てる
178
- #
179
- # @note 戻り値は calc_moon_orbit_value で使用する
180
- #
181
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
182
- # @param [Integer] day 大余
183
- # @param [Integer] minute 小余
184
- #
185
- # @return [Adjustment::Item] 補正値
186
- # @return [Integer] (小余を処理する時の)分母
187
- # @return [Integer] 小余の下げ幅
188
- #
189
- def self.specify_moon_adjustment(is_forward:, day:, minute:)
190
- prefix = { true => 'forward', false => 'back' }[is_forward]
191
-
192
- targets = Adjustment::LIST.select \
193
- { |key, _| key.match(/^#{prefix}_#{format('%<day>02d', day: day)}_.*/) }
194
-
195
- targets.each do |key, value|
196
- # NOTE: 境界値は上から順に引き当てた方を返す(7日の境界値7465は上のキーで返す)
197
- matched, diff = \
198
- extract_data_from_moon_adjustment_key(key, minute)
199
- # 小余の下げ幅
200
- calc_minute = (day == 7 && minute > 7465 ? minute - 7465 : minute)
201
- return value, diff, calc_minute if matched
202
- end
203
-
204
- [nil, nil, nil]
205
- end
206
- private_class_method :specify_moon_adjustment
207
-
208
- #
209
- # 補正値を引き当てる
210
- #
211
- # @param [String] key 補正値のキー
212
- # @param [Integer] minute 小余
213
- #
214
- # @return [Adjustment::Item] 補正値
215
- # @return [Integer] (小余を処理する時の)分母
216
- #
217
- def self.extract_data_from_moon_adjustment_key(key, minute)
218
- matched = key.match(/([0-9]{4})_([0-9]{4})$/)
219
- start = matched[1].to_i
220
- finish = matched[2].to_i
221
-
222
- matched = minute >= start && minute <= finish
223
- [matched, (finish - start)]
224
- end
225
- private_class_method :extract_data_from_moon_adjustment_key
226
-
227
- # :reek:ControlParameter and :reek:BooleanParameter
228
- # :reek:LongParameterList { max_params: 4 }
229
-
230
- #
231
- # 月地点を計算する
232
- #
233
- # @param [LunarRemainder] remainder 初回(昨年冬至), 前回計算結果(入暦)
234
- # @param [Integer] western_year 西暦年
235
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
236
- # @param [True, False] first 初回計算, 次回以降計算
237
- #
238
- # @return [LunarRemainder] 入暦
239
- # @return [True] 進(遠地点より数える)
240
- # @return [False] 退(近地点より数える)
241
- #
242
- def self.calc_moon_point(remainder:, western_year:,
243
- is_forward: true, first: true)
244
- if first
245
- return calc_first_moon_point(winter_solstice_age: remainder,
246
- western_year: western_year)
247
- end
248
- calc_following_moon_point(remainder: remainder, is_forward: is_forward)
249
- end
250
-
251
- # :reek:TooManyStatements { max_statements: 7 }
252
-
253
- #
254
- # 入暦(月の遠地点から数えた日数/近地点から数えた日数)を求める
255
- #
256
- # 天正冬至(入暦前回未計算)を求める
257
- #
258
- # @param [Remainder] winter_solstice_age 天正閏余
259
- # @param [Integer] western_year 西暦年
260
- #
261
- # @return [LunarRemainder] 入暦
262
- # @return [True] 進(遠地点より数える)
263
- # @return [False] 退(近地点より数える)
264
- #
265
- def self.calc_first_moon_point(winter_solstice_age:, western_year:)
266
- # 積年の開始から対象年までの年数
267
- total_year = \
268
- WinterSolstice::TOTAL_YEAR + western_year - WinterSolstice::BEGIN_YEAR
269
-
270
- # 通積分 - 天正閏余
271
- total_day = \
272
- total_year * WinterSolstice::YEAR - winter_solstice_age.to_minute
273
-
274
- remainder_month = \
275
- Cycle::LunarRemainder.new(total: (total_day % ANOMALISTIC_MONTH))
276
-
277
- remainder_month, is_forward = decrease_moon_point(
278
- remainder_month: remainder_month,
279
- remainder_limit: HALF_ANOMALISTIC_MONTH, is_forward: true
280
- )
281
-
282
- remainder_month.add!(Cycle::Remainder.new(day: 1, minute: 0, second: 0))
283
-
284
- [remainder_month, is_forward]
285
- end
286
- private_class_method :calc_first_moon_point
287
-
288
- #
289
- # 入暦(月の遠地点から数えた日数/近地点から数えた日数)を求める
290
- #
291
- # 前回計算結果を補正する
292
- #
293
- # @param [LunarRemainder] remainder 前回計算結果(入暦)
294
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
295
- #
296
- # @return [LunarRemainder] 入暦
297
- # @return [True] 進(遠地点より数える)
298
- # @return [False] 退(近地点より数える)
299
- #
300
- def self.calc_following_moon_point(remainder:, is_forward:)
301
- # 前回計算結果を引き継いた場合、暦中日ではなく損益眺朒(ちょうじく)数の上限とする
302
- remainder_month, is_forward = \
303
- decrease_moon_point(
304
- remainder_month: remainder,
305
- remainder_limit: Cycle::Remainder.new(day: 14, minute: 6529, second: 0),
306
- is_forward: is_forward
307
- )
308
-
309
- [remainder_month, is_forward]
310
- end
311
- private_class_method :calc_following_moon_point
312
-
313
- #
314
- # 月地点を減算する
315
- #
316
- # @param [LunarRemainder] remainder_month 大余小余
317
- # @param [Remainder] remainder_limit 大余小余の上限(最大の入暦)
318
- # @param [True, False] is_forward 進(遠地点より数える)/退(近地点より数える)
319
- #
320
- # @return [LunarRemainder] 大余小余の減算結果(上限値超えした場合)
321
- # @return [True] 進(遠地点より数える)
322
- # @return [False] 退(近地点より数える)
323
- #
324
- def self.decrease_moon_point(remainder_month:, remainder_limit:, is_forward:)
325
- return remainder_month, is_forward if remainder_month < remainder_limit
326
-
327
- [remainder_month.sub(HALF_ANOMALISTIC_MONTH), !is_forward]
328
- end
329
- private_class_method :decrease_moon_point
330
- end
331
- end
332
- end
@@ -1,169 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Senmyou
7
- #
8
- # SolarAverage 常気(太陽軌道平均)
9
- #
10
- class SolarAverage
11
- # @return [Remainder] 気策(24分の1年)
12
- SOLAR_TERM_AVERAGE = Cycle::Remainder.new(day: 15, minute: 1835, second: 5)
13
-
14
- #
15
- # 初期化
16
- #
17
- # @param [Integer] western_year 西暦年
18
- #
19
- def initialize(western_year:)
20
- @solar_term = SolarAverage.first_solar_term(western_year: western_year)
21
- end
22
-
23
- #
24
- # 冬至から数えた1年データの月ごとに二十四節気を割り当てる
25
- #
26
- # @param [Array<Month>] annual_range 1年データ
27
- #
28
- # @return [Array<Month>] 1年データ
29
- #
30
- def set(annual_range:)
31
- # 次月と比較しながら当月の二十四節気を決める
32
- # NOTE: 最後の月は処理できない(=計算外の余分な月が最後に必要である)
33
- annual_range.each_cons(2) do |(current_month, next_month)|
34
- set_solar_term(
35
- current_month: current_month,
36
- next_month: next_month
37
- )
38
- end
39
-
40
- annual_range
41
- end
42
-
43
- #
44
- # 計算開始する二十四節気を求める
45
- #
46
- # @param [Integer] western_year 西暦年
47
- #
48
- # @return [SolarTerm] 二十四節気
49
- #
50
- def self.first_solar_term(western_year:)
51
- # 天正冬至
52
- winter_solstice = WinterSolstice.calc(western_year: western_year)
53
-
54
- # 二十四節気(冬至)
55
- solar_term = Cycle::SolarTerm.new(index: 0, remainder: winter_solstice)
56
-
57
- first_solar_term_index = SolarAverage.calc_fist_solar_term_index(western_year: western_year)
58
-
59
- # 対象の二十四節気まで戻す
60
- solar_term.prev_by_index(first_solar_term_index)
61
-
62
- solar_term
63
- end
64
-
65
- #
66
- # 計算開始する二十四節気番号を求める
67
- #
68
- # * 前提として入定気は冬至の手前にある
69
- # * 例えば、定気が大雪であれば入定気は大雪の範囲内にある
70
- # * 入定気は、定気の開始位置に重複しない限り、常に定気より後にある
71
- # * 基本的に定気の一つ前から起算すれば、当時から求めた11月(閏10/閏11月)に二十四節気を割り当てられる
72
- #
73
- # @param [Integer] western_year 西暦年
74
- #
75
- # @return [Integer] 二十四節気番号
76
- #
77
- def self.calc_fist_solar_term_index(western_year:)
78
- # 天正閏余
79
- winter_solstice_age = \
80
- WinterSolstice.calc_moon_age(western_year: western_year)
81
-
82
- # 入定気を求める
83
- solar_location = SolarLocation.get(
84
- solar_term: Cycle::SolarTerm.new(remainder: winter_solstice_age)
85
- )
86
-
87
- solar_term_index = solar_location.index
88
-
89
- # 入定気の一つ後の二十四節気まで戻す(ただし11月経朔が二十四節気上にある場合は戻さない)
90
- solar_term_index += 1 unless solar_location.remainder == Cycle::Remainder.new(total: 0)
91
-
92
- solar_term_index
93
- end
94
-
95
- # :reek:TooManyStatements { max_statements: 7 }
96
-
97
- #
98
- # 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか
99
- # @note 大余60で一巡するため 以下2パターンがある
100
- # * current_month <= next_month : (二十四節気) >= current_month && (二十四節気) < next_month
101
- # * current_month > next_month : (二十四節気) >= current_month || (二十四節気) < next_month
102
- #
103
- # @param [Remainder] solar_term 二十四節気
104
- # @param [Remainder] current_month 月初
105
- # @param [Remainder] next_month 月末
106
- #
107
- # @return [True] 対象の二十四節気がある
108
- # @return [False] 対象の二十四節気がない
109
- #
110
- def self.in_solar_term?(solar_term:, current_month:, next_month:)
111
- # 大余で比較する
112
- target_time = solar_term.day
113
- current_month_time = current_month.day
114
- next_month_time = next_month.day
115
- current_month_over = (target_time >= current_month_time)
116
- next_month_under = (target_time < next_month_time)
117
-
118
- return current_month_over && next_month_under if current_month_time <= next_month_time
119
-
120
- current_month_over || next_month_under
121
- end
122
-
123
- private
124
-
125
- # :reek:TooManyStatements { max_statements: 8 }
126
-
127
- #
128
- # 二十四節気を設定する
129
- #
130
- # @param [Month] current_month 当月
131
- # @param [Month] next_month 次月
132
- #
133
- def set_solar_term(current_month:, next_month:)
134
- # 安全策として無限ループは回避する
135
- # * 最大試行回数:4回(設定なし => 設定あり => 設定あり => 設定なし)
136
- # * 閏月は1回しか設定しない
137
- # * 最大2回設定する(中気・節気)
138
- (0..3).each do |_index|
139
- in_range = SolarAverage.in_solar_term?(
140
- solar_term: @solar_term.remainder, current_month: current_month.remainder,
141
- next_month: next_month.remainder
142
- )
143
-
144
- # 範囲外
145
- unless in_range
146
- # 1つ以上設定されていれば切り上げる(一つ飛ばしで二十四節気を設定することはない)
147
- break unless current_month.empty_solar_term?
148
-
149
- next_solar_term
150
- next
151
- end
152
-
153
- current_month.add_term(term: @solar_term.clone)
154
- next_solar_term
155
-
156
- # 宣明暦は最大2つまで
157
- break if current_month.solar_term_size == 2
158
- end
159
- end
160
-
161
- #
162
- # 次の二十四節気に移る
163
- #
164
- def next_solar_term
165
- @solar_term.next_term!
166
- end
167
- end
168
- end
169
- end