zakuro 0.0.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +102 -42
  3. data/doc/operation.md +25 -0
  4. data/doc/operation/csv/month.csv +202 -0
  5. data/doc/operation/operation.xlsx +0 -0
  6. data/doc/operation/transfer.rb +77 -0
  7. data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
  8. data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
  9. data/lib/zakuro/calculation/base/year.rb +107 -0
  10. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +459 -0
  11. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +173 -0
  12. data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
  13. data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
  14. data/lib/zakuro/calculation/monthly/initialized_month.rb +125 -0
  15. data/lib/zakuro/calculation/monthly/month.rb +187 -0
  16. data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
  17. data/lib/zakuro/calculation/monthly/operated_month.rb +209 -0
  18. data/lib/zakuro/calculation/range/full_range.rb +210 -0
  19. data/lib/zakuro/calculation/range/operated_range.rb +144 -0
  20. data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
  21. data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +82 -0
  22. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +146 -0
  23. data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
  24. data/lib/zakuro/calculation/summary/single.rb +129 -0
  25. data/lib/zakuro/condition.rb +16 -13
  26. data/lib/zakuro/era/japan/gengou.rb +106 -0
  27. data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
  28. data/lib/zakuro/era/japan/gengou/type.rb +178 -0
  29. data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
  30. data/lib/zakuro/era/japan/reki.rb +91 -0
  31. data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
  32. data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
  33. data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +0 -0
  34. data/lib/zakuro/era/western.rb +1 -1
  35. data/lib/zakuro/merchant.rb +2 -2
  36. data/lib/zakuro/operation/month/parser.rb +373 -0
  37. data/lib/zakuro/operation/month/type.rb +453 -0
  38. data/lib/zakuro/operation/month/validator.rb +802 -0
  39. data/lib/zakuro/operation/operation.rb +66 -0
  40. data/lib/zakuro/operation/yaml/month.yaml +6452 -0
  41. data/lib/zakuro/output/error.rb +7 -4
  42. data/lib/zakuro/output/logger.rb +50 -47
  43. data/lib/zakuro/output/response.rb +146 -143
  44. data/lib/zakuro/result/core.rb +52 -0
  45. data/lib/zakuro/result/data.rb +187 -0
  46. data/lib/zakuro/result/operation.rb +114 -0
  47. data/lib/zakuro/result/result.rb +37 -0
  48. data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
  49. data/lib/zakuro/tools/typeof.rb +33 -0
  50. data/lib/zakuro/version.rb +1 -1
  51. data/lib/zakuro/version/abstract_version.rb +1 -1
  52. data/lib/zakuro/version/context.rb +23 -0
  53. data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
  54. data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
  55. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
  56. data/lib/zakuro/version/senmyou/range/annual_range.rb +167 -0
  57. data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
  58. data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +6 -6
  59. data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -152
  60. data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
  61. data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +3 -184
  62. data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
  63. data/lib/zakuro/version/version_class_resolver.rb +62 -0
  64. data/lib/zakuro/version_factory.rb +3 -3
  65. metadata +53 -24
  66. data/lib/zakuro/cycle/abstract_remainder.rb +0 -456
  67. data/lib/zakuro/cycle/zodiac.rb +0 -103
  68. data/lib/zakuro/era/japan.rb +0 -664
  69. data/lib/zakuro/output/result.rb +0 -225
  70. data/lib/zakuro/version/senmyou/base/era.rb +0 -83
  71. data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
  72. data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -205
  73. data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
  74. data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -66
  75. data/lib/zakuro/version/senmyou/base/year.rb +0 -104
  76. data/lib/zakuro/version/senmyou/monthly/month.rb +0 -122
  77. data/lib/zakuro/version/senmyou/summary/annual_range.rb +0 -187
  78. data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -224
  79. data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './era/japan'
3
+ require_relative './era/japan/reki'
4
4
  require_relative './era/western'
5
5
  require_relative './version/genka/genka'
6
6
  require_relative './version/gihou/gihou'
@@ -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.0.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pldb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-05-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mainly lunar solar calendar
14
14
  email:
@@ -29,6 +29,10 @@ files:
29
29
  - bin/console
30
30
  - bin/setup
31
31
  - doc/gengou.md
32
+ - doc/operation.md
33
+ - doc/operation/csv/month.csv
34
+ - doc/operation/operation.xlsx
35
+ - doc/operation/transfer.rb
32
36
  - images/12月以降の入定気.png
33
37
  - images/12月以降の月の進退.png
34
38
  - images/source/description.numbers
@@ -36,22 +40,52 @@ files:
36
40
  - images/各月の求め方.png
37
41
  - images/太陽と月.png
38
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
39
61
  - lib/zakuro/condition.rb
40
- - lib/zakuro/cycle/abstract_remainder.rb
41
- - lib/zakuro/cycle/zodiac.rb
42
- - lib/zakuro/era/gengou/set-001-until-south.yaml
43
- - lib/zakuro/era/gengou/set-002-from-north.yaml
44
- - lib/zakuro/era/gengou/set-003-modern.yaml
45
- - lib/zakuro/era/japan.rb
62
+ - lib/zakuro/era/japan/gengou.rb
63
+ - lib/zakuro/era/japan/gengou/parser.rb
64
+ - lib/zakuro/era/japan/gengou/type.rb
65
+ - lib/zakuro/era/japan/gengou/validator.rb
66
+ - lib/zakuro/era/japan/reki.rb
67
+ - lib/zakuro/era/japan/yaml/set-001-until-south.yaml
68
+ - lib/zakuro/era/japan/yaml/set-002-from-north.yaml
69
+ - lib/zakuro/era/japan/yaml/set-003-modern.yaml
46
70
  - lib/zakuro/era/western.rb
47
71
  - lib/zakuro/merchant.rb
72
+ - lib/zakuro/operation/month/parser.rb
73
+ - lib/zakuro/operation/month/type.rb
74
+ - lib/zakuro/operation/month/validator.rb
75
+ - lib/zakuro/operation/operation.rb
76
+ - lib/zakuro/operation/yaml/month.yaml
48
77
  - lib/zakuro/output/error.rb
49
78
  - lib/zakuro/output/logger.rb
50
79
  - lib/zakuro/output/response.rb
51
- - lib/zakuro/output/result.rb
52
- - lib/zakuro/output/stringifier.rb
80
+ - lib/zakuro/result/core.rb
81
+ - lib/zakuro/result/data.rb
82
+ - lib/zakuro/result/operation.rb
83
+ - lib/zakuro/result/result.rb
84
+ - lib/zakuro/tools/stringifier.rb
85
+ - lib/zakuro/tools/typeof.rb
53
86
  - lib/zakuro/version.rb
54
87
  - lib/zakuro/version/abstract_version.rb
88
+ - lib/zakuro/version/context.rb
55
89
  - lib/zakuro/version/genka/genka.rb
56
90
  - lib/zakuro/version/gihou/gihou.rb
57
91
  - lib/zakuro/version/gregorio/gregorio.rb
@@ -59,24 +93,19 @@ files:
59
93
  - lib/zakuro/version/joukyou/joukyou.rb
60
94
  - lib/zakuro/version/kansei/kansei.rb
61
95
  - lib/zakuro/version/senmyou/README.md
62
- - lib/zakuro/version/senmyou/base/era.rb
63
- - lib/zakuro/version/senmyou/base/multi_gengou.rb
64
- - lib/zakuro/version/senmyou/base/multi_gengou_roller.rb
65
- - lib/zakuro/version/senmyou/base/remainder.rb
66
- - lib/zakuro/version/senmyou/base/solar_term.rb
67
- - lib/zakuro/version/senmyou/base/year.rb
96
+ - lib/zakuro/version/senmyou/cycle/remainder.rb
97
+ - lib/zakuro/version/senmyou/cycle/solar_term.rb
68
98
  - lib/zakuro/version/senmyou/monthly/lunar_phase.rb
69
- - lib/zakuro/version/senmyou/monthly/month.rb
99
+ - lib/zakuro/version/senmyou/range/annual_range.rb
70
100
  - lib/zakuro/version/senmyou/senmyou.rb
71
101
  - lib/zakuro/version/senmyou/stella/lunar_orbit.rb
72
102
  - lib/zakuro/version/senmyou/stella/solar_average.rb
103
+ - lib/zakuro/version/senmyou/stella/solar_location.rb
73
104
  - lib/zakuro/version/senmyou/stella/solar_orbit.rb
74
105
  - lib/zakuro/version/senmyou/stella/winter_solstice.rb
75
- - lib/zakuro/version/senmyou/summary/annual_range.rb
76
- - lib/zakuro/version/senmyou/summary/full_range.rb
77
- - lib/zakuro/version/senmyou/summary/specifier.rb
78
106
  - lib/zakuro/version/taien/taien.rb
79
107
  - lib/zakuro/version/tenpou/tenpou.rb
108
+ - lib/zakuro/version/version_class_resolver.rb
80
109
  - lib/zakuro/version_factory.rb
81
110
  - zakuro.gemspec
82
111
  homepage: https://github.com/pldb/zakuro
@@ -87,7 +116,7 @@ metadata:
87
116
  homepage_uri: https://github.com/pldb/zakuro
88
117
  source_code_uri: https://github.com/pldb/zakuro
89
118
  changelog_uri: https://github.com/pldb/zakuro
90
- post_install_message:
119
+ post_install_message:
91
120
  rdoc_options: []
92
121
  require_paths:
93
122
  - lib
@@ -102,8 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
131
  - !ruby/object:Gem::Version
103
132
  version: '0'
104
133
  requirements: []
105
- rubygems_version: 3.1.4
106
- signing_key:
134
+ rubygems_version: 3.1.2
135
+ signing_key:
107
136
  specification_version: 4
108
137
  summary: japanese calendar library.
109
138
  test_files: []
@@ -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