zakuro 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +22 -7
  4. data/VERSION +1 -0
  5. data/doc/operation/transfer.rb +8 -8
  6. data/lib/zakuro/calculation/base/gengou.rb +128 -0
  7. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  8. data/lib/zakuro/calculation/base/operated_year.rb +5 -15
  9. data/lib/zakuro/calculation/base/year.rb +26 -14
  10. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
  11. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  12. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  13. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  14. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +41 -0
  23. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  24. data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
  25. data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
  26. data/lib/zakuro/calculation/era/version/version.rb +24 -0
  27. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  28. data/lib/zakuro/calculation/monthly/month.rb +88 -2
  29. data/lib/zakuro/calculation/monthly/operated_month.rb +3 -3
  30. data/lib/zakuro/calculation/range/abstract_full_range.rb +172 -0
  31. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +17 -15
  32. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  33. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  34. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  35. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  36. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -19
  37. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  38. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  39. data/lib/zakuro/calculation/summary/internal/month.rb +84 -0
  40. data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -37
  41. data/lib/zakuro/calculation/summary/japan/range.rb +152 -0
  42. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  43. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +91 -0
  44. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  45. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  46. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +169 -0
  47. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +93 -0
  48. data/lib/zakuro/condition.rb +15 -2
  49. data/lib/zakuro/era/japan/calendar.rb +133 -0
  50. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +121 -0
  51. data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
  52. data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
  53. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
  54. data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
  55. data/lib/zakuro/era/japan/gengou/resource/parser.rb +243 -0
  56. data/lib/zakuro/era/japan/gengou/resource/type.rb +293 -0
  57. data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
  58. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
  59. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
  60. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
  61. data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
  62. data/lib/zakuro/era/japan/gengou.rb +26 -80
  63. data/lib/zakuro/era/japan/version.rb +151 -0
  64. data/lib/zakuro/era/{western.rb → western/calendar.rb} +9 -9
  65. data/lib/zakuro/exception/case/pattern.rb +35 -0
  66. data/lib/zakuro/exception/case/preset.rb +51 -0
  67. data/lib/zakuro/exception/case/template.rb +48 -0
  68. data/lib/zakuro/exception/cause.rb +28 -0
  69. data/lib/zakuro/exception/exception.rb +37 -0
  70. data/lib/zakuro/exception/zakuro_error.rb +28 -0
  71. data/lib/zakuro/gateway/locale/date.rb +127 -0
  72. data/lib/zakuro/gateway/locale/range.rb +67 -0
  73. data/lib/zakuro/gateway/range.rb +99 -0
  74. data/lib/zakuro/gateway/single.rb +70 -0
  75. data/lib/zakuro/merchant.rb +15 -4
  76. data/lib/zakuro/operation/month/parser.rb +10 -10
  77. data/lib/zakuro/operation/month/type.rb +32 -32
  78. data/lib/zakuro/operation/month/validator.rb +51 -51
  79. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  80. data/lib/zakuro/output/logger.rb +17 -3
  81. data/lib/zakuro/output/response.rb +5 -5
  82. data/lib/zakuro/result/data/day.rb +43 -0
  83. data/lib/zakuro/result/data/gengou.rb +35 -0
  84. data/lib/zakuro/result/data/month.rb +63 -0
  85. data/lib/zakuro/result/data/single_day.rb +48 -0
  86. data/lib/zakuro/result/data/solar_term.rb +35 -0
  87. data/lib/zakuro/result/data/year.rb +45 -0
  88. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  89. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  90. data/lib/zakuro/result/operation/month/history.rb +54 -0
  91. data/lib/zakuro/result/operation/operation.rb +44 -0
  92. data/lib/zakuro/result/result.rb +21 -2
  93. data/lib/zakuro/tools/typeconv.rb +38 -0
  94. data/lib/zakuro/tools/typeof.rb +4 -1
  95. data/lib/zakuro/version/context.rb +24 -3
  96. data/lib/zakuro/version/daien/daien.rb +1 -26
  97. data/lib/zakuro/version/genka/genka.rb +1 -26
  98. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  99. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  100. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  101. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  102. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  103. data/lib/zakuro/version/senmyou/README.md +11 -7
  104. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  105. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  106. data/zakuro.gemspec +1 -3
  107. metadata +74 -22
  108. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  109. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  110. data/lib/zakuro/calculation/range/full_range.rb +0 -210
  111. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  112. data/lib/zakuro/calculation/specifier/single_day.rb +0 -109
  113. data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
  114. data/lib/zakuro/era/japan/gengou/type.rb +0 -178
  115. data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
  116. data/lib/zakuro/era/japan/reki.rb +0 -91
  117. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  118. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  119. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  120. data/lib/zakuro/result/data.rb +0 -187
  121. data/lib/zakuro/result/operation.rb +0 -114
  122. data/lib/zakuro/version/abstract_version.rb +0 -29
  123. data/lib/zakuro/version.rb +0 -7
  124. data/lib/zakuro/version_factory.rb +0 -59
@@ -1,218 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './multi_gengou'
4
-
5
- require_relative '../../era/japan/gengou'
6
-
7
- # :nodoc:
8
- module Zakuro
9
- # :nodoc:
10
- module Calculation
11
- # :nodoc:
12
- module Base
13
- #
14
- # MultiGengouRoller 改元処理
15
- #
16
- class MultiGengouRoller
17
- # @return [MultiGengou] 複数元号
18
- attr_reader :multi_gengou
19
- # @return [Western::Calendar] 元旦(元号が2つある場合は再過去の日付になる)
20
- attr_reader :oldest_date
21
- # @return [Western::Calendar] 元号内での最未来日(元号が2つある場合は再未来の日付になる)
22
- attr_reader :newest_date
23
- # @return [Western::Calendar] 現在日
24
- attr_reader :current_date
25
-
26
- def initialize(start_date: Western::Calendar.new, end_date: Western::Calendar.new)
27
- end_date = start_date if end_date.invalid?
28
-
29
- @oldest_date = MultiGengouRoller.choise_oldest_gengou_date(
30
- first_line: MultiGengouRoller.first_line(date: start_date),
31
- second_line: MultiGengouRoller.second_line(date: start_date)
32
- )
33
- @current_date = @oldest_date.clone
34
- @newest_date = MultiGengouRoller.choise_newest_gengou_date(
35
- first_line: MultiGengouRoller.first_line(date: end_date),
36
- second_line: MultiGengouRoller.second_line(date: end_date)
37
- )
38
-
39
- @multi_gengou = MultiGengou.new(
40
- first_line: current_first_line,
41
- second_line: current_second_line,
42
- new_year_date: @oldest_date
43
- )
44
- end
45
-
46
- #
47
- # 現在日付を未来に進める
48
- #
49
- # @param [<Type>] days <description>
50
- #
51
- # @return [<Type>] <description>
52
- #
53
- def next(days: 0)
54
- @current_date += days
55
- end
56
-
57
- #
58
- # 現在日から元号(1行目)を取得する
59
- #
60
- # @return [Japan::Gengou] 元号(1行目)
61
- #
62
- def current_first_line
63
- MultiGengouRoller.first_line(date: @current_date)
64
- end
65
-
66
- #
67
- # 現在日から元号(2行目)を取得する
68
- #
69
- # @return [Japan::Gengou] 元号(2行目)
70
- #
71
- def current_second_line
72
- MultiGengouRoller.second_line(date: @current_date)
73
- end
74
-
75
- #
76
- # 改元する
77
- #
78
- # @return [MultiGengou] 複数元号
79
- #
80
- def transfer
81
- MultiGengouRoller.transfer(multi_gengou: @multi_gengou, date: @current_date)
82
- end
83
-
84
- #
85
- # 次年にする
86
- #
87
- # @return [MultiGengou] 複数元号
88
- #
89
- def next_year
90
- @multi_gengou.next_year
91
- end
92
-
93
- #
94
- # 元号(1行目)を取得する
95
- #
96
- # @return [Japan::Gengou] 元号(1行目)
97
- #
98
- def self.first_line(date: Western::Calender.new)
99
- Japan::GengouResource.first_line(date: date)
100
- end
101
-
102
- #
103
- # 元号(2行目)を取得する
104
- #
105
- # @return [Japan::Gengou] 元号(2行目)
106
- #
107
- def self.second_line(date: Western::Calender.new)
108
- Japan::GengouResource.second_line(date: date)
109
- end
110
-
111
- #
112
- # 改元する
113
- #
114
- # @param [MultiGengou] multi_gengou 複数元号
115
- # @param [Western::Calendar] date 対象日
116
- #
117
- # @return [MultiGengou] 改元済み複数元号
118
- #
119
- def self.transfer(multi_gengou:, date:)
120
- multi_gengou.transfer(
121
- first_line: first_line(date: date),
122
- second_line: second_line(date: date)
123
- )
124
-
125
- multi_gengou
126
- end
127
-
128
- #
129
- # 現在日からみて直近の未来に対する元号の切替前日を求める
130
- # @note 2つの元号が重複した場合はより過去の日となる
131
- #
132
- # @param [Japan::Gengou] first_line 元号(1行目)
133
- # @param [Japan::Gengou] second_line 元号(2行目)
134
- #
135
- # @return [Western::Calendar] 元号の切替前日
136
- #
137
- def choise_nearest_end_date
138
- condition = lambda do |first_date, second_date|
139
- first_date < second_date ? first_date : second_date
140
- end
141
-
142
- second_line = current_second_line
143
-
144
- MultiGengouRoller.choise_date(condition: condition, second_line: second_line,
145
- first_date: current_first_line.end_date.clone,
146
- second_date: second_line.end_date.clone)
147
- end
148
-
149
- #
150
- # 最過去の元旦を求める
151
- # @note 2つの元号が重複した場合はより過去の日となる
152
- #
153
- # @param [Japan::Gengou] first_line 元号(1行目)
154
- # @param [Japan::Gengou] second_line 元号(2行目)
155
- #
156
- # @return [Western::Calendar] 最過去の元旦
157
- #
158
- def self.choise_oldest_gengou_date(first_line:, second_line:)
159
- condition = lambda do |first_date, second_date|
160
- first_date < second_date ? first_date : second_date
161
- end
162
- choise_date(condition: condition, second_line: second_line,
163
- first_date: first_line.new_year_date.clone,
164
- second_date: second_line.new_year_date.clone)
165
- end
166
-
167
- #
168
- # 元号内での最未来日を求める
169
- # @note 2つの元号が重複した場合はより未来の日となる
170
- #
171
- # @param [Japan::Gengou] first_line 元号(1行目)
172
- # @param [Japan::Gengou] second_line 元号(2行目)
173
- #
174
- # @return [Western::Calendar] 最未来日
175
- #
176
- def self.choise_newest_gengou_date(first_line:, second_line:)
177
- condition = lambda do |first_date, second_date|
178
- first_date > second_date ? first_date : second_date
179
- end
180
- choise_date(condition: condition, second_line: second_line,
181
- first_date: first_line.end_date.clone,
182
- second_date: second_line.end_date.clone)
183
- end
184
-
185
- # :reek:LongParameterList {max_params: 4}
186
-
187
- #
188
- # 条件を元に日付を求める
189
- #
190
- # @param [Proc] condition 比較条件
191
- # @param [Japan::Gengou] second_line 元号(2行目)
192
- # @param [Western::Calendar] first_date 比較対象(1行目)
193
- # @param [Western::Calendar] second_date 比較対象(2行目)
194
- #
195
- # @return [Western::Calendar] 比較結果
196
- #
197
- def self.choise_date(condition:, second_line:, first_date:, second_date:)
198
- # first_lineは常に存在する
199
- return first_date if second_line.invalid?
200
-
201
- condition.call(first_date, second_date)
202
- end
203
-
204
- #
205
- # ディープコピー
206
- #
207
- # @param [MultiGengou] obj 自身
208
- #
209
- def initialize_copy(obj)
210
- @oldest_date = obj.oldest_date.clone
211
- @current_date = obj.current_date.clone
212
- @newest_date = obj.newest_date.clone
213
- @multi_gengou = obj.multi_gengou.clone
214
- end
215
- end
216
- end
217
- end
218
- end
@@ -1,210 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../era/western'
4
- require_relative '../../output/logger'
5
-
6
- require_relative '../base/multi_gengou_roller'
7
- require_relative '../base/year'
8
-
9
- require_relative './transfer/year_boundary'
10
- require_relative './transfer/western_date_allocation'
11
-
12
- # :nodoc:
13
- module Zakuro
14
- # :nodoc:
15
- module Calculation
16
- # :nodoc:
17
- module Range
18
- # :reek:TooManyInstanceVariables { max_instance_variables: 6 }
19
-
20
- #
21
- # FullRange 完全範囲
22
- # ある日からある日の範囲を計算可能な年月範囲
23
- # * 前提として元号年はその元号の開始年から数える
24
- # * ある日の元号年を求める場合、その元号が含まれる最初の年まで遡る
25
- # * 元号は一つとは限らない。南北朝などで二つある場合は、古い方の元号から求める
26
- #
27
- # NOTE: 割り当てた元号は年初を基準にした元号年である
28
- # * 元旦を基準にした時の正しい元号を設定している
29
- # * 引き当てたい日付が元旦ではない場合、その月日に従い元号を再度求める
30
- # * この再計算が必要になるのは、元号が切り替わる年のみである
31
- #
32
- class FullRange
33
- # @return [Context] 暦コンテキスト
34
- attr_reader :context
35
- # @return [Western::Calendar] 開始日
36
- attr_reader :start_date
37
- # @return [Western::Calendar] 終了日
38
- attr_reader :end_date
39
- # @return [MultiGengouRoller] 改元処理
40
- attr_reader :multi_gengou_roller
41
- # @return [Western::Calendar] 最過去の元旦
42
- attr_reader :new_year_date
43
- # @return [Integer] 西暦年
44
- attr_reader :western_year
45
-
46
- # @return [Output::Logger] ロガー
47
- LOGGER = Output::Logger.new(location: 'full_range')
48
-
49
- #
50
- # 初期化
51
- #
52
- # @param [Context] context 暦コンテキスト
53
- # @param [Western::Calendar] start_date 開始日
54
- # @param [Western::Calendar] end_date 終了日
55
- #
56
- def initialize(context:, start_date: Western::Calendar.new, end_date: Western::Calendar.new)
57
- @start_date = start_date
58
- @end_date = end_date
59
- return if invalid?
60
-
61
- @context = context
62
- @multi_gengou_roller = Base::MultiGengouRoller.new(
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
67
- end
68
-
69
- #
70
- # 無効か
71
- #
72
- # @return [True] 無効
73
- # @return [False] 有効
74
- #
75
- def invalid?
76
- @start_date.invalid?
77
- end
78
-
79
- #
80
- # 完全範囲を取得する
81
- #
82
- # @return [Array<Year>] 完全範囲
83
- #
84
- def get
85
- return [] if invalid?
86
-
87
- years = Transfer::YearBoundary.get(
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
98
-
99
- # :reek:TooManyStatements { max_statements: 7 }
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
110
-
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
119
-
120
- years
121
- end
122
-
123
- # :reek:TooManyStatements { max_statements: 8 }
124
-
125
- #
126
- # 完全範囲内の年データの元号を開始年基準で更新する
127
- #
128
- # @param [Array<Year>] years 年データ(元旦基準)
129
- #
130
- # @return [Array<Year>] 元号更新済み年データ(元旦基準)
131
- #
132
- def update_gengou(years:)
133
- updated_years = []
134
-
135
- nearest_end_date = choise_nearest_end_date
136
-
137
- years.each do |year|
138
- next_year(years: updated_years, year: year)
139
-
140
- if @new_year_date > nearest_end_date
141
- @multi_gengou_roller.transfer
142
- nearest_end_date = choise_nearest_end_date
143
- end
144
- @multi_gengou_roller.next_year
145
- end
146
-
147
- updated_years
148
- end
149
-
150
- private
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)
164
-
165
- nil
166
- end
167
-
168
- #
169
- # 年の元号を更新する
170
- #
171
- # @param [Year] year 元号処理前の年(元旦基準)
172
- #
173
- # @return [Year] 元号処理済の年(元旦基準)
174
- #
175
- def update_year(year:)
176
- multi_gengou = @multi_gengou_roller.multi_gengou.clone
177
-
178
- updated_year = Base::Year.new(
179
- multi_gengou: multi_gengou, new_year_date: @new_year_date.clone,
180
- months: year.months
181
- )
182
- updated_year.commit
183
-
184
- updated_year
185
- end
186
-
187
- #
188
- # 次の年に進める
189
- #
190
- # @param [Integer] total_days 年の日数
191
- #
192
- def next_new_year_date(total_days:)
193
- @new_year_date += total_days
194
- @multi_gengou_roller.next(days: total_days)
195
-
196
- nil
197
- end
198
-
199
- #
200
- # 現在日からみて直近の未来に対する元号の切替前日を求める
201
- #
202
- # @return [Western::Calendar] 元号の切替前日
203
- #
204
- def choise_nearest_end_date
205
- @multi_gengou_roller.choise_nearest_end_date
206
- end
207
- end
208
- end
209
- end
210
- end
@@ -1,82 +0,0 @@
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
@@ -1,109 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../base/multi_gengou_roller'
4
- require_relative '../base/year'
5
-
6
- require_relative '../../era/western'
7
- require_relative '../../output/response'
8
- require_relative '../../output/logger'
9
-
10
- # :nodoc:
11
- module Zakuro
12
- # :nodoc:
13
- module Calculation
14
- # :nodoc:
15
- module Specifier
16
- #
17
- # SingleDay 一日検索
18
- #
19
- module SingleDay
20
- # @return [Output::Logger] ロガー
21
- LOGGER = Output::Logger.new(location: 'specifier')
22
-
23
- #
24
- # 取得する
25
- #
26
- # @param [Array<Year>] yeas 範囲
27
- # @param [Western::Calendar] date 西暦日
28
- #
29
- # @return [Result::Data::SingleDay] 和暦日
30
- #
31
- def self.get(years: [], date: Western::Calendar.new)
32
- year = specify_year(years: years, date: date)
33
-
34
- year = transfer(year: year, date: date)
35
-
36
- month = specify_month(year: year, date: date)
37
- first_date = month.western_date
38
-
39
- Output::Response::SingleDay.save_single_day(
40
- param: Output::Response::SingleDay::Param.new(
41
- year: year, month: month,
42
- date: date, days: date - first_date
43
- )
44
- )
45
- end
46
-
47
- #
48
- # 年を特定する
49
- #
50
- # @param [Array<Year>] years 範囲
51
- # @param [Western::Calendar] date 西暦日
52
- #
53
- # @return [Year] 対象年
54
- #
55
- def self.specify_year(years:, date:)
56
- years.reverse_each do |year|
57
- return year if date >= year.new_year_date
58
- end
59
-
60
- raise ArgumentError, "invalid year range. date: #{date.format}"
61
- end
62
- private_class_method :specify_year
63
-
64
- #
65
- # 改元する
66
- #
67
- # @param [Year] year 年
68
- # @param [Western::Calendar] date 西暦日
69
- #
70
- # @return [Year] 改元後の年
71
- #
72
- def self.transfer(year:, date:)
73
- multi_gengou = Calculation::Base::MultiGengouRoller.transfer(
74
- multi_gengou: year.multi_gengou, date: date
75
- )
76
- Calculation::Base::Year.new(
77
- multi_gengou: multi_gengou, new_year_date: year.new_year_date,
78
- months: year.months, total_days: year.total_days
79
- )
80
- end
81
- private_class_method :transfer
82
-
83
- # :reek:TooManyStatements { max_statements: 7 }
84
-
85
- #
86
- # 月を特定する
87
- #
88
- # @param [Year] year 年
89
- # @param [Western::Calendar] date 西暦日
90
- #
91
- # @return [Month] 対象月
92
- #
93
- def self.specify_month(year:, date:)
94
- months = year.months
95
-
96
- current_month = months[0]
97
- months.each do |month|
98
- return current_month if month.western_date > date
99
-
100
- current_month = month
101
- end
102
-
103
- current_month
104
- end
105
- private_class_method :specify_month
106
- end
107
- end
108
- end
109
- end