zakuro 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -1
  3. data/VERSION +1 -0
  4. data/doc/gengou.md +22 -22
  5. data/doc/operation/csv/month.csv +468 -202
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/lib/zakuro/calculation/base/gengou.rb +82 -0
  8. data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
  9. data/lib/zakuro/calculation/base/operated_year.rb +104 -0
  10. data/lib/zakuro/calculation/base/year.rb +28 -13
  11. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
  12. data/lib/zakuro/calculation/gengou/internal/counter.rb +129 -0
  13. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
  14. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
  15. data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
  16. data/lib/zakuro/calculation/gengou/scroll.rb +262 -0
  17. data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
  18. data/lib/zakuro/calculation/monthly/month.rb +49 -2
  19. data/lib/zakuro/calculation/monthly/operated_month.rb +49 -5
  20. data/lib/zakuro/calculation/range/full_range.rb +65 -103
  21. data/lib/zakuro/calculation/range/operated_range.rb +73 -23
  22. data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
  23. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
  24. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
  25. data/lib/zakuro/calculation/specifier/single_day.rb +13 -35
  26. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +9 -7
  27. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +19 -0
  28. data/lib/zakuro/calculation/summary/single.rb +5 -2
  29. data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
  30. data/lib/zakuro/calculation/version/internal/range.rb +39 -0
  31. data/lib/zakuro/calculation/version/version.rb +24 -0
  32. data/lib/zakuro/era/japan/calendar.rb +133 -0
  33. data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
  34. data/lib/zakuro/era/japan/gengou/type.rb +148 -41
  35. data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
  36. data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
  37. data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
  38. data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
  39. data/lib/zakuro/era/japan/gengou.rb +5 -5
  40. data/lib/zakuro/era/japan/version.rb +151 -0
  41. data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
  42. data/lib/zakuro/merchant.rb +12 -3
  43. data/lib/zakuro/operation/month/parser.rb +1 -1
  44. data/lib/zakuro/operation/month/type.rb +59 -1
  45. data/lib/zakuro/operation/month/validator.rb +1 -1
  46. data/lib/zakuro/operation/yaml/month.yaml +8512 -0
  47. data/lib/zakuro/output/response.rb +5 -5
  48. data/lib/zakuro/tools/typeconv.rb +38 -0
  49. data/lib/zakuro/tools/typeof.rb +4 -1
  50. data/lib/zakuro/version/context.rb +25 -4
  51. data/lib/zakuro/version/daien/const/number.rb +55 -0
  52. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  53. data/lib/zakuro/version/daien/cycle/remainder.rb +85 -0
  54. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  55. data/lib/zakuro/version/daien/daien.rb +11 -0
  56. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  57. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  58. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  59. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  60. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  61. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  62. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  63. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  64. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  65. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  66. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  67. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  68. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  69. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  70. data/lib/zakuro/version/genka/const/number.rb +43 -0
  71. data/lib/zakuro/version/genka/const/remainder.rb +33 -0
  72. data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
  73. data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
  74. data/lib/zakuro/version/genka/genka.rb +1 -9
  75. data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
  76. data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
  77. data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
  78. data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
  79. data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
  80. data/lib/zakuro/version/gihou/const/remainder.rb +0 -2
  81. data/lib/zakuro/version/gihou/cycle/remainder.rb +27 -6
  82. data/lib/zakuro/version/gihou/gihou.rb +1 -30
  83. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +1 -1
  84. data/lib/zakuro/version/gihou/stella/lunar/location.rb +2 -8
  85. data/lib/zakuro/version/gihou/stella/lunar/value.rb +3 -2
  86. data/lib/zakuro/version/gihou/stella/solar/average.rb +3 -3
  87. data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
  88. data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
  89. data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
  90. data/lib/zakuro/version/kansei/kansei.rb +1 -9
  91. data/lib/zakuro/version/senmyou/const/remainder.rb +0 -2
  92. data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
  93. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
  94. data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
  95. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +2 -8
  96. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +3 -2
  97. data/lib/zakuro/version/senmyou/stella/solar/average.rb +3 -3
  98. data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
  99. data/lib/zakuro/version/version_class_resolver.rb +8 -0
  100. data/zakuro.gemspec +1 -3
  101. metadata +50 -14
  102. data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
  103. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
  104. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
  105. data/lib/zakuro/era/japan/reki.rb +0 -91
  106. data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
  107. data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
  108. data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
  109. data/lib/zakuro/version/abstract_version.rb +0 -29
  110. data/lib/zakuro/version/taien/taien.rb +0 -19
  111. data/lib/zakuro/version.rb +0 -7
  112. data/lib/zakuro/version_factory.rb +0 -59
@@ -2,7 +2,9 @@
2
2
 
3
3
  require_relative './operated_solar_terms'
4
4
  require_relative '../../operation/operation'
5
+ require_relative '../base/operated_year'
5
6
  require_relative '../../calculation/monthly/operated_month'
7
+ require_relative './transfer/gengou_scroller'
6
8
 
7
9
  # :nodoc:
8
10
  module Zakuro
@@ -26,11 +28,15 @@ module Zakuro
26
28
  # 初期化
27
29
  #
28
30
  # @param [Context] context 暦コンテキスト
31
+ # @param [Western::Calendar] start_date 開始日
32
+ # @param [Western::Calendar] end_date 終了日
29
33
  # @param [Array<Year>] years 年データ(完全範囲)
30
34
  #
31
- def initialize(context:, years: [])
35
+ def initialize(context:, start_date: Western::Calendar.new, end_date: Western::Calendar.new,
36
+ years: [])
32
37
  @context = context
33
38
  @years = years
39
+ @scroll = Gengou::Scroll.new(start_date: start_date, end_date: end_date)
34
40
  @operated_solar_terms = OperatedSolarTerms.new(context: context, years: @years)
35
41
  @operated_solar_terms.create
36
42
  end
@@ -41,20 +47,28 @@ module Zakuro
41
47
  # @return [Array<Year>] 運用結果範囲
42
48
  #
43
49
  def get
44
- rewrite
50
+ operated_years = rewrite
51
+
52
+ OperatedRange.move(operated_years: operated_years)
53
+
54
+ OperatedRange.commit(operated_years: operated_years)
55
+
56
+ Transfer::GengouScroller.set(scroll: @scroll, years: operated_years)
57
+
58
+ operated_years
45
59
  end
46
60
 
47
61
  #
48
62
  # 運用結果に書き換える
49
63
  #
50
- # @return [Array<Year>] 運用結果範囲
64
+ # @return [Array<OperatedYear>] 運用結果範囲
51
65
  #
52
66
  def rewrite
53
67
  operated_years = []
54
68
 
55
69
  years.each do |year|
56
70
  operated_year = OperatedRange.rewrite_year(
57
- context: context, year: year,
71
+ year: year,
58
72
  operated_solar_terms: @operated_solar_terms
59
73
  )
60
74
  operated_years.push(operated_year)
@@ -63,19 +77,65 @@ module Zakuro
63
77
  operated_years
64
78
  end
65
79
 
80
+ #
81
+ # 運用情報で年を跨ぐ月をその年に寄せる
82
+ #
83
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
84
+ #
85
+ def self.move(operated_years:)
86
+ # FIXME: この方式は完全ではない。範囲の1年前/1年後が必要
87
+ move_into_next_year(operated_years: operated_years)
88
+ move_into_last_year(operated_years: operated_years)
89
+ end
90
+
91
+ #
92
+ # 運用情報では来年に属する月を来年に寄せる
93
+ #
94
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
95
+ #
96
+ def self.move_into_next_year(operated_years:)
97
+ operated_years.each_cons(2) do |current_year, next_year|
98
+ months = current_year.pop_next_year_months
99
+
100
+ next_year.unshift_months(months)
101
+ end
102
+ end
103
+
104
+ #
105
+ # 運用情報では昨年に属する月を昨年に寄せる
106
+ #
107
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
108
+ #
109
+ def self.move_into_last_year(operated_years:)
110
+ rerversed_year = operated_years.reverse!
111
+ rerversed_year.each_cons(2) do |current_year, last_year|
112
+ months = current_year.shift_last_year_months
113
+ last_year.push_months(months)
114
+ end
115
+
116
+ rerversed_year.reverse!
117
+ end
118
+
119
+ #
120
+ # 年を確定させる
121
+ #
122
+ # @param [Array<OperatedYear>] operated_years 運用結果範囲
123
+ #
124
+ def self.commit(operated_years:)
125
+ operated_years.each(&:commit)
126
+ end
127
+
66
128
  #
67
129
  # 年を書き換える
68
130
  #
69
- # @param [Context] context 暦コンテキスト
70
131
  # @param [Year] year 年
71
132
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
72
133
  #
73
- # @return [Year] 年
134
+ # @return [OperatedYear] 年
74
135
  #
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
- )
136
+ def self.rewrite_year(year:, operated_solar_terms:)
137
+ context = year.context
138
+ result = Base::OperatedYear.new(context: context)
79
139
  year.months.each do |month|
80
140
  result.push(month: resolve_month(
81
141
  context: context, month: month,
@@ -83,8 +143,6 @@ module Zakuro
83
143
  ))
84
144
  end
85
145
 
86
- result.commit
87
-
88
146
  result
89
147
  end
90
148
 
@@ -100,8 +158,6 @@ module Zakuro
100
158
  def self.resolve_month(context:, month:, operated_solar_terms:)
101
159
  history = Operation.specify_history(western_date: month.western_date)
102
160
 
103
- return month if history.invalid?
104
-
105
161
  OperatedRange.rewrite_month(
106
162
  context: context, month: month, history: history,
107
163
  operated_solar_terms: operated_solar_terms
@@ -121,22 +177,16 @@ module Zakuro
121
177
  # @return [Month] 月(運用結果)
122
178
  #
123
179
  def self.rewrite_month(context:, month:, history:, operated_solar_terms:)
124
- return month unless month.western_date == history.western_date
125
-
126
180
  operated_month = Monthly::OperatedMonth.new(
127
181
  context: context,
128
182
  month_label: month.month_label, first_day: month.first_day,
129
- solar_terms: month.solar_terms, history: history,
183
+ solar_terms: month.solar_terms, history: history, gengou: month.gengou,
130
184
  operated_solar_terms: operated_solar_terms
131
185
  )
132
186
 
133
- operated_month.rewrite
187
+ operated_month.rewrite unless history.invalid?
134
188
 
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
- )
189
+ operated_month
140
190
  end
141
191
  end
142
192
  end
@@ -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 [Array<Year>] annual_ranges 年データ(冬至基準)
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(annual_ranges: annual_ranges, index: index)
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 [Array<Year>] annual_ranges 年データ(冬至基準)
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 [Array<Year>] annual_ranges 年データ(冬至基準)
109
- # @param [Year] year 対象年
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(annual_range:, year: Base::Year.new)
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<Year>] annual_ranges 年データ(冬至基準)
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|
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../base/multi_gengou_roller'
4
3
  require_relative '../base/year'
5
4
 
6
- require_relative '../../era/western'
5
+ require_relative '../../era/western/calendar'
7
6
  require_relative '../../output/response'
8
7
  require_relative '../../output/logger'
9
8
 
@@ -29,11 +28,7 @@ module Zakuro
29
28
  # @return [Result::Data::SingleDay] 和暦日
30
29
  #
31
30
  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)
31
+ year, month = specify(years: years, date: date)
37
32
  first_date = month.western_date
38
33
 
39
34
  Output::Response::SingleDay.save_single_day(
@@ -50,35 +45,18 @@ module Zakuro
50
45
  # @param [Array<Year>] years 範囲
51
46
  # @param [Western::Calendar] date 西暦日
52
47
  #
53
- # @return [Year] 対象年
48
+ # @return [Base::Year] 対象年
49
+ # @return [Base::Month] 対象月
54
50
  #
55
- def self.specify_year(years:, date:)
56
- years.reverse_each do |year|
57
- return year if date >= year.new_year_date
51
+ def self.specify(years:, date:)
52
+ years.each do |year|
53
+ month = specify_month(year: year, date: date)
54
+ return year, month unless month.invalid?
58
55
  end
59
56
 
60
57
  raise ArgumentError, "invalid year range. date: #{date.format}"
61
58
  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
59
+ private_class_method :specify
82
60
 
83
61
  # :reek:TooManyStatements { max_statements: 7 }
84
62
 
@@ -93,14 +71,14 @@ module Zakuro
93
71
  def self.specify_month(year:, date:)
94
72
  months = year.months
95
73
 
96
- current_month = months[0]
97
74
  months.each do |month|
98
- return current_month if month.western_date > date
75
+ western_date = month.western_date
76
+ next if western_date.invalid?
99
77
 
100
- current_month = month
78
+ return month if month.include?(date: date)
101
79
  end
102
80
 
103
- current_month
81
+ Monthly::Month.new
104
82
  end
105
83
  private_class_method :specify_month
106
84
  end
@@ -46,6 +46,15 @@ module Zakuro
46
46
  # abstract
47
47
  end
48
48
 
49
+ #
50
+ # 1始まりの大余小余を取得する
51
+ #
52
+ # @return [Cycle::AbstractRemainder] 1始まりの大余小余
53
+ #
54
+ def adjusted_remainder
55
+ @remainder.add(Cycle::AbstractRemainder.new(day: 1, minute: 0, second: 0))
56
+ end
57
+
49
58
  private
50
59
 
51
60
  #
@@ -63,13 +72,6 @@ module Zakuro
63
72
  def decrease(limit:)
64
73
  # abstract
65
74
  end
66
-
67
- #
68
- # 1始まりにする
69
- #
70
- def one_based
71
- @remainder.add!(Cycle::AbstractRemainder.new(day: 1, minute: 0, second: 0))
72
- end
73
75
  end
74
76
  end
75
77
  end
@@ -30,6 +30,25 @@ module Zakuro
30
30
  day
31
31
  end
32
32
 
33
+ #
34
+ # 秒がない大余小余にする
35
+ #
36
+ # @param [Cycle::LunarRemainder] remainder 大余小余
37
+ #
38
+ # @note 815年で大余繰り上げあり
39
+ #
40
+ # @return [Integer] 大余
41
+ # @return [Float] 小余
42
+ #
43
+ def self.remainder_without_second(remainder:)
44
+ adjusted = remainder.class.new(
45
+ day: remainder.day, minute: remainder.floor_minute, second: 0
46
+ )
47
+ adjusted.carry!
48
+
49
+ [adjusted.day, adjusted.minute]
50
+ end
51
+
33
52
  def self.day_only(remainder_minute:, denominator:)
34
53
  float_day = Type::OldFloat.new(remainder_minute / denominator)
35
54
  # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
@@ -32,11 +32,14 @@ module Zakuro
32
32
  years: years, date: date
33
33
  )
34
34
 
35
- operated_range = Calculation::Range::OperatedRange.new(context: context, years: years)
35
+ operated_range = Calculation::Range::OperatedRange.new(
36
+ context: context, start_date: date, years: years
37
+ )
38
+ operated_years = operated_range.get
36
39
 
37
40
  Result::Single.new(
38
41
  data: Calculation::Specifier::SingleDay.get(
39
- years: operated_range.get, date: date
42
+ years: operated_years, date: date
40
43
  ),
41
44
  operation: create_operation(calc_date: calc_date)
42
45
  )
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../era/japan/version'
4
+ require_relative './range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Version
12
+ #
13
+ # 暦検索
14
+ #
15
+ module Crawler
16
+ #
17
+ # 暦の範囲を取得する
18
+ #
19
+ # @param [Integer] start_year 開始西暦年
20
+ # @param [Integer] end_year 終了西暦年
21
+ #
22
+ # @return [Array<Range>] 暦の範囲
23
+ #
24
+ def self.get(start_year:, end_year:)
25
+ ranges = Japan::Version.ranges_with_year(start_year: start_year, end_year: end_year)
26
+
27
+ result = []
28
+
29
+ ranges.each do |range|
30
+ next unless range.released
31
+
32
+ range_start_year = range.start_year
33
+ range_start_year = start_year if start_year > range.start_year
34
+
35
+ range_end_year = range.end_year
36
+ range_end_year = end_year if end_year < range.end_year
37
+
38
+ result.push(
39
+ Range.new(
40
+ name: range.name, start_date: range.start_date.clone,
41
+ start_year: range_start_year, end_year: range_end_year
42
+ )
43
+ )
44
+ end
45
+
46
+ result
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Version
9
+ #
10
+ # Range 暦(範囲)
11
+ #
12
+ class Range
13
+ # @return [String] 暦名
14
+ attr_reader :name
15
+ # @return [Western::Calendar] 暦の開始日
16
+ attr_reader :start_date
17
+ # @return [Integer] 開始西暦年
18
+ attr_reader :start_year
19
+ # @return [Integer] 終了西暦年
20
+ attr_reader :end_year
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [String] name 暦名
26
+ # @param [Western::Calendar] start_date 暦の開始日
27
+ # @param [Integer] start_year 開始西暦年
28
+ # @param [Integer] end_year 終了西暦年
29
+ #
30
+ def initialize(name:, start_date:, start_year:, end_year:)
31
+ @name = name
32
+ @start_date = start_date
33
+ @start_year = start_year
34
+ @end_year = end_year
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './internal/crawler'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Version
11
+ #
12
+ # 暦の範囲を取得する
13
+ #
14
+ # @param [Integer] start_year 開始西暦年
15
+ # @param [Integer] end_year 終了西暦年
16
+ #
17
+ # @return [Array<Range>] 暦の範囲
18
+ #
19
+ def self.get(start_year:, end_year:)
20
+ Crawler.get(start_year: start_year, end_year: end_year)
21
+ end
22
+ end
23
+ end
24
+ end