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
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/abstract_average'
4
+
5
+ require_relative '../../const/remainder'
6
+
7
+ require_relative '../../cycle/solar_term'
8
+
9
+ require_relative '../origin/winter_solstice'
10
+
11
+ require_relative './location'
12
+
13
+ # :nodoc:
14
+ module Zakuro
15
+ # :nodoc:
16
+ module Daien
17
+ # :nodoc:
18
+ module Solar
19
+ #
20
+ # Average 平気(太陽軌道平均)
21
+ #
22
+ class Average < Calculation::Solar::AbstractAverage
23
+ #
24
+ # 初期化
25
+ #
26
+ # @param [Integer] western_year 西暦年
27
+ #
28
+ def initialize(western_year:)
29
+ solar_term = Average.first_solar_term(western_year: western_year)
30
+ super(solar_term: solar_term)
31
+ end
32
+
33
+ #
34
+ # 冬至から数えた1年データの月ごとに二十四節気を割り当てる
35
+ #
36
+ # @param [Array<Month>] annual_range 1年データ
37
+ #
38
+ # @return [Array<Month>] 1年データ
39
+ #
40
+ def set(annual_range:)
41
+ super(annual_range: annual_range)
42
+ end
43
+
44
+ #
45
+ # 計算開始する二十四節気を求める
46
+ #
47
+ # @param [Integer] western_year 西暦年
48
+ #
49
+ # @return [SolarTerm] 二十四節気
50
+ #
51
+ def self.first_solar_term(western_year:)
52
+ # 天正冬至
53
+ winter_solstice = Origin::WinterSolstice.get(western_year: western_year)
54
+
55
+ # 二十四節気(冬至)
56
+ solar_term = Cycle::SolarTerm.new(index: 0, remainder: winter_solstice)
57
+
58
+ first_solar_term_index = Average.calc_first_solar_term_index(western_year: western_year)
59
+
60
+ # 対象の二十四節気まで戻す
61
+ solar_term.prev_by_index(first_solar_term_index)
62
+
63
+ solar_term
64
+ end
65
+
66
+ # :reek:TooManyStatements { max_statements: 6 }
67
+
68
+ #
69
+ # 計算開始する二十四節気番号を求める
70
+ #
71
+ # * 前提として入定気は冬至の手前にある
72
+ # * 例えば、定気が大雪であれば入定気は大雪の範囲内にある
73
+ # * 入定気は、定気の開始位置に重複しない限り、常に定気より後にある
74
+ # * 基本的に定気の一つ前から起算すれば、当時から求めた11月(閏10/閏11月)に二十四節気を割り当てられる
75
+ #
76
+ # @param [Integer] western_year 西暦年
77
+ #
78
+ # @return [Integer] 二十四節気番号
79
+ #
80
+ def self.calc_first_solar_term_index(western_year:)
81
+ # 天正閏余
82
+ lunar_age = Origin::LunarAge.get(western_year: western_year)
83
+
84
+ solar_location = Solar::Location.new(lunar_age: lunar_age)
85
+ solar_location.run
86
+
87
+ solar_term_index = solar_location.index
88
+
89
+ # 入定気の一つ後の二十四節気まで戻す(ただし11月経朔が二十四節気上にある場合は戻さない)
90
+ # NOTE: 789年で大余0のパターンあり
91
+ solar_term_index += 1 unless solar_location.remainder.day.zero?
92
+
93
+ solar_term_index
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Daien
7
+ # :nodoc:
8
+ module Solar
9
+ #
10
+ # Interval 入気定日加減数(二十四節気の間隔)
11
+ #
12
+ module Interval
13
+ #
14
+ # 気策の 15-664.7 を加減する
15
+ #
16
+ # @note 『歴代天文律暦等志彙編 七』中華書房 p.2224 盈縮分の行で加減した
17
+ #
18
+ # @return [Hash<Symbol, Cycle::Remainder>] 一覧
19
+ MAP = {
20
+ # 冬至(とうじ)・大雪(たいせつ)
21
+ touji: Cycle::Remainder.new(day: 14, minute: 1351, second: 7), # -2353
22
+ taisetsu: Cycle::Remainder.new(day: 14, minute: 1351, second: 7),
23
+ # 小寒(しょうかん)・小雪(しょうせつ)
24
+ shoukan: Cycle::Remainder.new(day: 14, minute: 1859, second: 7), # -1845
25
+ shousetsu: Cycle::Remainder.new(day: 14, minute: 1859, second: 7),
26
+ # 大寒(だいかん)・立冬(りっとう)
27
+ daikan: Cycle::Remainder.new(day: 14, minute: 2314, second: 7), # -1390
28
+ rittou: Cycle::Remainder.new(day: 14, minute: 2314, second: 7),
29
+ # 立春(りっしゅん)・霜降(そうこう)
30
+ risshun: Cycle::Remainder.new(day: 14, minute: 2728, second: 7), # -976
31
+ soukou: Cycle::Remainder.new(day: 14, minute: 2728, second: 7),
32
+ # 雨水(うすい)・寒露(かんろ)
33
+ usui: Cycle::Remainder.new(day: 15, minute: 76, second: 7), # -588
34
+ kanro: Cycle::Remainder.new(day: 15, minute: 76, second: 7),
35
+ # 啓蟄(けいちつ)・秋分(しゅうぶん)
36
+ keichitsu: Cycle::Remainder.new(day: 15, minute: 450, second: 7), # -214
37
+ shuubun: Cycle::Remainder.new(day: 15, minute: 450, second: 7),
38
+ # 春分(しゅんぶん)・白露(はくろ)
39
+ shunbun: Cycle::Remainder.new(day: 15, minute: 878, second: 7), # +214
40
+ hakuro: Cycle::Remainder.new(day: 15, minute: 878, second: 7),
41
+ # 清明(せいめい)・処暑(しょしょ)
42
+ seimei: Cycle::Remainder.new(day: 15, minute: 1252, second: 7), # +588
43
+ shosho: Cycle::Remainder.new(day: 15, minute: 1252, second: 7),
44
+ # 穀雨(こくう)・立秋(りっしゅう)
45
+ kokuu: Cycle::Remainder.new(day: 15, minute: 1640, second: 7), # +976
46
+ risshuu: Cycle::Remainder.new(day: 15, minute: 1640, second: 7),
47
+ # 立夏(りっか)・大暑(たいしょ)
48
+ rikka: Cycle::Remainder.new(day: 15, minute: 2054, second: 7), # +1390
49
+ taisho: Cycle::Remainder.new(day: 15, minute: 2054, second: 7),
50
+ # 小満(しょうまん)・小暑(しょうしょ)
51
+ shouman: Cycle::Remainder.new(day: 15, minute: 2509, second: 7), # +1845
52
+ shousho: Cycle::Remainder.new(day: 15, minute: 2509, second: 7),
53
+ # 芒種(ぼうしゅ)・夏至(げし)
54
+ boushu: Cycle::Remainder.new(day: 15, minute: 3017, second: 7), # +2353
55
+ geshi: Cycle::Remainder.new(day: 15, minute: 3017, second: 7)
56
+ }.freeze
57
+
58
+ # @return [Array<Remainder>] 索引
59
+ LIST = [
60
+ MAP[:touji], # 0
61
+ MAP[:shoukan], # 1
62
+ MAP[:daikan], # 2
63
+ MAP[:risshun], # 3
64
+ MAP[:usui], # 4
65
+ MAP[:keichitsu], # 5
66
+ MAP[:shunbun], # 6
67
+ MAP[:seimei], # 7
68
+ MAP[:kokuu], # 8
69
+ MAP[:rikka], # 9
70
+ MAP[:shouman], # 10
71
+ MAP[:boushu], # 11
72
+ MAP[:geshi], # 12
73
+ MAP[:shousho], # 13
74
+ MAP[:taisho], # 14
75
+ MAP[:risshuu], # 15
76
+ MAP[:shosho], # 16
77
+ MAP[:hakuro], # 17
78
+ MAP[:shuubun], # 18
79
+ MAP[:kanro], # 19
80
+ MAP[:soukou], # 20
81
+ MAP[:rittou], # 21
82
+ MAP[:shousetsu], # 22
83
+ MAP[:taisetsu] # 23
84
+ ].freeze
85
+
86
+ #
87
+ # 入気定日加減数を引き当てる
88
+ #
89
+ # @param [Integer] index 二十四節気番号
90
+ #
91
+ # @return [Cycle::Remainder] 入気定日加減数
92
+ #
93
+ def self.index_of(index)
94
+ LIST[index]
95
+ end
96
+
97
+ #
98
+ # 入気定日加減数の総数を返す
99
+ #
100
+ # @return [Integer] 入気定日加減数の総数
101
+ #
102
+ def self.size
103
+ LIST.size
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/abstract_location'
4
+
5
+ require_relative '../../const/remainder'
6
+
7
+ require_relative './interval'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Daien
13
+ # :nodoc:
14
+ module Solar
15
+ #
16
+ # Location 入定気
17
+ #
18
+ class Location < Calculation::Solar::AbstractLocation
19
+ # @return [Cycle::Remainder] 弦
20
+ QUARTER = Const::Remainder::Solar::QUARTER
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Cycle::Remainder] lunar_age 天正閏余(大余小余)
26
+ #
27
+ def initialize(lunar_age:)
28
+ super(lunar_age: lunar_age, quarter: QUARTER)
29
+ end
30
+
31
+ # :reek:UtilityFunction
32
+
33
+ #
34
+ # 二十四節気番号に対応する入気定日加減数を返す
35
+ #
36
+ # @note 継承のためクラスメソッドにしない
37
+ #
38
+ # @param [Integer] index 二十四節気番号
39
+ #
40
+ # @return [Cycle::Remainder] 入気定日加減数
41
+ #
42
+ def interval(index:)
43
+ Interval.index_of(index)
44
+ end
45
+
46
+ # :reek:UtilityFunction
47
+
48
+ #
49
+ # 入気定日加減数の要素数を返す
50
+ #
51
+ # @note 継承のためクラスメソッドにしない
52
+ #
53
+ # @return [Integer] 入気定日加減数の要素数
54
+ #
55
+ def interval_size
56
+ Interval.size
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../../calculation/stella/solar/choukei_value'
4
+
5
+ require_relative '../../const/number'
6
+
7
+ require_relative './adjustment'
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ # :nodoc:
12
+ module Daien
13
+ # :nodoc:
14
+ module Solar
15
+ #
16
+ # Value 太陽補正値
17
+ #
18
+ module Value
19
+ #
20
+ # 太陽の運行による補正値を算出する
21
+ #
22
+ # @param [SolarTerm] solar_location 入定気
23
+ #
24
+ # @return [Integer] 補正値
25
+ #
26
+ def self.get(solar_location:)
27
+ remainder = solar_location.remainder
28
+
29
+ row = Adjustment.specify(index: solar_location.index)
30
+
31
+ Calculation::Solar::ChoukeiValue.get(remainder: remainder, row: row)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Genka
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日=752分)
20
+ DAY = 752
21
+ # @return [Integer] 度法(1日=304分)
22
+ TERM_DAY = 304
23
+ # @return [Integer] 朔望月
24
+ SYNODIC_MONTH = 22_207
25
+ end
26
+
27
+ #
28
+ # 累積
29
+ #
30
+ module Stack
31
+ # @return [Integer] 積年(甲子夜半朔旦冬至〜暦の開始前)
32
+ TOTAL_YEAR = 5703
33
+ # @return [Integer] 暦の開始年(元嘉20年)
34
+ BEGIN_YEAR = 443
35
+ # @return [Integer] 西暦0年の積年
36
+ WESTERN_YEAR = 1612
37
+ # @return [Integer] 余数
38
+ YEAR_REMAINDER = 1595
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../cycle/remainder'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Genka
9
+ #
10
+ # Const 定数
11
+ #
12
+ module Const
13
+ #
14
+ # Remainder 大余小余
15
+ #
16
+ module Remainder
17
+ #
18
+ # @note 『歴代天文律暦等志彙編 六』中華書房 p.1727
19
+ # 「推弦望法..加朔大餘七,小餘二百八十七,小分三,小分満四從小餘」
20
+ #
21
+ # @return [Cycle::Remainder] 弦(1分=4秒)
22
+ QUARTER = Cycle::Remainder.new(day: 7, minute: 287, second: 3)
23
+
24
+ #
25
+ # @note 『歴代天文律暦等志彙編 六』中華書房 p.1727
26
+ # 「推二十四氣術」「求次氣,加朔大餘十五,小餘六十六,小分十一,小分満氣法從小餘,小餘満度法從大餘」
27
+ #
28
+ # @return [Cycle::Remainder] 気策(24分の1年)
29
+ SOLAR_TERM_AVERAGE = Cycle::TermRemainder.new(day: 15, minute: 66 + 11.0 / 24, second: 0)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,92 @@
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 Genka
11
+ # :nodoc:
12
+ module Cycle
13
+ #
14
+ # Remainder 時刻情報(大余小余)
15
+ #
16
+ class Remainder < Calculation::Cycle::AbstractRemainder
17
+ #
18
+ # @note 『歴代天文律暦等志彙編 六』中華書房 p.1727
19
+ # 「推弦望法..加朔大餘七,小餘二百八十七,小分三,小分満四從小餘」
20
+ #
21
+ # @return [Integer] 分(1分=4秒)
22
+ MINUTE = 4
23
+
24
+ #
25
+ # 初期化
26
+ #
27
+ # @param [Integer] day 大余("日"に相当)
28
+ # @param [Integer] minute 小余("分"に相当)
29
+ # @param [Integer] second 秒
30
+ # @param [Integer] total 繰り上げなしの小余
31
+ #
32
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
33
+ super(base_day: Const::Number::Cycle::DAY, base_mitune: MINUTE,
34
+ day: day, minute: minute, second: second, total: total)
35
+ end
36
+
37
+ #
38
+ # 特定の文字フォーマットにして出力する
39
+ #
40
+ # @return [String] フォーマットした結果
41
+ #
42
+ def format(form: '%.4f', digit: 4)
43
+ return '' if invalid?
44
+
45
+ decimal = @day + @minute / @base_day.to_f
46
+ super(form, decimal.round(digit))
47
+ end
48
+ end
49
+
50
+ #
51
+ # TermRemainder 時刻情報(大余小余)
52
+ #
53
+ class TermRemainder < Calculation::Cycle::AbstractRemainder
54
+ #
55
+ # @note 『歴代天文律暦等志彙編 六』中華書房 p.1726
56
+ # 「氣法,二十四」
57
+ #
58
+ # @return [Integer] 分(1分=24秒)
59
+ MINUTE = 24
60
+
61
+ #
62
+ # 初期化
63
+ #
64
+ # @param [Integer] day 大余("日"に相当)
65
+ # @param [Integer] minute 小余("分"に相当)
66
+ # @param [Integer] second 秒
67
+ # @param [Integer] total 繰り上げなしの小余
68
+ #
69
+ def initialize(day: -1, minute: -1, second: -1, total: -1)
70
+ super(base_day: Const::Number::Cycle::TERM_DAY, base_mitune: MINUTE,
71
+ day: day, minute: minute, second: second, total: total)
72
+ end
73
+
74
+ #
75
+ # 特定の文字フォーマットにして出力する
76
+ #
77
+ # @return [String] フォーマットした結果
78
+ #
79
+ def format(form: '%.4f', digit: 4)
80
+ return '' if invalid?
81
+
82
+ decimal = @day + @minute / @base_day.to_f
83
+ # NOTE: roundなしで format を使用した場合は、四捨五入が正しく実行されないことが判明した
84
+ # 具体的には、468年の中気は '55.7813' だが '55.7812' になる
85
+ # これは '55.7812500' を4桁にした際に、境界値の少数点以下5桁目の '5' が切り捨てを受けたためである
86
+ # format による四捨五入は避け、roundによる四捨五入を採用する
87
+ super(form, decimal.round(digit))
88
+ end
89
+ end
90
+ end
91
+ end
92
+ 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 Genka
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_TERM_AVERAGE
21
+
22
+ #
23
+ # 初期化
24
+ #
25
+ # @param [Integer] index 連番
26
+ # @param [Remainder] remainder 時刻情報(大余小余)
27
+ #
28
+ def initialize(index: -1, remainder: TermRemainder.new)
29
+ super(index: index, remainder: remainder, average: SOLAR_TERM_AVERAGE)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,19 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../abstract_version'
4
-
5
3
  # :nodoc:
6
4
  module Zakuro
7
5
  #
8
6
  # Genka 元嘉暦
9
7
  #
10
8
  module Genka
11
- #
12
- # Gateway アクセサメソッド群
13
- #
14
- class Gateway < AbstractVersion
15
- # @return [False] リリースなし
16
- RELEASE = false
17
- end
9
+ # none
18
10
  end
19
11
  end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../const/remainder'
4
+
5
+ require_relative '../cycle/solar_term'
6
+
7
+ require_relative '../stella/origin/first_term'
8
+
9
+ require_relative '../stella/origin/january'
10
+
11
+ # :nodoc:
12
+ module Zakuro
13
+ # :nodoc:
14
+ module Genka
15
+ # :nodoc:
16
+ module Monthly
17
+ #
18
+ # LunarPhase 月の位相
19
+ #
20
+ class LunarPhase
21
+ # @return [Cycle::Remainder] 弦
22
+ QUARTER = Const::Remainder::QUARTER
23
+
24
+ # TODO: AbstractLunarPhase でも使用している
25
+
26
+ # @return [Array<String>] 月内の弦
27
+ PHASE_INDEXES = %w[朔日 上弦 望月 下弦].freeze
28
+
29
+ # @return [Cycle::AbstractRemainder] 経
30
+ attr_reader :remainder
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [Cycle::Remainder] remainder 正月経朔
36
+ #
37
+ def initialize(remainder:)
38
+ # 経
39
+ @remainder = remainder
40
+
41
+ # 弦の位置
42
+ @index = 0
43
+ end
44
+
45
+ #
46
+ # 次の弦に進める
47
+ #
48
+ # @return [Remainder] 定朔
49
+ #
50
+ def next_phase
51
+ adjusted = remainder.clone
52
+
53
+ add_quarter_moon_size
54
+
55
+ adjusted
56
+ end
57
+
58
+ #
59
+ # 次の月に進める
60
+ # @note 進めた後の月の定朔ではなく、当月のものを返却する
61
+ #
62
+ # @return [Remainder] 当月初の定朔
63
+ #
64
+ def next_month
65
+ result = nil
66
+ PHASE_INDEXES.each_with_index do |_phase, index|
67
+ adjust = next_phase
68
+ result = adjust if index.zero?
69
+ end
70
+
71
+ result
72
+ end
73
+
74
+ private
75
+
76
+ #
77
+ # 次の弦に進める
78
+ #
79
+ # @return [Integer] 弦
80
+ #
81
+ def next_index
82
+ @index += 1
83
+ @index = 0 if @index >= PHASE_INDEXES.size
84
+ @index
85
+ end
86
+
87
+ def add_quarter_moon_size
88
+ @remainder.add!(QUARTER)
89
+
90
+ next_index
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../calculation/range/medieval_annual_range'
4
+ require_relative '../../../output/logger'
5
+ require_relative '../monthly/lunar_phase'
6
+ require_relative '../stella/solar/average'
7
+
8
+ # :nodoc:
9
+ module Zakuro
10
+ # :nodoc:
11
+ module Genka
12
+ # :nodoc:
13
+ module Range
14
+ #
15
+ # AnnualRange 年間範囲
16
+ #
17
+ module AnnualRange
18
+ # @return [Output::Logger] ロガー
19
+ LOGGER = Output::Logger.new(location: 'annual_range')
20
+
21
+ #
22
+ # 一覧取得する
23
+ #
24
+ # * 対象年に対して、当年1月-翌年1月までを出力する
25
+ # * 対象年(西暦)と計算年(元号x年)の紐付けは行わない
26
+ #
27
+ # @param [Context] context 暦コンテキスト
28
+ # @param [Integer] western_year 西暦年
29
+ #
30
+ # @return [Array<Month>] 1年データ
31
+ #
32
+ def self.get(context:, western_year:)
33
+ # 正月中気
34
+ solar_term = Cycle::SolarTerm.new(
35
+ index: 4, remainder: Origin::FirstTerm.get(western_year: western_year)
36
+ )
37
+ # 正月に立春が含まれる可能性があるので、立春まで戻しておく
38
+ solar_term.prev_term!
39
+
40
+ # 経
41
+ remainder = Origin::January.get(western_year: western_year)
42
+
43
+ lunar_phase = Monthly::LunarPhase.new(remainder: remainder)
44
+
45
+ solar_average = Solar::Average.new(solar_term: solar_term)
46
+
47
+ annual_range = Calculation::Range::MedievalAnnualRange.get(
48
+ context: context, lunar_phase: lunar_phase, solar_average: solar_average
49
+ )
50
+
51
+ pop_months_on_next_year(annual_range: annual_range)
52
+ end
53
+
54
+ #
55
+ # 来年の月を除去する
56
+ #
57
+ # @param [Array<Month>] annual_range 1年データ
58
+ #
59
+ # @return [Array<Month>] 1年データ
60
+ #
61
+ def self.pop_months_on_next_year(annual_range:)
62
+ result = []
63
+ number = 0
64
+ annual_range.each do |month|
65
+ # 来年
66
+ break if number > month.month_label.number
67
+
68
+ number = month.month_label.number
69
+ result.push(month)
70
+ end
71
+
72
+ result
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end