zakuro 0.1.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  3. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  4. data/lib/zakuro/calculation/base/year.rb +107 -0
  5. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +484 -0
  6. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  7. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  8. data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +169 -0
  9. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  10. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  11. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  12. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  13. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  14. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  15. data/lib/zakuro/calculation/range/medieval_annual_range.rb +105 -0
  16. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  17. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  18. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  19. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  20. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  21. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +78 -0
  22. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +71 -0
  23. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +117 -0
  24. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +187 -0
  25. data/lib/zakuro/calculation/stella/solar/choukei_value.rb +136 -0
  26. data/lib/zakuro/calculation/summary/single.rb +129 -0
  27. data/lib/zakuro/calculation/type/old_float.rb +69 -0
  28. data/lib/zakuro/era/japan/reki.rb +1 -1
  29. data/lib/zakuro/merchant.rb +2 -2
  30. data/lib/zakuro/output/error.rb +7 -6
  31. data/lib/zakuro/output/logger.rb +50 -49
  32. data/lib/zakuro/output/response.rb +145 -144
  33. data/lib/zakuro/tools/typeof.rb +2 -2
  34. data/lib/zakuro/version.rb +1 -1
  35. data/lib/zakuro/version/abstract_version.rb +1 -1
  36. data/lib/zakuro/version/context.rb +23 -0
  37. data/lib/zakuro/version/daien/const/number.rb +55 -0
  38. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  39. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  40. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  41. data/lib/zakuro/version/daien/daien.rb +36 -0
  42. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  43. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  44. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  45. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  46. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  47. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  48. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  49. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  50. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  51. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  52. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  53. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  54. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  55. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  56. data/lib/zakuro/version/gihou/const/number.rb +55 -0
  57. data/lib/zakuro/version/gihou/const/remainder.rb +54 -0
  58. data/lib/zakuro/version/gihou/cycle/remainder.rb +56 -0
  59. data/lib/zakuro/version/gihou/cycle/solar_term.rb +34 -0
  60. data/lib/zakuro/version/gihou/gihou.rb +23 -2
  61. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +106 -0
  62. data/lib/zakuro/version/gihou/range/annual_range.rb +39 -0
  63. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +250 -0
  64. data/lib/zakuro/version/gihou/stella/lunar/localization.rb +44 -0
  65. data/lib/zakuro/version/gihou/stella/lunar/location.rb +80 -0
  66. data/lib/zakuro/version/gihou/stella/lunar/value.rb +75 -0
  67. data/lib/zakuro/version/gihou/stella/origin/average_november.rb +34 -0
  68. data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +62 -0
  69. data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +55 -0
  70. data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +93 -0
  71. data/lib/zakuro/version/gihou/stella/solar/average.rb +97 -0
  72. data/lib/zakuro/version/gihou/stella/solar/interval.rb +108 -0
  73. data/lib/zakuro/version/gihou/stella/solar/location.rb +61 -0
  74. data/lib/zakuro/version/gihou/stella/solar/value.rb +36 -0
  75. data/lib/zakuro/version/senmyou/const/number.rb +51 -0
  76. data/lib/zakuro/version/senmyou/const/remainder.rb +47 -0
  77. data/lib/zakuro/version/senmyou/cycle/remainder.rb +56 -0
  78. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +34 -0
  79. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +80 -195
  80. data/lib/zakuro/version/senmyou/range/annual_range.rb +25 -145
  81. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  82. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +237 -0
  83. data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +44 -0
  84. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +87 -0
  85. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +67 -0
  86. data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +34 -0
  87. data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +62 -0
  88. data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +55 -0
  89. data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +93 -0
  90. data/lib/zakuro/version/senmyou/stella/solar/average.rb +97 -0
  91. data/lib/zakuro/version/senmyou/stella/solar/interval.rb +103 -0
  92. data/lib/zakuro/version/senmyou/stella/solar/location.rb +61 -0
  93. data/lib/zakuro/version/senmyou/stella/solar/value.rb +39 -0
  94. data/lib/zakuro/version/version_class_resolver.rb +70 -0
  95. data/lib/zakuro/version_factory.rb +3 -3
  96. metadata +83 -28
  97. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  98. data/lib/zakuro/cycle/zodiac.rb +0 -103
  99. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  100. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  101. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  102. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  103. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -148
  104. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  105. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  106. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -119
  107. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  108. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  109. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -196
  110. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -194
  111. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  112. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  113. data/lib/zakuro/version/senmyou/range/western_date_allocation.rb +0 -68
  114. data/lib/zakuro/version/senmyou/range/year_boundary.rb +0 -138
  115. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  116. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +0 -332
  117. data/lib/zakuro/version/senmyou/stella/solar_average.rb +0 -169
  118. data/lib/zakuro/version/senmyou/stella/solar_location.rb +0 -213
  119. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +0 -213
  120. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +0 -106
  121. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
  122. data/lib/zakuro/version/taien/taien.rb +0 -19
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './operated_solar_terms'
4
+ require_relative '../../operation/operation'
5
+ require_relative '../../calculation/monthly/operated_month'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Calculation
11
+ # :nodoc:
12
+ module Range
13
+ #
14
+ # OperatedRange 運用結果範囲
15
+ #
16
+ # 何らかの理由により、計算された暦とは異なる運用結果である場合、その結果に合わせて計算結果を上書きする
17
+ class OperatedRange
18
+ # @return [Array<Year>] 年データ(完全範囲)
19
+ attr_reader :years
20
+ # @return [OperatedSolarTerms] 運用時二十四節気
21
+ attr_reader :operated_solar_terms
22
+ # @return [Context] 暦コンテキスト
23
+ attr_reader :context
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [Context] context 暦コンテキスト
29
+ # @param [Array<Year>] years 年データ(完全範囲)
30
+ #
31
+ def initialize(context:, years: [])
32
+ @context = context
33
+ @years = years
34
+ @operated_solar_terms = OperatedSolarTerms.new(context: context, years: @years)
35
+ @operated_solar_terms.create
36
+ end
37
+
38
+ #
39
+ # 運用結果範囲を取得する
40
+ #
41
+ # @return [Array<Year>] 運用結果範囲
42
+ #
43
+ def get
44
+ rewrite
45
+ end
46
+
47
+ #
48
+ # 運用結果に書き換える
49
+ #
50
+ # @return [Array<Year>] 運用結果範囲
51
+ #
52
+ def rewrite
53
+ operated_years = []
54
+
55
+ years.each do |year|
56
+ operated_year = OperatedRange.rewrite_year(
57
+ context: context, year: year,
58
+ operated_solar_terms: @operated_solar_terms
59
+ )
60
+ operated_years.push(operated_year)
61
+ end
62
+
63
+ operated_years
64
+ end
65
+
66
+ #
67
+ # 年を書き換える
68
+ #
69
+ # @param [Context] context 暦コンテキスト
70
+ # @param [Year] year 年
71
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
72
+ #
73
+ # @return [Year] 年
74
+ #
75
+ def self.rewrite_year(context:, year:, operated_solar_terms:)
76
+ result = Base::Year.new(
77
+ multi_gengou: year.multi_gengou, new_year_date: year.new_year_date
78
+ )
79
+ year.months.each do |month|
80
+ result.push(month: resolve_month(
81
+ context: context, month: month,
82
+ operated_solar_terms: operated_solar_terms
83
+ ))
84
+ end
85
+
86
+ result.commit
87
+
88
+ result
89
+ end
90
+
91
+ #
92
+ # 履歴情報の有無に応じた月にする
93
+ #
94
+ # @param [Context] context 暦コンテキスト
95
+ # @param [Month] month 月
96
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
97
+ #
98
+ # @return [Month] 月
99
+ #
100
+ def self.resolve_month(context:, month:, operated_solar_terms:)
101
+ history = Operation.specify_history(western_date: month.western_date)
102
+
103
+ return month if history.invalid?
104
+
105
+ OperatedRange.rewrite_month(
106
+ context: context, month: month, history: history,
107
+ operated_solar_terms: operated_solar_terms
108
+ )
109
+ end
110
+
111
+ # :reek:LongParameterList {max_params: 4}
112
+
113
+ #
114
+ # 月を運用結果に書き換える
115
+ #
116
+ # @param [Context] context 暦コンテキスト
117
+ # @param [Month] month 月
118
+ # @param [Operation::MonthHistory] history 変更履歴
119
+ # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
120
+ #
121
+ # @return [Month] 月(運用結果)
122
+ #
123
+ def self.rewrite_month(context:, month:, history:, operated_solar_terms:)
124
+ return month unless month.western_date == history.western_date
125
+
126
+ operated_month = Monthly::OperatedMonth.new(
127
+ context: context,
128
+ month_label: month.month_label, first_day: month.first_day,
129
+ solar_terms: month.solar_terms, history: history,
130
+ operated_solar_terms: operated_solar_terms
131
+ )
132
+
133
+ operated_month.rewrite
134
+
135
+ Monthly::Month.new(
136
+ context: context,
137
+ month_label: operated_month.month_label, first_day: operated_month.first_day,
138
+ solar_terms: operated_month.solar_terms
139
+ )
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,201 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../operation/operation'
4
+ require_relative '../monthly/month'
5
+
6
+ # TODO: solar_termの中はsrc/destだが、yamlはcalc/actual。統一したい。
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Calculation
12
+ # :nodoc:
13
+ module Range
14
+ #
15
+ # OperatedSolarTerm 運用時二十四節気
16
+ #
17
+ class OperatedSolarTerms
18
+ # @return [Array<Year>] 完全範囲(年データ)
19
+ attr_reader :years
20
+ # @return [Hash<String, SolarTerm>] 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
21
+ #
22
+ # * 移動元の二十四節気:無効な大余小余あり(削除対象)
23
+ # * 移動先の二十四節気:移動元からの二十四節気(追加対象)
24
+ #
25
+ attr_reader :directions
26
+ # @return [Context] 暦コンテキスト
27
+ attr_reader :context
28
+
29
+ #
30
+ # 初期化
31
+ #
32
+ # @param [Context] context 暦コンテキスト
33
+ # @param [Array<Year>] years 完全範囲(年データ)
34
+ #
35
+ def initialize(context:, years: [])
36
+ @context = context
37
+ @years = years
38
+ @directions = {}
39
+ end
40
+
41
+ #
42
+ # データ生成する
43
+ #
44
+ # @return [<Type>] <description>
45
+ #
46
+ def create
47
+ @directions = create_directions
48
+ end
49
+
50
+ #
51
+ # 二十四節気を取得する
52
+ #
53
+ # @param [Western::Calendar] western_date 月初日の西暦日
54
+ #
55
+ # @return [True] 対象あり
56
+ # @return [False] 対象なし
57
+ # @return [SolarTerm] 二十四節気
58
+ #
59
+ def get(western_date: Western::Calendar.new)
60
+ solar_term_class = context.resolver.solar_term
61
+ solar_term = @directions.fetch(western_date.format, solar_term_class.new)
62
+
63
+ # 合致しない場合
64
+ return false, solar_term_class.new if solar_term.empty?
65
+
66
+ # 合致した上で、二十四節気が移動元(削除対象)の場合
67
+ # 合致した上で、二十四節気が移動先(追加対象)の場合
68
+ [true, solar_term]
69
+ end
70
+
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
+ # :reek:TooManyStatements { max_statements: 6 }
89
+
90
+ #
91
+ # 年内の全ての月の移動方向を作成する
92
+ #
93
+ # @param [Context] context 暦コンテキスト
94
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
95
+ # @param [Array<Month>] months 年内の全ての月
96
+ #
97
+ def self.create_directions_with_months(context:, directions: {}, months: [])
98
+ months.each do |month|
99
+ history = Operation.specify_history(western_date: month.western_date)
100
+
101
+ next if history.invalid?
102
+
103
+ direction = history.diffs.solar_term
104
+
105
+ next if direction.invalid?
106
+
107
+ OperatedSolarTerms.create_directions_each_month(
108
+ context: context, directions: directions, direction: direction, month: month
109
+ )
110
+ end
111
+ end
112
+
113
+ # :reek:LongParameterList {max_params: 4}
114
+
115
+ #
116
+ # 月毎の移動方向を作成する
117
+ #
118
+ # @param [Context] context 暦コンテキスト
119
+ # @param [Month] 月
120
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
121
+ # @param [Operation::SolarTerm::Diretion] 二十四節気(移動)
122
+ #
123
+ def self.create_directions_each_month(context:, month:, directions: {},
124
+ direction: Operation::SolarTerm::Diretion.new)
125
+
126
+ month.solar_terms.each do |solar_term|
127
+ OperatedSolarTerms.push_source(context: context, directions: directions,
128
+ direction: direction, solar_term: solar_term)
129
+ end
130
+ OperatedSolarTerms.push_destination(context: context, directions: directions,
131
+ destination: direction.destination)
132
+ end
133
+
134
+ # :reek:LongParameterList {max_params: 4}
135
+
136
+ #
137
+ # 移動先に有効な二十四節気(差し替える二十四節気)を指定する
138
+ #
139
+ # @param [Context] context 暦コンテキスト
140
+ # @param [SolarTerm] solar_term 二十四節気(計算値)
141
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
142
+ # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
143
+ #
144
+ def self.push_source(context:, solar_term:, directions: {},
145
+ direction: Operation::SolarTerm::Direction.new)
146
+ source = direction.source
147
+
148
+ return if source.invalid?
149
+
150
+ return unless source.index == solar_term.index
151
+
152
+ # 移動先に移動元の二十四節気を指定する
153
+ directions[source.to.format] = OperatedSolarTerms.created_source(
154
+ context: context, direction: direction, solar_term: solar_term
155
+ )
156
+ end
157
+
158
+ #
159
+ # 移動先に有効な二十四節気(差し替える二十四節気)を生成する
160
+ #
161
+ # @param [Context] context 暦コンテキスト
162
+ # @param [SolarTerm] solar_term 二十四節気(計算値)
163
+ # @param [Operation::SolarTerm::Direction] source 二十四節気(移動)
164
+ #
165
+ # @return [SolarTerm] 二十四節気(運用値)
166
+ #
167
+ def self.created_source(context:, solar_term:,
168
+ direction: Operation::SolarTerm::Direction.new)
169
+ operated_solar_term = solar_term.clone
170
+ remainder_class_name = context.resolver.remainder
171
+
172
+ unless direction.invalid_days?
173
+ # 二十四節気の大余をずらす
174
+ operated_solar_term.remainder.add!(
175
+ remainder_class_name.new(day: direction.days, minute: 0, second: 0)
176
+ )
177
+ end
178
+
179
+ operated_solar_term
180
+ end
181
+
182
+ #
183
+ # 移動元に無効な二十四節気(連番のみ指定)を指定する
184
+ #
185
+ # @param [Context] context 暦コンテキスト
186
+ # @param [Hash<String, SolarTerm>] directions 二十四節気の移動元/移動先(西暦日 -> 対応する二十四節気)
187
+ # @param [Operation::SolarTerm::Destination] destination 二十四節気(移動先)
188
+ #
189
+ def self.push_destination(context:, directions: {},
190
+ destination: Operation::SolarTerm::Destination.new)
191
+ return if destination.invalid?
192
+
193
+ solar_term_class = context.resolver.solar_term
194
+ directions[destination.from.format] = solar_term_class.new(
195
+ index: destination.index
196
+ )
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Range
9
+ # :nodoc:
10
+ module Transfer
11
+ #
12
+ # WesternDateAllocation 西暦日の割り当て
13
+ #
14
+ module WesternDateAllocation
15
+ #
16
+ # 月初日の西暦日を更新する
17
+ #
18
+ # @param [Context] context 暦コンテキスト
19
+ # @param [Array<Year>] years 完全範囲(月初日なし)
20
+ #
21
+ # @return [Array<Year>] 完全範囲(月初日あり)
22
+ #
23
+ def self.get(context:, years:)
24
+ update_first_day(context: context, years: years)
25
+
26
+ years
27
+ end
28
+
29
+ #
30
+ # 月初日の西暦日を更新する
31
+ #
32
+ # @param [Context] context 暦コンテキスト
33
+ # @param [Array<Year>] years 完全範囲(月初日なし)
34
+ #
35
+ def self.update_first_day(context:, years:)
36
+ years.each_with_index do |year, index|
37
+ new_year_date = year.new_year_date.clone
38
+
39
+ months = year.months
40
+ update_first_day_within_all_months(
41
+ context: context,
42
+ new_year_date: new_year_date, months: months
43
+ )
44
+
45
+ years[index] = Base::Year.new(
46
+ multi_gengou: year.multi_gengou, new_year_date: new_year_date,
47
+ months: months, total_days: year.total_days
48
+ )
49
+ end
50
+ end
51
+
52
+ #
53
+ # 全ての月で月初日の西暦日を更新する
54
+ #
55
+ # @param [Context] context 暦コンテキスト
56
+ # @param [Western::Calendar] new_year_date 元旦
57
+ # @param [Array<Month>] months 月データ
58
+ #
59
+ def self.update_first_day_within_all_months(context:,
60
+ new_year_date:, months:)
61
+ date = new_year_date.clone
62
+ months.each_with_index do |month, index|
63
+ updated_month = Monthly::Month.new(
64
+ context: context,
65
+ month_label: month.month_label,
66
+ first_day: Monthly::FirstDay.new(
67
+ remainder: month.first_day.remainder,
68
+ western_date: date
69
+ ),
70
+ solar_terms: month.solar_terms
71
+ )
72
+ months[index] = updated_month
73
+
74
+ date = date.clone + updated_month.days
75
+ end
76
+ end
77
+ private_class_method :update_first_day_within_all_months
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/base/multi_gengou_roller'
4
+ require_relative '../../../calculation/base/year'
5
+
6
+ require_relative '../../../era/western'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Calculation
12
+ # :nodoc:
13
+ module Range
14
+ # :nodoc:
15
+ module Transfer
16
+ #
17
+ # YearBoundary 年境界
18
+ #
19
+ module YearBoundary
20
+ #
21
+ # 年間範囲内の年データの開始月を変更する
22
+ #
23
+ # @param [Context] context 暦コンテキスト
24
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
25
+ #
26
+ # @return [Array<Year>] 年データ(元旦基準)
27
+ #
28
+ def self.get(context:, annual_ranges:)
29
+ categorize(context: context, annual_ranges: annual_ranges)
30
+ rearranged_years(annual_ranges: annual_ranges)
31
+ end
32
+
33
+ #
34
+ # 年間範囲内の年データの開始月を変更する
35
+ #
36
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
37
+ #
38
+ # @return [Array<Year>] 年データ(元旦基準)
39
+ #
40
+ def self.rearranged_years(annual_ranges:)
41
+ years = []
42
+
43
+ (0..(annual_ranges.size - 2)).each do |index|
44
+ year = rearranged_year(annual_ranges: annual_ranges, index: index)
45
+ years.push(year)
46
+ end
47
+
48
+ years
49
+ end
50
+ private_class_method :rearranged_years
51
+
52
+ #
53
+ # 年間範囲を昨年/今年で分類する
54
+ #
55
+ # @param [Context] context 暦コンテキスト
56
+ # @param [Array<Year>] annual_range 1年データ
57
+ #
58
+ def self.categorize(context:, annual_ranges:)
59
+ annual_ranges.each do |annual_range|
60
+ categorize_year(context: context, annual_range: annual_range)
61
+ end
62
+ end
63
+ private_class_method :categorize
64
+
65
+ #
66
+ # 各月を昨年/今年で分類する
67
+ #
68
+ # @param [Context] context 暦コンテキスト
69
+ # @param [Array<Month>] annual_range 1年データ
70
+ #
71
+ def self.categorize_year(context:, annual_range:)
72
+ is_last_year = true
73
+ annual_range.each_with_index do |month, index|
74
+ is_last_year = false if month.number == 1
75
+
76
+ annual_range[index] = Monthly::InitializedMonth.new(
77
+ context: context,
78
+ month_label: month.month_label, first_day: month.first_day,
79
+ solar_terms: month.solar_terms, phase_index: month.phase_index,
80
+ is_last_year: is_last_year
81
+ )
82
+ end
83
+ end
84
+ private_class_method :categorize_year
85
+
86
+ #
87
+ # 年データの開始月を変更する
88
+ #
89
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
90
+ # @param [Integer] index 対象年の要素番号
91
+ #
92
+ # @return [Year] 年データ(元旦基準)
93
+ #
94
+ def self.rearranged_year(annual_ranges:, index:)
95
+ current_annual_range = annual_ranges[index]
96
+ next_annual_range = annual_ranges[index + 1]
97
+
98
+ year = push_current_year(annual_range: current_annual_range)
99
+ push_last_year(annual_range: next_annual_range, year: year)
100
+
101
+ year
102
+ end
103
+ private_class_method :rearranged_year
104
+
105
+ #
106
+ # 当年データを生成する
107
+ #
108
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
109
+ # @param [Year] year 対象年
110
+ #
111
+ # @return [Year] 当年月ありの対象年
112
+ #
113
+ def self.push_current_year(annual_range:, year: Base::Year.new)
114
+ annual_range.each do |month|
115
+ next if month.is_last_year
116
+
117
+ year.push(month: month)
118
+ end
119
+
120
+ year
121
+ end
122
+ private_class_method :push_current_year
123
+
124
+ #
125
+ # 昨年データを生成する
126
+ #
127
+ # @param [Array<Year>] annual_ranges 年データ(冬至基準)
128
+ # @param [Year] year 対象年
129
+ #
130
+ # @return [Year] 昨年月ありの対象年
131
+ #
132
+ def self.push_last_year(annual_range:, year: Base::Year.new)
133
+ annual_range.each do |month|
134
+ next unless month.is_last_year
135
+
136
+ year.push(month: month)
137
+ end
138
+
139
+ year
140
+ end
141
+ private_class_method :push_last_year
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end