zakuro 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +33 -20
  3. data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +9 -7
  4. data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +19 -0
  5. data/lib/zakuro/era/japan/reki.rb +1 -1
  6. data/lib/zakuro/version.rb +1 -1
  7. data/lib/zakuro/version/context.rb +1 -1
  8. data/lib/zakuro/version/daien/const/number.rb +55 -0
  9. data/lib/zakuro/version/daien/const/remainder.rb +53 -0
  10. data/lib/zakuro/version/daien/cycle/remainder.rb +59 -0
  11. data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
  12. data/lib/zakuro/version/daien/daien.rb +36 -0
  13. data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
  14. data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
  15. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
  16. data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
  17. data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
  18. data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
  19. data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
  20. data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
  21. data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
  22. data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
  23. data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
  24. data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
  25. data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
  26. data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
  27. data/lib/zakuro/version/gihou/const/remainder.rb +0 -2
  28. data/lib/zakuro/version/gihou/cycle/remainder.rb +1 -6
  29. data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +1 -1
  30. data/lib/zakuro/version/gihou/stella/lunar/location.rb +2 -8
  31. data/lib/zakuro/version/gihou/stella/lunar/value.rb +3 -2
  32. data/lib/zakuro/version/gihou/stella/solar/average.rb +1 -1
  33. data/lib/zakuro/version/senmyou/const/remainder.rb +0 -2
  34. data/lib/zakuro/version/senmyou/cycle/remainder.rb +1 -6
  35. data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
  36. data/lib/zakuro/version/senmyou/stella/lunar/location.rb +2 -8
  37. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +3 -2
  38. data/lib/zakuro/version/senmyou/stella/solar/average.rb +1 -1
  39. data/lib/zakuro/version/version_class_resolver.rb +4 -0
  40. data/lib/zakuro/version_factory.rb +1 -1
  41. metadata +25 -7
  42. data/lib/zakuro/version/taien/taien.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4269bda9e7a1bc90589d072ac97a0acc089f098a5b1e8bbe6d04d661407c256
4
- data.tar.gz: cb8821e9f1f9692a867c4baec73ce515281d3bf4ef8a04db676909d03cd3b7b0
3
+ metadata.gz: 73a145098928102269c600528b1552422d174c88a14baa83f8cc426deaa2ee43
4
+ data.tar.gz: 55d493cccce632e6d654394bee779be3756a628cf747d6c064583cc8c244ab55
5
5
  SHA512:
6
- metadata.gz: f4acc077c7191f18601765cc81668660f4fe0af9dbeecf0af74cf0841f20546a0792484bbcc9bf8c490f62065ef8b32c9268def780037ec62739665823950d47
7
- data.tar.gz: 97ea77400bd644d2c84e08e4d3056ee121563e5d52e1b418dfb57e50cbf5c741f4dde1954d4951460618b5c5837bc13103f8ae7857075b159a307986e2fb39af
6
+ metadata.gz: 9df9ca681cf42f72b574b888123d40a2368218c9077f7c03415ec4e50219489d16b8e5f285c1c17cdad3f88bae1c8ea460920c2469c17f381adf4bc54d654033
7
+ data.tar.gz: 8eb61f2f32029e649f2faf75e3d4592daf9c2b2da82216143f5586712f0d1fe50088677bed35e980a3e2ddf2a1be3712f101c4486dfa32261efd3ce5da9bf4d7
@@ -10,6 +10,11 @@ module Zakuro
10
10
  # 大余小余(時刻情報)
11
11
  # @abstract 大余小余計算に必要な処理を行う、暦に依存しない汎用的なクラス
12
12
  #
13
+ # * 十干十二支(60日)を上限とした「日時分秒」の情報で、日付(date)/時刻(time)と部分的に重なる概念
14
+ # * 「15日1012分5秒」のような形式で表される
15
+ # * 分の上限で大余に繰り上げる
16
+ # * 秒の上限で1分に繰り上げる
17
+ #
13
18
  class AbstractRemainder # rubocop:disable Metrics/ClassLength
14
19
  # @return [Integer] 大余上限
15
20
  LIMIT = 60
@@ -224,8 +229,7 @@ module Zakuro
224
229
  # @return [False] より小さい
225
230
  #
226
231
  def >=(other)
227
- up?(other) || \
228
- (@day == other.day && @minute == other.minute && @second == other.second)
232
+ up?(other) || eql?(other)
229
233
  end
230
234
 
231
235
  #
@@ -249,8 +253,7 @@ module Zakuro
249
253
  # @return [False] より大きい
250
254
  #
251
255
  def <=(other)
252
- down?(other) || \
253
- (@day == other.day && @minute == other.minute && @second == other.second)
256
+ down?(other) || eql?(other)
254
257
  end
255
258
 
256
259
  #
@@ -339,10 +342,19 @@ module Zakuro
339
342
  # @return [Integer] 小余(秒切り捨て)
340
343
  #
341
344
  def floor_minute
342
- result = @minute + @second / @base_minute
345
+ result = float_minute
343
346
  result.floor
344
347
  end
345
348
 
349
+ #
350
+ # 秒を含めた小余を返す
351
+ #
352
+ # @return [Float] 小余
353
+ #
354
+ def float_minute
355
+ @minute + @second.to_f / @base_minute
356
+ end
357
+
346
358
  #
347
359
  # 大余に四捨五入した結果を返す(秒は除外する)
348
360
  #
@@ -377,14 +389,19 @@ module Zakuro
377
389
  super(form, @day, @minute, @second)
378
390
  end
379
391
 
380
- private
381
-
382
- def carry!(day, minute, second)
383
- @day, @minute, @second = carry(day, minute, second)
392
+ #
393
+ # 繰り上げる
394
+ #
395
+ # @return [AbstractRemainder] 繰り上げ結果
396
+ #
397
+ def carry!
398
+ @day, @minute, @second = carry(@day, @minute, @second)
384
399
 
385
400
  self
386
401
  end
387
402
 
403
+ private
404
+
388
405
  # 繰り上げ、繰り下げ
389
406
  def carry(param_day, param_minute, param_second)
390
407
  # NOTE: 計算方法としてマイナスでも徐算・剰余算の結果をプラス同様に扱う
@@ -437,33 +454,29 @@ module Zakuro
437
454
  def up?(other)
438
455
  invalid?(param: other)
439
456
  day = other.day
440
- minute = other.minute
457
+ minute = other.float_minute
458
+
441
459
  return true if @day > day
442
460
  return false if @day < day
443
461
 
444
- return true if @minute > minute
445
- return false if @minute < minute
446
-
447
- @second > other.second
462
+ float_minute > minute
448
463
  end
449
464
 
450
465
  def eql?(other)
451
466
  invalid?(param: other)
452
467
 
453
- (@day == other.day && @minute == other.minute && @second == other.second)
468
+ (@day == other.day && float_minute == other.float_minute)
454
469
  end
455
470
 
456
471
  def down?(other)
457
472
  invalid?(param: other)
458
473
  day = other.day
459
- minute = other.minute
474
+ minute = other.float_minute
475
+
460
476
  return true if @day < day
461
477
  return false if @day > day
462
478
 
463
- return true if @minute < minute
464
- return false if @minute > minute
465
-
466
- @second < other.second
479
+ float_minute < minute
467
480
  end
468
481
  end
469
482
  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
  # 切り捨て(プラスマイナスに関わらず小数点以下切り捨て)
@@ -44,7 +44,7 @@ module Zakuro
44
44
  start_date: Western::Calendar.new(year: 698, month: 2, day: 16)
45
45
  ),
46
46
  Range.new(
47
- class_name: 'Zakuro::Taien::Gateway',
47
+ class_name: 'Zakuro::Daien::Gateway',
48
48
  start_date: Western::Calendar.new(year: 764, month: 2, day: 7)
49
49
  ),
50
50
  Range.new(
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Zakuro
5
5
  # @return [String] library version
6
- VERSION = '0.2.0'
6
+ VERSION = '0.3.0'
7
7
  end
@@ -11,7 +11,7 @@ module Zakuro
11
11
  attr_reader :version_name
12
12
  attr_reader :resolver
13
13
 
14
- VERSION_NAMES = %w[Genka Gihou Taien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
14
+ VERSION_NAMES = %w[Genka Gihou Daien Senmyou Joukyou Kansei Tenpou Gregorio].freeze
15
15
 
16
16
  def initialize(version_name:)
17
17
  raise ArgumentError.new, 'invalid version' unless VERSION_NAMES.include?(version_name)
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Daien
7
+ #
8
+ # Const 定数
9
+ #
10
+ module Const
11
+ #
12
+ # Number 数値
13
+ #
14
+ module Number
15
+ #
16
+ # Cycle 周期
17
+ #
18
+ module Cycle
19
+ # @return [Integer] 通法(1日=3040分)
20
+ DAY = 3040
21
+ #
22
+ # @return [Float] 転日(1近点月 = 27日1685分79秒(1分=80秒))
23
+ # @note 小数点以下の値によって大幅に結果が変わる。除算結果を設定した
24
+ #
25
+ ANOMALISTIC_MONTH = 83_765 + (79.0 / 80)
26
+ # @return [Integer] 朔望月
27
+ SYNODIC_MONTH = 89_773
28
+ # @return [Integer] 一年
29
+ YEAR = 1_110_343
30
+ end
31
+
32
+ #
33
+ # Derivation 導出
34
+ #
35
+ module Derivation
36
+ # @return [Integer] 通余: (YEAR - DAY * 12 * 30)
37
+ # 1110343 - 1094400
38
+ REMAINDER_ALL_YEAR = 15_943
39
+ # @return [Integer] 旬周(60日) DAY * 60
40
+ SIXTY_DAYS = 182_400
41
+ end
42
+
43
+ #
44
+ # 累積
45
+ #
46
+ module Stack
47
+ # @return [Integer] 積年(甲子夜半朔旦冬至〜暦の開始前)
48
+ TOTAL_YEAR = 96_961_740
49
+ # @return [Integer] 暦の開始年(開元12年)
50
+ BEGIN_YEAR = 724
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../cycle/remainder'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Daien
9
+ #
10
+ # Const 定数
11
+ #
12
+ module Const
13
+ #
14
+ # Remainder 大余小余
15
+ #
16
+ module Remainder
17
+ #
18
+ # Solar 太陽
19
+ #
20
+ module Solar
21
+ # @return [Remainder] 気策(24分の1年)
22
+ # 1年(1_110_343) / 24 / 1日(3040)= 15 余り 664.2916666666642
23
+ # * 0.2916666666642 * 24(1分=24秒) = 6.999999999940799 ≒ 7
24
+ SOLAR_TERM_AVERAGE = Cycle::Remainder.new(day: 15, minute: 664, second: 7)
25
+ #
26
+ # @note 揲法 89773 = 29-1613
27
+ # * 89773 / 4 = 22443.25 / 3040 = 7 余り 1163.25
28
+ # * 0.25 * 24(1分=24秒) = 6
29
+ #
30
+ # @return [Cycle::Remainder] 弦(1分=80秒)
31
+ QUARTER = Cycle::Remainder.new(day: 7, minute: 1163, second: 6)
32
+ end
33
+
34
+ #
35
+ # Lunar 月
36
+ #
37
+ module Lunar
38
+ # @return [Cycle::LunarRemainder] 転日(1近点月)
39
+ ANOMALISTIC_MONTH = \
40
+ Cycle::LunarRemainder.new(day: 27, minute: 1685, second: 79)
41
+ #
42
+ # @note 揲法 89773 = 29-1613
43
+ # * 89773 / 4 = 22443.25 / 3040 = 7 余り 1163.25
44
+ # * 0.25 * 80(1分=80秒) = 20
45
+ #
46
+ # @return [Cycle::LunarRemainder] 弦(1分=80秒)
47
+ # TODO: 秒が20では通らない。少なくとも0.01247は必要になる
48
+ QUARTER = Cycle::LunarRemainder.new(day: 7, minute: 1163, second: 20.01247)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/cycle/abstract_remainder'
4
+
5
+ require_relative '../const/number'
6
+
7
+ # :nodoc:
8
+ module Zakuro
9
+ # :nodoc:
10
+ module Daien
11
+ # :nodoc:
12
+ module Cycle
13
+ #
14
+ # Remainder 時刻情報(大余小余)
15
+ #
16
+ class Remainder < Calculation::Cycle::AbstractRemainder
17
+ # 『歴代天文律暦等志彙編 七』中華書房 p.2056
18
+ # 「象統;二十四」「其秒盈象統,従小餘」
19
+ # 上記は舊唐志の記述だが、新唐志(p.2218)でも同様であることを確認した
20
+ # @return [Integer] 分(1分=24秒)
21
+ MINUTE = 24
22
+
23
+ #
24
+ # 初期化
25
+ #
26
+ # @param [Integer] day 大余("日"に相当)
27
+ # @param [Integer] minute 小余("分"に相当)
28
+ # @param [Integer] second 秒
29
+ # @param [Integer] total 繰り上げなしの小余
30
+ #
31
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
32
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
33
+ day: day, minute: minute, second: second, total: total)
34
+ end
35
+ end
36
+
37
+ #
38
+ # LunarRemainder 月の位相計算向け時刻情報(大余小余)
39
+ #
40
+ class LunarRemainder < Calculation::Cycle::AbstractRemainder
41
+ # @return [Integer] 分(1分=80秒)
42
+ MINUTE = 80
43
+
44
+ #
45
+ # 初期化
46
+ #
47
+ # @param [Integer] day 大余("日"に相当)
48
+ # @param [Integer] minute 小余("分"に相当)
49
+ # @param [Integer] second 秒
50
+ # @param [Integer] total 繰り上げなしの小余
51
+ #
52
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
53
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
54
+ day: day, minute: minute, second: second, total: total)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/cycle/abstract_solar_term'
4
+
5
+ require_relative '../const/remainder'
6
+
7
+ require_relative './remainder'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Daien
13
+ # :nodoc:
14
+ module Cycle
15
+ #
16
+ # SolarTerm 二十四節気
17
+ #
18
+ class SolarTerm < Calculation::Cycle::AbstractSolarTerm
19
+ # @return [Remainder] 気策(24分の1年)
20
+ SOLAR_TERM_AVERAGE = Const::Remainder::Solar::SOLAR_TERM_AVERAGE
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Integer] index 連番
26
+ # @param [Remainder] remainder 時刻情報(大余小余)
27
+ #
28
+ def initialize(index: -1, remainder: Remainder.new)
29
+ super(index: index, remainder: remainder, average: SOLAR_TERM_AVERAGE)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../abstract_version'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ #
8
+ # Daien 大衍暦
9
+ #
10
+ module Daien
11
+ #
12
+ # Gateway アクセサメソッド群
13
+ #
14
+ class Gateway < AbstractVersion
15
+ # @return [True] リリースあり
16
+ RELEASE = true
17
+
18
+ # @return [String] 暦クラス名
19
+ VERSION_NAME = 'Daien'
20
+
21
+ #
22
+ # 西暦日から和暦日に変換する
23
+ #
24
+ # @param [Date] western_date 西暦日
25
+ #
26
+ # @return [Result::Single] 和暦日
27
+ #
28
+ def self.to_japan_date(western_date:)
29
+ date = Western::Calendar.create(date: western_date)
30
+
31
+ context = Context.new(version_name: VERSION_NAME)
32
+ Calculation::Summary::Single.get(context: context, date: date)
33
+ end
34
+ end
35
+ end
36
+ end