zakuro 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) 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 +459 -0
  6. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +151 -0
  7. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  8. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  9. data/lib/zakuro/calculation/monthly/initialized_month.rb +120 -0
  10. data/lib/zakuro/calculation/monthly/month.rb +184 -0
  11. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  12. data/lib/zakuro/calculation/monthly/operated_month.rb +201 -0
  13. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  14. data/lib/zakuro/calculation/range/operated_range.rb +134 -0
  15. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  16. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +76 -0
  17. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +142 -0
  18. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  19. data/lib/zakuro/calculation/summary/single.rb +129 -0
  20. data/lib/zakuro/merchant.rb +2 -2
  21. data/lib/zakuro/output/error.rb +7 -6
  22. data/lib/zakuro/output/logger.rb +50 -49
  23. data/lib/zakuro/output/response.rb +145 -144
  24. data/lib/zakuro/tools/typeof.rb +2 -2
  25. data/lib/zakuro/version.rb +1 -1
  26. data/lib/zakuro/version/abstract_version.rb +1 -1
  27. data/lib/zakuro/version/context.rb +23 -0
  28. data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
  29. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  30. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
  31. data/lib/zakuro/version/senmyou/range/annual_range.rb +134 -129
  32. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  33. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +5 -5
  34. data/lib/zakuro/version/senmyou/stella/solar_average.rb +4 -4
  35. data/lib/zakuro/version/senmyou/stella/solar_location.rb +27 -27
  36. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +2 -2
  37. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
  38. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  39. data/lib/zakuro/version_factory.rb +2 -2
  40. metadata +24 -22
  41. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  42. data/lib/zakuro/cycle/zodiac.rb +0 -103
  43. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  44. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  45. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -217
  46. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  47. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -148
  48. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  49. data/lib/zakuro/version/senmyou/monthly/first_day.rb +0 -44
  50. data/lib/zakuro/version/senmyou/monthly/initialized_month.rb +0 -119
  51. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -181
  52. data/lib/zakuro/version/senmyou/monthly/month_label.rb +0 -87
  53. data/lib/zakuro/version/senmyou/monthly/operated_month.rb +0 -196
  54. data/lib/zakuro/version/senmyou/range/full_range.rb +0 -194
  55. data/lib/zakuro/version/senmyou/range/operated_range.rb +0 -126
  56. data/lib/zakuro/version/senmyou/range/operated_solar_terms.rb +0 -181
  57. data/lib/zakuro/version/senmyou/range/western_date_allocation.rb +0 -68
  58. data/lib/zakuro/version/senmyou/range/year_boundary.rb +0 -138
  59. data/lib/zakuro/version/senmyou/specifier/single_day_specifier.rb +0 -102
  60. data/lib/zakuro/version/senmyou/summary/single.rb +0 -125
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../base/solar_term'
3
+ require_relative '../cycle/solar_term'
4
4
 
5
5
  # :nodoc:
6
6
  module Zakuro
@@ -134,7 +134,7 @@ module Zakuro
134
134
  # @return [Adjustment::Item] 24気損益眺朒(ちょうじく)数
135
135
  #
136
136
  def self.specify_solar_term_adjustment(index:)
137
- key = SolarTerm::ORDER[index]
137
+ key = Cycle::SolarTerm::ORDER[index]
138
138
  Adjustment::LIST[key].clone
139
139
  end
140
140
  private_class_method :specify_solar_term_adjustment
@@ -27,8 +27,8 @@ module Zakuro
27
27
  # @return [Integer] 暦の開始年(長慶2年)
28
28
  BEGIN_YEAR = 822
29
29
 
30
- # @return [Logger] ロガー
31
- LOGGER = Logger.new(location: 'winter_solstice')
30
+ # @return [Output::Logger] ロガー
31
+ LOGGER = Output::Logger.new(location: 'winter_solstice')
32
32
 
33
33
  # :reek:TooManyStatements { max_statements: 6 }
34
34
 
@@ -51,7 +51,7 @@ module Zakuro
51
51
 
52
52
  LOGGER.debug("[a02]:#{winter_solstice_minute}")
53
53
 
54
- Remainder.new(total: winter_solstice_minute)
54
+ Cycle::Remainder.new(total: winter_solstice_minute)
55
55
  end
56
56
 
57
57
  # :reek:TooManyStatements { max_statements: 7 }
@@ -82,7 +82,7 @@ module Zakuro
82
82
  LOGGER.debug("[b02]: #{winter_solstice_age}")
83
83
 
84
84
  # 大余・小余に変換する
85
- Remainder.new(total: winter_solstice_age)
85
+ Cycle::Remainder.new(total: winter_solstice_age)
86
86
  end
87
87
 
88
88
  #
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './senmyou/cycle/remainder'
4
+ require_relative './senmyou/cycle/solar_term'
5
+ require_relative './senmyou/range/annual_range'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ #
10
+ # VersionClassResolver 暦リゾルバー
11
+ #
12
+ class VersionClassResolver
13
+ attr_reader :version_name
14
+
15
+ CLASSES = {
16
+ 'remainder' => 'Zakuro::$VERSION::Cycle::Remainder',
17
+ 'solar_term' => 'Zakuro::$VERSION::Cycle::SolarTerm',
18
+ 'annual_range' => 'Zakuro::$VERSION::Range::AnnualRange'
19
+ }.freeze
20
+
21
+ def initialize(version_name:)
22
+ @version_name = version_name
23
+ end
24
+
25
+ def self.get_class(version_name:, class_name:)
26
+ constant = CLASSES.fetch(class_name, '')
27
+
28
+ raise ArgumentError.new, 'invalid class name' if constant == ''
29
+
30
+ resolved_constant = constant.gsub('$VERSION', version_name)
31
+
32
+ Object.const_get(resolved_constant)
33
+ end
34
+
35
+ #
36
+ # 大余小余(暦別)クラスを返す
37
+ #
38
+ # @return [Class] 大余小余(暦別)クラス
39
+ #
40
+ def remainder
41
+ VersionClassResolver.get_class(version_name: @version_name, class_name: 'remainder')
42
+ end
43
+
44
+ #
45
+ # 二十四節気クラスを返す
46
+ #
47
+ # @return [Class] 二十四節気クラス
48
+ #
49
+ def solar_term
50
+ VersionClassResolver.get_class(version_name: @version_name, class_name: 'solar_term')
51
+ end
52
+
53
+ #
54
+ # 年間範囲クラスを返す
55
+ #
56
+ # @return [Class] 年間範囲クラス
57
+ #
58
+ def annual_range
59
+ VersionClassResolver.get_class(version_name: @version_name, class_name: 'annual_range')
60
+ end
61
+ end
62
+ end
@@ -47,13 +47,13 @@ module Zakuro
47
47
  #
48
48
  # @param [Date] western_date 西暦日
49
49
  #
50
- # @return [Result::SingleDay] 和暦日
50
+ # @return [Result::Single] 和暦日
51
51
  #
52
52
  def self.to_japan_date(western_date:)
53
53
  runnable = VersionFactory.get_runnable_constant(date: western_date)
54
54
  runnable.to_japan_date(western_date: western_date)
55
55
  rescue StandardError => e
56
- raise ZakuroError, e.message
56
+ raise Output::ZakuroError, e.message
57
57
  end
58
58
  end
59
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zakuro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - pldb
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-29 00:00:00.000000000 Z
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mainly lunar solar calendar
14
14
  email:
@@ -40,9 +40,25 @@ files:
40
40
  - images/各月の求め方.png
41
41
  - images/太陽と月.png
42
42
  - lib/zakuro.rb
43
+ - lib/zakuro/calculation/base/multi_gengou.rb
44
+ - lib/zakuro/calculation/base/multi_gengou_roller.rb
45
+ - lib/zakuro/calculation/base/year.rb
46
+ - lib/zakuro/calculation/cycle/abstract_remainder.rb
47
+ - lib/zakuro/calculation/cycle/abstract_solar_term.rb
48
+ - lib/zakuro/calculation/cycle/zodiac.rb
49
+ - lib/zakuro/calculation/monthly/first_day.rb
50
+ - lib/zakuro/calculation/monthly/initialized_month.rb
51
+ - lib/zakuro/calculation/monthly/month.rb
52
+ - lib/zakuro/calculation/monthly/month_label.rb
53
+ - lib/zakuro/calculation/monthly/operated_month.rb
54
+ - lib/zakuro/calculation/range/full_range.rb
55
+ - lib/zakuro/calculation/range/operated_range.rb
56
+ - lib/zakuro/calculation/range/operated_solar_terms.rb
57
+ - lib/zakuro/calculation/range/transfer/western_date_allocation.rb
58
+ - lib/zakuro/calculation/range/transfer/year_boundary.rb
59
+ - lib/zakuro/calculation/specifier/single_day.rb
60
+ - lib/zakuro/calculation/summary/single.rb
43
61
  - lib/zakuro/condition.rb
44
- - lib/zakuro/cycle/abstract_remainder.rb
45
- - lib/zakuro/cycle/zodiac.rb
46
62
  - lib/zakuro/era/japan/gengou.rb
47
63
  - lib/zakuro/era/japan/gengou/parser.rb
48
64
  - lib/zakuro/era/japan/gengou/type.rb
@@ -69,6 +85,7 @@ files:
69
85
  - lib/zakuro/tools/typeof.rb
70
86
  - lib/zakuro/version.rb
71
87
  - lib/zakuro/version/abstract_version.rb
88
+ - lib/zakuro/version/context.rb
72
89
  - lib/zakuro/version/genka/genka.rb
73
90
  - lib/zakuro/version/gihou/gihou.rb
74
91
  - lib/zakuro/version/gregorio/gregorio.rb
@@ -76,34 +93,19 @@ files:
76
93
  - lib/zakuro/version/joukyou/joukyou.rb
77
94
  - lib/zakuro/version/kansei/kansei.rb
78
95
  - lib/zakuro/version/senmyou/README.md
79
- - lib/zakuro/version/senmyou/base/era.rb
80
- - lib/zakuro/version/senmyou/base/multi_gengou.rb
81
- - lib/zakuro/version/senmyou/base/multi_gengou_roller.rb
82
- - lib/zakuro/version/senmyou/base/remainder.rb
83
- - lib/zakuro/version/senmyou/base/solar_term.rb
84
- - lib/zakuro/version/senmyou/base/year.rb
85
- - lib/zakuro/version/senmyou/monthly/first_day.rb
86
- - lib/zakuro/version/senmyou/monthly/initialized_month.rb
96
+ - lib/zakuro/version/senmyou/cycle/remainder.rb
97
+ - lib/zakuro/version/senmyou/cycle/solar_term.rb
87
98
  - lib/zakuro/version/senmyou/monthly/lunar_phase.rb
88
- - lib/zakuro/version/senmyou/monthly/month.rb
89
- - lib/zakuro/version/senmyou/monthly/month_label.rb
90
- - lib/zakuro/version/senmyou/monthly/operated_month.rb
91
99
  - lib/zakuro/version/senmyou/range/annual_range.rb
92
- - lib/zakuro/version/senmyou/range/full_range.rb
93
- - lib/zakuro/version/senmyou/range/operated_range.rb
94
- - lib/zakuro/version/senmyou/range/operated_solar_terms.rb
95
- - lib/zakuro/version/senmyou/range/western_date_allocation.rb
96
- - lib/zakuro/version/senmyou/range/year_boundary.rb
97
100
  - lib/zakuro/version/senmyou/senmyou.rb
98
- - lib/zakuro/version/senmyou/specifier/single_day_specifier.rb
99
101
  - lib/zakuro/version/senmyou/stella/lunar_orbit.rb
100
102
  - lib/zakuro/version/senmyou/stella/solar_average.rb
101
103
  - lib/zakuro/version/senmyou/stella/solar_location.rb
102
104
  - lib/zakuro/version/senmyou/stella/solar_orbit.rb
103
105
  - lib/zakuro/version/senmyou/stella/winter_solstice.rb
104
- - lib/zakuro/version/senmyou/summary/single.rb
105
106
  - lib/zakuro/version/taien/taien.rb
106
107
  - lib/zakuro/version/tenpou/tenpou.rb
108
+ - lib/zakuro/version/version_class_resolver.rb
107
109
  - lib/zakuro/version_factory.rb
108
110
  - zakuro.gemspec
109
111
  homepage: https://github.com/pldb/zakuro
@@ -1,456 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # :nodoc:
4
- module Zakuro
5
- # :nodoc:
6
- module Cycle
7
- #
8
- # 大余小余(時刻情報)
9
- # @abstract 大余小余計算に必要な処理を行う、暦に依存しない汎用的なクラス
10
- #
11
- class AbstractRemainder # rubocop:disable Metrics/ClassLength
12
- # @return [Integer] 大余上限
13
- LIMIT = 60
14
-
15
- # @return [Integer] 大余("日"に相当)
16
- attr_reader :day
17
- # @return [Integer] 小余("分"に相当)
18
- attr_reader :minute
19
- # @return [Integer] 秒
20
- attr_reader :second
21
- # @return [Integer] 繰り上げなしの小余
22
- attr_reader :base_limit
23
- # @return [Integer] 1大余に必要な小余(暦によって基数が異なる)
24
- attr_reader :base_day
25
- # @return [Integer] 1小余に必要な秒(暦によって基数が異なる)
26
- attr_reader :base_minute
27
- # 繰り上げ有無
28
- # @return [True] 繰り上げあり
29
- # @return [False] 繰り上げなし
30
- attr_reader :limited
31
-
32
- # :reek:instanceVariableAssumption
33
- # rubocop:disable Metrics/ParameterLists
34
-
35
- #
36
- # 初期化
37
- #
38
- # @param [Integer] base_day 1大余に必要な小余(暦によって基数が異なる)
39
- # @param [Integer] base_mitune 1小余に必要な秒(暦によって基数が異なる)
40
- # @param [Integer] day 大余("日"に相当)
41
- # @param [Integer] minute 小余("分"に相当)
42
- # @param [Integer] second 秒
43
- # @param [Integer] total 繰り上げなしの小余
44
- #
45
- def initialize(base_day:, base_mitune:, day: -1, minute: -1, second: -1, total: -1)
46
- @base_limit = LIMIT
47
- @base_day = base_day
48
- @base_minute = base_mitune
49
- @limited = true
50
-
51
- set(day: day, minute: minute, second: second, total: total)
52
- end
53
- # rubocop:enable Metrics/ParameterLists
54
-
55
- #
56
- # 値を設定する
57
- #
58
- # @param [Integer] day 大余("日"に相当)
59
- # @param [Integer] minute 小余("分"に相当)
60
- # @param [Integer] second 秒
61
- # @param [Integer] total 繰り上げなしの小余
62
- #
63
- # @return [AbstractRemainder] 自身の参照
64
- #
65
- def set(day: -1, minute: -1, second: -1, total: -1)
66
- @day = day
67
- @minute = minute
68
- @second = second
69
-
70
- if total != -1
71
- @day = (total.to_f / @base_day).floor
72
- @minute = (total % @base_day)
73
- @second = 0
74
- end
75
-
76
- self
77
- end
78
-
79
- #
80
- # 繰り上げ処理を外す
81
- #
82
- # @return [AbstractRemainder] 自身の参照
83
- #
84
- def lift_limit
85
- @limited = false
86
-
87
- self
88
- end
89
-
90
- #
91
- # 繰り上げ処理を設定する
92
- #
93
- # @return [AbstractRemainder] 自身の参照
94
- #
95
- def set_limit
96
- @limited = true
97
-
98
- self
99
- end
100
-
101
- #
102
- # 無効かどうか
103
- #
104
- # @param [AbstractRemainder] param 自クラスのインスタンス(デフォルトは自身の参照)
105
- #
106
- # @return [True] 無効
107
- # @return [False] 有効
108
- #
109
- def invalid?(param: self)
110
- raise ArgumentError, 'unmatch parameter type' unless param.is_a?(AbstractRemainder)
111
-
112
- param.day == -1 || param.minute == -1 || param.second == -1
113
- end
114
-
115
- #
116
- # 十干十二支名
117
- #
118
- # @return [String] 十干十二支名
119
- #
120
- def zodiac_name
121
- Cycle::Zodiac.day_name(day: @day)
122
- end
123
-
124
- #
125
- # 日が同じ十干かどうか(大小の月判定)
126
- #
127
- # @param [Integer] other 大余
128
- #
129
- # @return [True] 当月朔日と翌月朔日が同じ十干(「大」の月)
130
- # @return [False] 当月朔日と翌月朔日が異なる十干(「小」の月)
131
- #
132
- def same_remainder_divided_by_ten?(other:)
133
- day = @day % LIMIT
134
-
135
- (day % 10) == (other % 10)
136
- end
137
-
138
- #
139
- # (非破壊的に)加算する
140
- #
141
- # @param [AbstractRemainder] other 他の大余小余
142
- #
143
- # @return [AbstractRemainder] 加算結果
144
- #
145
- def add(other)
146
- invalid?(param: other)
147
- day = @day + other.day
148
- minute = @minute + other.minute
149
- second = @second + other.second
150
- day, minute, second = carry(day, minute, second)
151
-
152
- clone.set(day: day, minute: minute, second: second)
153
- end
154
-
155
- #
156
- # (破壊的に)加算する
157
- #
158
- # @param [AbstractRemainder] other 他の大余小余
159
- #
160
- # @return [AbstractRemainder] 加算結果
161
- #
162
- def add!(other)
163
- result = add(other)
164
- @day = result.day
165
- @minute = result.minute
166
- @second = result.second
167
-
168
- self
169
- end
170
-
171
- #
172
- # (非破壊的に)除算する
173
- #
174
- # @param [AbstractRemainder] other 他の大余小余
175
- #
176
- # @return [AbstractRemainder] 除算結果
177
- #
178
- def sub(other)
179
- invalid?(param: other)
180
- day = @day - other.day
181
- minute = @minute - other.minute
182
- second = @second - other.second
183
- day, minute, second = carry(day, minute, second)
184
-
185
- clone.set(day: day, minute: minute, second: second)
186
- end
187
-
188
- #
189
- # (破壊的に)除算する
190
- #
191
- # @param [AbstractRemainder] other 他の大余小余
192
- #
193
- # @return [AbstractRemainder] 除算結果
194
- #
195
- def sub!(other)
196
- result = sub(other)
197
- @day = result.day
198
- @minute = result.minute
199
- @second = result.second
200
-
201
- self
202
- end
203
-
204
- #
205
- # 大小比較(>)
206
- #
207
- # @param [AbstractRemainder] other 他の大余小余
208
- #
209
- # @return [True] より大きい
210
- # @return [False] 以下
211
- #
212
- def >(other)
213
- up?(other)
214
- end
215
-
216
- #
217
- # 大小比較(>=)
218
- #
219
- # @param [AbstractRemainder] other 他の大余小余
220
- #
221
- # @return [True] 以上
222
- # @return [False] より小さい
223
- #
224
- def >=(other)
225
- up?(other) || \
226
- (@day == other.day && @minute == other.minute && @second == other.second)
227
- end
228
-
229
- #
230
- # 大小比較(<)
231
- #
232
- # @param [AbstractRemainder] other 他の大余小余
233
- #
234
- # @return [True] より小さい
235
- # @return [False] 以上
236
- #
237
- def <(other)
238
- down?(other)
239
- end
240
-
241
- #
242
- # 大小比較(<=)
243
- #
244
- # @param [AbstractRemainder] other 他の大余小余
245
- #
246
- # @return [True] 以下
247
- # @return [False] より大きい
248
- #
249
- def <=(other)
250
- down?(other) || \
251
- (@day == other.day && @minute == other.minute && @second == other.second)
252
- end
253
-
254
- #
255
- # 大小比較(==)
256
- #
257
- # @param [AbstractRemainder] other 他の大余小余
258
- #
259
- # @return [True] 等しい
260
- # @return [False] 等しくない
261
- #
262
- def ==(other)
263
- eql?(other)
264
- end
265
-
266
- #
267
- # 大小比較(!=)
268
- #
269
- # @param [AbstractRemainder] other 他の大余小余
270
- #
271
- # @return [True] 等しくない
272
- # @return [False] 等しい
273
- #
274
- def !=(other)
275
- !eql?(other)
276
- end
277
-
278
- # 進朔
279
- # @see 進朔 http://eco.mtk.nao.ac.jp/koyomi/wiki/C2C0B1A2C2C0CDDBCEF12FBFCABAF3.html
280
- # 進朔とは、朔の瞬間が1日の3/4すなわち夕方以降となる場合に、その日ではなく1日進めて翌日を1日目にする方法のことです。
281
- # 進朔するかどうかの基準時刻を進朔限といいます。宣明暦では1日8400分ですから、進朔限は6300分で、それ以降だと進朔されます。
282
-
283
- #
284
- # (非破壊的に)進朔する
285
- #
286
- # @see http://eco.mtk.nao.ac.jp/koyomi/wiki/C2C0B1A2C2C0CDDBCEF12FBFCABAF3.html
287
- #
288
- # 進朔とは、朔の瞬間が1日の3/4すなわち夕方以降となる場合に、その日ではなく1日進めて翌日を1日目にする方法のことです。
289
- # 進朔するかどうかの基準時刻を進朔限といいます。宣明暦では1日8400分ですから、進朔限は6300分で、それ以降だと進朔されます。
290
- #
291
- # @return [AbstractRemainder] 進朔結果
292
- #
293
- def up_on_new_moon
294
- cloned = clone
295
- limit = (base_day * 3) / 4
296
- if @minute >= limit
297
- day, minute, second = carry((@day + 1), @minute, @second)
298
- return cloned.set(day: day, minute: minute, second: second)
299
- end
300
-
301
- cloned
302
- end
303
-
304
- #
305
- # (破壊的に)進朔する
306
- #
307
- # @see http://eco.mtk.nao.ac.jp/koyomi/wiki/C2C0B1A2C2C0CDDBCEF12FBFCABAF3.html
308
- #
309
- # 進朔とは、朔の瞬間が1日の3/4すなわち夕方以降となる場合に、その日ではなく1日進めて翌日を1日目にする方法のことです。
310
- # 進朔するかどうかの基準時刻を進朔限といいます。宣明暦では1日8400分ですから、進朔限は6300分で、それ以降だと進朔されます。
311
- #
312
- # @return [AbstractRemainder] 進朔結果
313
- #
314
- def up_on_new_moon!
315
- result = up_on_new_moon
316
- @day = result.day
317
- @minute = result.minute
318
- @second = result.second
319
-
320
- self
321
- end
322
-
323
- #
324
- # 小余に揃えた結果を返す(秒は除外する)
325
- #
326
- # @return [Integer] 小余
327
- #
328
- def to_minute
329
- @day * @base_day + @minute
330
- end
331
-
332
- #
333
- # 大余に四捨五入した結果を返す(秒は除外する)
334
- #
335
- # @return [AbstractRemainder] 大余
336
- #
337
- def round
338
- day = @day
339
- day += 1 if @minute >= (@base_day / 2)
340
-
341
- initialize(day, 0, 0)
342
- end
343
-
344
- #
345
- # 文字化する
346
- #
347
- # @return [String] 文字化
348
- #
349
- def to_s
350
- "大余(日): #{@day}, 小余(分): #{@minute}, 小余(秒): #{@second}"
351
- end
352
-
353
- #
354
- # 特定の文字フォーマットにして出力する
355
- #
356
- # @param [String] form フォーマット(大余、小余、秒それぞれを%dで指定する)
357
- #
358
- # @return [String] フォーマットした結果
359
- #
360
- def format(form: '%d-%d')
361
- return '' if invalid?
362
-
363
- super(form, @day, @minute, @second)
364
- end
365
-
366
- private
367
-
368
- def carry!(day, minute, second)
369
- @day, @minute, @second = carry(day, minute, second)
370
-
371
- self
372
- end
373
-
374
- # 繰り上げ、繰り下げ
375
- def carry(param_day, param_minute, param_second)
376
- # NOTE: 計算方法としてマイナスでも徐算・剰余算の結果をプラス同様に扱う
377
- minute, second = carry_second(param_minute, param_second)
378
-
379
- day, minute = carry_minute(param_day, minute)
380
-
381
- day = carry_day(day, @limited)
382
-
383
- [day, minute, second]
384
- end
385
-
386
- def carry_second(param_minute, param_second)
387
- sign = param_second.negative? ? -1 : 1
388
- abs = sign * param_second
389
- minute = param_minute + (sign * (abs / @base_minute).floor)
390
- second = sign * (abs % @base_minute)
391
-
392
- if sign.negative?
393
- second += @base_minute
394
- minute -= 1
395
- end
396
-
397
- [minute, second]
398
- end
399
-
400
- def carry_minute(param_day, param_minute)
401
- sign = param_minute.negative? ? -1 : 1
402
- abs = sign * param_minute
403
-
404
- day = param_day + (sign * (abs / @base_day).floor)
405
- minute = sign * (abs % @base_day)
406
-
407
- if sign.negative?
408
- minute += @base_day
409
- day -= 1
410
- end
411
-
412
- [day, minute]
413
- end
414
-
415
- def carry_day(day, limited)
416
- sign = day.negative? ? -1 : 1
417
- abs = sign * day
418
- carried = sign * (abs % @base_limit) if limited
419
- carried += @base_limit if sign.negative?
420
- carried
421
- end
422
-
423
- def up?(other)
424
- invalid?(param: other)
425
- day = other.day
426
- minute = other.minute
427
- return true if @day > day
428
- return false if @day < day
429
-
430
- return true if @minute > minute
431
- return false if @minute < minute
432
-
433
- @second > other.second
434
- end
435
-
436
- def eql?(other)
437
- invalid?(param: other)
438
-
439
- (@day == other.day && @minute == other.minute && @second == other.second)
440
- end
441
-
442
- def down?(other)
443
- invalid?(param: other)
444
- day = other.day
445
- minute = other.minute
446
- return true if @day < day
447
- return false if @day > day
448
-
449
- return true if @minute < minute
450
- return false if @minute > minute
451
-
452
- @second < other.second
453
- end
454
- end
455
- end
456
- end