zakuro 0.9.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +41 -8
- data/VERSION +1 -1
- data/doc/gengou.md +1 -1
- data/doc/operation/csv/month.csv +8 -9
- data/doc/operation/operation.xlsx +0 -0
- data/images/logo-text.png +0 -0
- data/lib/zakuro/calculation/base/gengou.rb +2 -4
- data/lib/zakuro/calculation/base/year.rb +1 -1
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +6 -0
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +2 -2
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +4 -2
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +1 -1
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +13 -7
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +18 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +6 -2
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +5 -2
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +12 -4
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +10 -4
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +3 -3
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +1 -1
- data/lib/zakuro/calculation/monthly/internal/date_comparer.rb +78 -0
- data/lib/zakuro/calculation/monthly/{meta → internal/meta}/all_solar_term.rb +1 -1
- data/lib/zakuro/calculation/monthly/{meta → internal/meta}/meta_collector.rb +2 -2
- data/lib/zakuro/calculation/monthly/{first_day.rb → internal/part/first_day.rb} +2 -2
- data/lib/zakuro/calculation/monthly/{meta.rb → internal/part/meta.rb} +1 -1
- data/lib/zakuro/calculation/monthly/internal/solar_term_selector.rb +203 -0
- data/lib/zakuro/calculation/monthly/month.rb +38 -74
- data/lib/zakuro/calculation/monthly/operated_month.rb +7 -2
- data/lib/zakuro/calculation/option/dropped_date/location.rb +8 -1
- data/lib/zakuro/calculation/range/dated_full_range.rb +6 -3
- data/lib/zakuro/calculation/range/dated_operation_range.rb +2 -1
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +0 -2
- data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +24 -10
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +3 -3
- data/lib/zakuro/calculation/summary/internal/option/dropped_date.rb +102 -0
- data/lib/zakuro/calculation/summary/internal/option/vanished_date.rb +111 -0
- data/lib/zakuro/calculation/summary/internal/option.rb +4 -137
- data/lib/zakuro/calculation/summary/japan/range.rb +4 -5
- data/lib/zakuro/calculation/summary/western/range.rb +8 -1
- data/lib/zakuro/calculation/summary/western/single.rb +10 -5
- data/lib/zakuro/context/version_class_resolver.rb +5 -5
- data/lib/zakuro/era/japan/calendar.rb +4 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +2 -2
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +2 -2
- data/lib/zakuro/era/japan/gengou/alignment.rb +35 -6
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +17 -16
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +3 -394
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +2 -2
- data/lib/zakuro/era/japan/gengou.rb +8 -6
- data/lib/zakuro/era/japan/type/base/both/date.rb +51 -0
- data/lib/zakuro/era/japan/type/base/both/year.rb +53 -0
- data/lib/zakuro/era/japan/type/base/gengou.rb +177 -0
- data/lib/zakuro/era/japan/type/base/gengou_set.rb +78 -0
- data/lib/zakuro/era/japan/type/base/switch_date.rb +74 -0
- data/lib/zakuro/era/japan/type/base/version_range.rb +189 -0
- data/lib/zakuro/era/japan/type/validation/both/date.rb +99 -0
- data/lib/zakuro/era/japan/type/validation/both/year.rb +75 -0
- data/lib/zakuro/era/japan/type/validation/gengou.rb +93 -0
- data/lib/zakuro/era/japan/type/validation/gengou_set.rb +133 -0
- data/lib/zakuro/era/japan/type/validation/switch_date.rb +73 -0
- data/lib/zakuro/era/japan/type/validation/version_range.rb +109 -0
- data/lib/zakuro/era/japan/type/validation/version_root.rb +102 -0
- data/lib/zakuro/era/japan/version/resource/parser.rb +266 -0
- data/lib/zakuro/era/japan/version/resource/validator.rb +37 -0
- data/lib/zakuro/era/japan/version/resource/yaml/version.yaml +80 -0
- data/lib/zakuro/era/japan/version/resource.rb +22 -0
- data/lib/zakuro/era/japan/version.rb +4 -115
- data/lib/zakuro/era/western/calendar.rb +2 -2
- data/lib/zakuro/exception/zakuro_error.rb +1 -1
- data/lib/zakuro/merchant.rb +5 -5
- data/lib/zakuro/operation/month/parser.rb +2 -2
- data/lib/zakuro/operation/yaml/month.yaml +8 -40
- data/lib/zakuro/output/logger.rb +4 -4
- data/lib/zakuro/parameter/catalog/basis_date.rb +55 -0
- data/lib/zakuro/parameter/catalog/column.rb +57 -0
- data/lib/zakuro/parameter/catalog/option.rb +60 -0
- data/lib/zakuro/parameter/catalog/range.rb +81 -0
- data/lib/zakuro/parameter/condition.rb +108 -0
- data/lib/zakuro/result/core.rb +2 -2
- data/lib/zakuro/{tools → tool}/remainder_comparer.rb +3 -2
- data/lib/zakuro/{tools → tool}/stringifier.rb +3 -3
- data/lib/zakuro/{tools → tool}/typeconv.rb +2 -2
- data/lib/zakuro/{tools → tool}/typeof.rb +2 -2
- data/lib/zakuro/version/daien/const/number.rb +42 -39
- data/lib/zakuro/version/daien/const/remainder.rb +38 -35
- data/lib/zakuro/version/daien/cycle/remainder.rb +77 -74
- data/lib/zakuro/version/daien/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/daien/daien.rb +8 -5
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +67 -64
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +15 -12
- data/lib/zakuro/version/daien/option/vanished_date/parameter.rb +15 -12
- data/lib/zakuro/version/daien/range/annual_range.rb +27 -24
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +209 -206
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +32 -29
- data/lib/zakuro/version/daien/stella/lunar/location.rb +53 -50
- data/lib/zakuro/version/daien/stella/lunar/value.rb +65 -62
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +23 -20
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +42 -39
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +44 -41
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +74 -71
- data/lib/zakuro/version/daien/stella/solar/average.rb +68 -65
- data/lib/zakuro/version/daien/stella/solar/interval.rb +95 -92
- data/lib/zakuro/version/daien/stella/solar/location.rb +41 -38
- data/lib/zakuro/version/daien/stella/solar/value.rb +21 -18
- data/lib/zakuro/version/genka/const/number.rb +31 -28
- data/lib/zakuro/version/genka/const/remainder.rb +20 -17
- data/lib/zakuro/version/genka/cycle/remainder.rb +72 -69
- data/lib/zakuro/version/genka/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/genka/genka.rb +8 -5
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +82 -79
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +13 -10
- data/lib/zakuro/version/genka/option/vanished_date/parameter.rb +13 -10
- data/lib/zakuro/version/genka/range/annual_range.rb +57 -54
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +44 -41
- data/lib/zakuro/version/genka/stella/origin/january.rb +38 -35
- data/lib/zakuro/version/genka/stella/solar/average.rb +24 -21
- data/lib/zakuro/version/gihou/const/number.rb +40 -37
- data/lib/zakuro/version/gihou/const/remainder.rb +32 -29
- data/lib/zakuro/version/gihou/cycle/remainder.rb +38 -35
- data/lib/zakuro/version/gihou/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/gihou/gihou.rb +8 -5
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +68 -65
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +13 -10
- data/lib/zakuro/version/gihou/option/vanished_date/parameter.rb +13 -10
- data/lib/zakuro/version/gihou/range/annual_range.rb +27 -24
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +212 -209
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +32 -29
- data/lib/zakuro/version/gihou/stella/lunar/location.rb +53 -50
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +65 -62
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +23 -20
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +42 -39
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +44 -41
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +74 -71
- data/lib/zakuro/version/gihou/stella/solar/average.rb +67 -64
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +95 -92
- data/lib/zakuro/version/gihou/stella/solar/location.rb +41 -38
- data/lib/zakuro/version/gihou/stella/solar/value.rb +21 -18
- data/lib/zakuro/version/gregorio/gregorio.rb +8 -5
- data/lib/zakuro/version/houryaku/houryaku.rb +8 -5
- data/lib/zakuro/version/joukyou/joukyou.rb +8 -5
- data/lib/zakuro/version/kansei/kansei.rb +8 -5
- data/lib/zakuro/version/senmyou/const/number.rb +40 -37
- data/lib/zakuro/version/senmyou/const/remainder.rb +35 -32
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +74 -71
- data/lib/zakuro/version/senmyou/cycle/solar_term.rb +18 -15
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +69 -66
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +15 -12
- data/lib/zakuro/version/senmyou/option/vanished_date/parameter.rb +15 -12
- data/lib/zakuro/version/senmyou/range/annual_range.rb +27 -24
- data/lib/zakuro/version/senmyou/senmyou.rb +8 -5
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +206 -203
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +32 -29
- data/lib/zakuro/version/senmyou/stella/lunar/location.rb +60 -57
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +66 -63
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +23 -20
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +42 -39
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +44 -41
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +74 -71
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +67 -64
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +93 -90
- data/lib/zakuro/version/senmyou/stella/solar/location.rb +41 -38
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +23 -20
- data/lib/zakuro/version/tenpou/tenpou.rb +8 -5
- metadata +40 -15
- data/lib/zakuro/condition.rb +0 -306
- data/lib/zakuro/era/japan/gengou/resource/type.rb +0 -356
- /data/lib/zakuro/calculation/monthly/{operated_solar_term.rb → internal/operated_solar_term.rb} +0 -0
- /data/lib/zakuro/calculation/monthly/{const.rb → internal/part/const.rb} +0 -0
- /data/lib/zakuro/calculation/monthly/{month_label.rb → internal/part/month_label.rb} +0 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nodoc:
|
4
|
+
module Zakuro
|
5
|
+
# :nodoc:
|
6
|
+
module Calculation
|
7
|
+
# :nodoc:
|
8
|
+
module Monthly
|
9
|
+
#
|
10
|
+
# DateComparer 日付比較
|
11
|
+
#
|
12
|
+
module DateComparer
|
13
|
+
class << self
|
14
|
+
#
|
15
|
+
# 範囲内か
|
16
|
+
#
|
17
|
+
# @param [Western::Calendar] date 日付
|
18
|
+
# @param [Western::Calendar] start_date 開始日
|
19
|
+
# @param [Western::Calendar] last_date 終了日
|
20
|
+
#
|
21
|
+
# @return [True] 範囲内
|
22
|
+
# @return [False] 範囲外
|
23
|
+
#
|
24
|
+
def include?(date:, start_date:, last_date:)
|
25
|
+
return false if start_date.invalid?
|
26
|
+
|
27
|
+
return false if date < start_date
|
28
|
+
|
29
|
+
return false if date > last_date
|
30
|
+
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# 範囲内か
|
36
|
+
#
|
37
|
+
# @param [Japan::Calendar] date 日付
|
38
|
+
# @param [Base::Gengou] gengou 元号
|
39
|
+
# @param [MonthLabel] month_label 月表示名
|
40
|
+
#
|
41
|
+
# @return [True] 範囲内
|
42
|
+
# @return [False] 範囲外
|
43
|
+
#
|
44
|
+
def include_by_japan_date?(date:, gengou:, month_label:)
|
45
|
+
linear_gengou = gengou.match_by_name(name: date.gengou)
|
46
|
+
|
47
|
+
return false if linear_gengou.invalid?
|
48
|
+
|
49
|
+
return false unless linear_gengou.name == date.gengou
|
50
|
+
|
51
|
+
return false unless linear_gengou.year == date.year
|
52
|
+
|
53
|
+
same_by_japan_date?(month_label: month_label, date: date)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
#
|
59
|
+
# 同一の月情報かを検証する
|
60
|
+
#
|
61
|
+
# @param [MonthLabel] month_label 月表示名
|
62
|
+
# @param [Japan::Calendar] date 日付
|
63
|
+
#
|
64
|
+
# @return [True] 同一の月
|
65
|
+
# @return [False] 異なる月
|
66
|
+
#
|
67
|
+
def same_by_japan_date?(month_label:, date: Japan::Calendar.new)
|
68
|
+
return false unless month_label.number == date.month
|
69
|
+
|
70
|
+
return false unless month_label.leaped == date.leaped
|
71
|
+
|
72
|
+
true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -48,7 +48,7 @@ module Zakuro
|
|
48
48
|
|
49
49
|
first = all_solar_terms[0].clone
|
50
50
|
|
51
|
-
return all_solar_terms if before_solar_terms.
|
51
|
+
return all_solar_terms if before_solar_terms.empty?
|
52
52
|
|
53
53
|
# 最初の二十四節気が月初日と同日であれば何もしない
|
54
54
|
return all_solar_terms if first.remainder.day == remainder.day
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative '../../../../era/western/calendar'
|
4
4
|
|
5
|
-
require_relative '
|
5
|
+
require_relative '../../../cycle/abstract_remainder'
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
@@ -0,0 +1,203 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../cycle/abstract_solar_term'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
# :nodoc:
|
8
|
+
module Calculation
|
9
|
+
# :nodoc:
|
10
|
+
module Monthly
|
11
|
+
#
|
12
|
+
# SolarTermSelector 二十四節気検索
|
13
|
+
#
|
14
|
+
class SolarTermSelector
|
15
|
+
# @return [Integer] 月最後の二十四節気を検索する大余の範囲上限
|
16
|
+
LAST_DAY_LIMIT = 20
|
17
|
+
|
18
|
+
# @return [Context::Context] 暦コンテキスト
|
19
|
+
attr_reader :context
|
20
|
+
# @return [Array<Cyle::AbstractSolarTerm>] 二十四節気
|
21
|
+
attr_reader :solar_terms
|
22
|
+
|
23
|
+
#
|
24
|
+
# 初期化
|
25
|
+
#
|
26
|
+
# @param [Context::Context] context 暦コンテキスト
|
27
|
+
# @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
|
28
|
+
#
|
29
|
+
def initialize(context: Context::Context.new, solar_terms: [])
|
30
|
+
@context = context
|
31
|
+
@solar_terms = solar_terms
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# 二十四節気が未設定かどうかを検証する
|
36
|
+
#
|
37
|
+
# @return [True] 設定なし
|
38
|
+
# @return [False] 設定あり
|
39
|
+
#
|
40
|
+
def empty?
|
41
|
+
solar_terms.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# 中気を返す
|
46
|
+
#
|
47
|
+
# @return [Cycle::AbstractSolarTerm] 中気
|
48
|
+
#
|
49
|
+
def even_term
|
50
|
+
solar_terms.each do |term|
|
51
|
+
return term if term.index.even?
|
52
|
+
end
|
53
|
+
|
54
|
+
context.resolver.solar_term.new
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# 節気を返す
|
59
|
+
#
|
60
|
+
# @return [Cycle::AbstractSolarTerm] 節気
|
61
|
+
#
|
62
|
+
def odd_term
|
63
|
+
solar_terms.each do |term|
|
64
|
+
return term if term.index.odd?
|
65
|
+
end
|
66
|
+
|
67
|
+
context.resolver.solar_term.new
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# 二十四節気を追加する
|
72
|
+
#
|
73
|
+
# @param [Cycle::AbstractSolarTerm] term 二十四節気
|
74
|
+
#
|
75
|
+
def add_term(term:)
|
76
|
+
solar_terms.push(term)
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# 二十四節気を正しい順序にソートする
|
81
|
+
#
|
82
|
+
def sort
|
83
|
+
sorted = (solar_terms.sort do |termx, termy|
|
84
|
+
termx.index <=> termy.index
|
85
|
+
end)
|
86
|
+
|
87
|
+
unless reset_term?(solar_terms: sorted)
|
88
|
+
@solar_terms = sorted
|
89
|
+
return
|
90
|
+
end
|
91
|
+
|
92
|
+
@solar_terms = reset(terms: sorted)
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# 大余に対応する二十四節気
|
97
|
+
#
|
98
|
+
# @param [Integer] day 大余
|
99
|
+
#
|
100
|
+
# @return [Cycle::AbstractSolarTerm] 二十四節気
|
101
|
+
#
|
102
|
+
|
103
|
+
#
|
104
|
+
# 大余に対応する二十四節気
|
105
|
+
#
|
106
|
+
# @param [Integer] day 大余
|
107
|
+
# @param [Meta] meta メタ情報
|
108
|
+
#
|
109
|
+
# @return [Cycle::AbstractSolarTerm] 二十四節気
|
110
|
+
#
|
111
|
+
def solar_term_by_day(day:, meta:)
|
112
|
+
target = context.resolver.remainder.new(day: day, minute: 0, second: 0)
|
113
|
+
|
114
|
+
meta.all_solar_terms.each_cons(2) do |current_solar_term, next_solar_term|
|
115
|
+
in_range = Tool::RemainderComparer.in_range?(
|
116
|
+
target: target, start: current_solar_term.remainder, last: next_solar_term.remainder
|
117
|
+
)
|
118
|
+
return current_solar_term if in_range
|
119
|
+
end
|
120
|
+
|
121
|
+
last_solar_term(target: target, meta: meta)
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
#
|
127
|
+
# 二十四節気の折り返し(23 -> 0)があるか
|
128
|
+
#
|
129
|
+
# @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
|
130
|
+
#
|
131
|
+
# @return [True] 折り返しあり
|
132
|
+
# @return [False] 折り返しなし
|
133
|
+
#
|
134
|
+
def reset_term?(solar_terms: [])
|
135
|
+
first = false
|
136
|
+
last = false
|
137
|
+
|
138
|
+
solar_terms.each do |term|
|
139
|
+
index = term.index
|
140
|
+
case index
|
141
|
+
when Cycle::AbstractSolarTerm::FIRST_INDEX
|
142
|
+
first = true
|
143
|
+
when Cycle::AbstractSolarTerm::LAST_INDEX
|
144
|
+
last = true
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
first && last
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# 二十四節気を終端で折り返す
|
153
|
+
#
|
154
|
+
# @param [Array<Cyle::AbstractSolarTerm>] terms 二十四節気
|
155
|
+
#
|
156
|
+
# @return [Array<Cyle::AbstractSolarTerm>] 折り返し済みの二十四節気
|
157
|
+
#
|
158
|
+
def reset(terms: [])
|
159
|
+
first = []
|
160
|
+
second = []
|
161
|
+
|
162
|
+
terms.each do |term|
|
163
|
+
# NOTE: 二十四節気は最大3つとすると、 「23, 0」「22, 23, 0」「23, 0, 1」 での折り返しが考えられる
|
164
|
+
if term.index >= (Cycle::AbstractSolarTerm::LAST_INDEX - 2)
|
165
|
+
second.push(term)
|
166
|
+
next
|
167
|
+
end
|
168
|
+
|
169
|
+
first.push(term)
|
170
|
+
end
|
171
|
+
|
172
|
+
# 0以前を先頭にする
|
173
|
+
second += first
|
174
|
+
|
175
|
+
second
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# 最後の二十四節気を返す
|
180
|
+
#
|
181
|
+
# @param [Cycle::AbstractRemainder] target 対象の大余情報
|
182
|
+
# @param [Meta] meta メタ情報
|
183
|
+
#
|
184
|
+
# @return [Cycle::AbstractSolarTerm] 二十四節気
|
185
|
+
#
|
186
|
+
def last_solar_term(target:, meta:)
|
187
|
+
last = meta.all_solar_terms[-1]
|
188
|
+
|
189
|
+
empty_solar_term = context.resolver.solar_term.new
|
190
|
+
|
191
|
+
return empty_solar_term unless last
|
192
|
+
|
193
|
+
if Tool::RemainderComparer.in_limit?(target: target, start: last.remainder,
|
194
|
+
limit: LAST_DAY_LIMIT)
|
195
|
+
return last
|
196
|
+
end
|
197
|
+
|
198
|
+
empty_solar_term
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../cycle/abstract_solar_term'
|
4
|
+
|
3
5
|
require_relative '../base/gengou'
|
4
|
-
require_relative './first_day'
|
5
|
-
require_relative './meta'
|
6
|
-
require_relative './month_label'
|
7
|
-
require_relative './meta/meta_collector'
|
6
|
+
require_relative './internal/part/first_day'
|
7
|
+
require_relative './internal/part/meta'
|
8
|
+
require_relative './internal/part/month_label'
|
9
|
+
require_relative './internal/meta/meta_collector'
|
10
|
+
|
11
|
+
require_relative './internal/solar_term_selector'
|
12
|
+
require_relative './internal/date_comparer'
|
8
13
|
|
9
14
|
# :nodoc:
|
10
15
|
module Zakuro
|
@@ -22,8 +27,8 @@ module Zakuro
|
|
22
27
|
attr_reader :month_label
|
23
28
|
# @return [FirstDay] 月初日(朔日)
|
24
29
|
attr_reader :first_day
|
25
|
-
# @return [
|
26
|
-
attr_reader :
|
30
|
+
# @return [SolarTermSelector] 二十四節気検索
|
31
|
+
attr_reader :solar_term_selector
|
27
32
|
# @return [Base::Gengou] 元号
|
28
33
|
attr_reader :gengou
|
29
34
|
# @return [Meta] 付加情報
|
@@ -37,7 +42,7 @@ module Zakuro
|
|
37
42
|
# @param [Context::Context] context 暦コンテキスト
|
38
43
|
# @param [MonthLabel] month_label 月表示名
|
39
44
|
# @param [FirstDay] first_day 月初日(朔日)
|
40
|
-
# @param [Array<AbstractSolarTerm>] solar_terms 二十四節気
|
45
|
+
# @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
|
41
46
|
# @param [Base::Gengou] gengou 元号
|
42
47
|
# @param [Meta] meta 付加情報
|
43
48
|
#
|
@@ -47,7 +52,7 @@ module Zakuro
|
|
47
52
|
@context = context
|
48
53
|
@month_label = month_label
|
49
54
|
@first_day = first_day
|
50
|
-
@
|
55
|
+
@solar_term_selector = SolarTermSelector.new(context: context, solar_terms: solar_terms)
|
51
56
|
@gengou = gengou
|
52
57
|
@meta = meta
|
53
58
|
end
|
@@ -158,7 +163,7 @@ module Zakuro
|
|
158
163
|
# @return [False] 設定あり
|
159
164
|
#
|
160
165
|
def empty_solar_term?
|
161
|
-
|
166
|
+
solar_term_selector.empty?
|
162
167
|
end
|
163
168
|
|
164
169
|
#
|
@@ -167,11 +172,7 @@ module Zakuro
|
|
167
172
|
# @return [Cycle::AbstractSolarTerm] 中気
|
168
173
|
#
|
169
174
|
def even_term
|
170
|
-
|
171
|
-
return term if term.index.even?
|
172
|
-
end
|
173
|
-
|
174
|
-
context.resolver.solar_term.new
|
175
|
+
solar_term_selector.even_term
|
175
176
|
end
|
176
177
|
|
177
178
|
#
|
@@ -180,11 +181,16 @@ module Zakuro
|
|
180
181
|
# @return [Cycle::AbstractSolarTerm] 節気
|
181
182
|
#
|
182
183
|
def odd_term
|
183
|
-
|
184
|
-
|
185
|
-
end
|
184
|
+
solar_term_selector.odd_term
|
185
|
+
end
|
186
186
|
|
187
|
-
|
187
|
+
#
|
188
|
+
# 二十四節気を返す
|
189
|
+
#
|
190
|
+
# @return [Array<Cyle::AbstractSolarTerm>] 二十四節気
|
191
|
+
#
|
192
|
+
def solar_terms
|
193
|
+
solar_term_selector.solar_terms
|
188
194
|
end
|
189
195
|
|
190
196
|
#
|
@@ -193,7 +199,7 @@ module Zakuro
|
|
193
199
|
# @param [SolarTerm] term 二十四節気
|
194
200
|
#
|
195
201
|
def add_term(term:)
|
196
|
-
|
202
|
+
solar_term_selector.add_term(term: term)
|
197
203
|
end
|
198
204
|
|
199
205
|
#
|
@@ -230,14 +236,9 @@ module Zakuro
|
|
230
236
|
def include?(date:)
|
231
237
|
return false if invalid?
|
232
238
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
return false if date < start_date
|
237
|
-
|
238
|
-
return false if date > last_date
|
239
|
-
|
240
|
-
true
|
239
|
+
DateComparer.include?(
|
240
|
+
date: date, start_date: western_date, last_date: last_date
|
241
|
+
)
|
241
242
|
end
|
242
243
|
|
243
244
|
#
|
@@ -251,14 +252,16 @@ module Zakuro
|
|
251
252
|
def include_by_japan_date?(date:)
|
252
253
|
return false if invalid?
|
253
254
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
return false unless linear_gengou.year == date.year
|
255
|
+
DateComparer.include_by_japan_date?(
|
256
|
+
date: date, gengou: gengou, month_label: month_label
|
257
|
+
)
|
258
|
+
end
|
260
259
|
|
261
|
-
|
260
|
+
#
|
261
|
+
# 二十四節気を正しい順序にソートする
|
262
|
+
#
|
263
|
+
def sort_solar_terms
|
264
|
+
solar_term_selector.sort
|
262
265
|
end
|
263
266
|
|
264
267
|
#
|
@@ -269,28 +272,7 @@ module Zakuro
|
|
269
272
|
# @return [Cycle::AbstractSolarTerm] 二十四節気
|
270
273
|
#
|
271
274
|
def solar_term_by_day(day:)
|
272
|
-
|
273
|
-
target = context.resolver.remainder.new(day: day, minute: 0, second: 0)
|
274
|
-
|
275
|
-
meta.all_solar_terms.each_cons(2) do |current_solar_term, next_solar_term|
|
276
|
-
in_range = Tools::RemainderComparer.in_range?(
|
277
|
-
target: target, start: current_solar_term.remainder, last: next_solar_term.remainder
|
278
|
-
)
|
279
|
-
return current_solar_term if in_range
|
280
|
-
end
|
281
|
-
|
282
|
-
last_solar_term = meta.all_solar_terms[-1]
|
283
|
-
|
284
|
-
empty_solar_term = context.resolver.solar_term.new
|
285
|
-
|
286
|
-
return empty_solar_term unless last_solar_term
|
287
|
-
# NOTE: 大余20を上限として範囲チェックする
|
288
|
-
if Tools::RemainderComparer.in_limit?(target: target, start: last_solar_term.remainder,
|
289
|
-
limit: 20)
|
290
|
-
return last_solar_term
|
291
|
-
end
|
292
|
-
|
293
|
-
empty_solar_term
|
275
|
+
solar_term_selector.solar_term_by_day(day: day, meta: meta)
|
294
276
|
end
|
295
277
|
|
296
278
|
#
|
@@ -304,24 +286,6 @@ module Zakuro
|
|
304
286
|
current_month: self
|
305
287
|
)
|
306
288
|
end
|
307
|
-
|
308
|
-
private
|
309
|
-
|
310
|
-
#
|
311
|
-
# 同一の月情報かを検証する
|
312
|
-
#
|
313
|
-
# @param [Japan::Calendar] date 日付
|
314
|
-
#
|
315
|
-
# @return [True] 同一の月
|
316
|
-
# @return [False] 異なる月
|
317
|
-
#
|
318
|
-
def same_by_japan_date?(date: Japan::Calendar.new)
|
319
|
-
return false unless number == date.month
|
320
|
-
|
321
|
-
return false unless leaped? == date.leaped
|
322
|
-
|
323
|
-
true
|
324
|
-
end
|
325
289
|
end
|
326
290
|
end
|
327
291
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../operation/operation'
|
4
|
-
require_relative './operated_solar_term'
|
4
|
+
require_relative './internal/operated_solar_term'
|
5
5
|
require_relative './month'
|
6
6
|
|
7
7
|
# :nodoc:
|
@@ -54,6 +54,8 @@ module Zakuro
|
|
54
54
|
rewrite_month
|
55
55
|
rewrite_solar_terms
|
56
56
|
rewrite_first_day
|
57
|
+
|
58
|
+
sort_solar_terms
|
57
59
|
end
|
58
60
|
|
59
61
|
#
|
@@ -85,10 +87,13 @@ module Zakuro
|
|
85
87
|
|
86
88
|
return unless matched
|
87
89
|
|
88
|
-
|
90
|
+
operated_solar_terms = OperatedSolarTerm.create_operated_solar_term(
|
89
91
|
operated_solar_term: solar_term,
|
90
92
|
solar_terms: solar_terms
|
91
93
|
)
|
94
|
+
@solar_term_selector = SolarTermSelector.new(
|
95
|
+
context: context, solar_terms: operated_solar_terms
|
96
|
+
)
|
92
97
|
end
|
93
98
|
|
94
99
|
#
|
@@ -62,7 +62,14 @@ module Zakuro
|
|
62
62
|
# @return [False] 存在なし
|
63
63
|
#
|
64
64
|
def exist?
|
65
|
-
|
65
|
+
remainder = solar_term_remainder
|
66
|
+
|
67
|
+
return false if remainder.invalid?
|
68
|
+
|
69
|
+
minute_later = remainder.class.new(
|
70
|
+
day: 0, minute: remainder.minute, second: remainder.second
|
71
|
+
)
|
72
|
+
minute_later >= limit
|
66
73
|
end
|
67
74
|
|
68
75
|
#
|
@@ -19,11 +19,14 @@ module Zakuro
|
|
19
19
|
# @param [Context::Context] context 暦コンテキスト
|
20
20
|
# @param [Western::Calendar] start_date 開始日
|
21
21
|
# @param [Western::Calendar] last_date 終了日
|
22
|
+
# @param [True, False] operated 運用値設定
|
23
|
+
# @param [True, False] restored 運用値から計算値に戻すか
|
22
24
|
#
|
23
|
-
def initialize(context:,
|
24
|
-
|
25
|
+
def initialize(context:, start_date: Western::Calendar.new,
|
26
|
+
last_date: Western::Calendar.new, operated: false, restored: false)
|
25
27
|
scroll = Gengou::DatedScroll.new(
|
26
|
-
start_date: start_date, last_date: last_date, operated:
|
28
|
+
start_date: start_date, last_date: last_date, operated: operated,
|
29
|
+
restored: restored
|
27
30
|
)
|
28
31
|
|
29
32
|
super(context: context, scroll: scroll, start_date: start_date, last_date: last_date)
|
@@ -25,7 +25,8 @@ module Zakuro
|
|
25
25
|
def initialize(context:, start_date: Western::Calendar.new,
|
26
26
|
last_date: Western::Calendar.new, years: [])
|
27
27
|
scroll = Gengou::DatedScroll.new(
|
28
|
-
start_date: start_date, last_date: last_date, operated: true
|
28
|
+
start_date: start_date, last_date: last_date, operated: true,
|
29
|
+
restored: false
|
29
30
|
)
|
30
31
|
super(context: context, scroll: scroll, years: years)
|
31
32
|
end
|
@@ -25,7 +25,7 @@ module Zakuro
|
|
25
25
|
#
|
26
26
|
def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME)
|
27
27
|
scroll = Gengou::NamedScroll.new(
|
28
|
-
start_name: start_name, last_name: last_name, operated: false
|
28
|
+
start_name: start_name, last_name: last_name, operated: false, restored: false
|
29
29
|
)
|
30
30
|
range = scroll.range
|
31
31
|
|
@@ -38,19 +38,33 @@ module Zakuro
|
|
38
38
|
year.months.each_with_index do |month, index|
|
39
39
|
scroll.run(month: month)
|
40
40
|
gengou = scroll.to_gengou
|
41
|
-
year.months[index] =
|
42
|
-
|
43
|
-
month_label: month.month_label,
|
44
|
-
first_day: Monthly::FirstDay.new(
|
45
|
-
remainder: month.first_day.remainder,
|
46
|
-
average_remainder: month.first_day.average_remainder,
|
47
|
-
western_date: gengou.start_date.clone
|
48
|
-
),
|
49
|
-
solar_terms: month.solar_terms, gengou: gengou,
|
50
|
-
meta: month.meta
|
41
|
+
year.months[index] = replace_gengou(
|
42
|
+
month: month, gengou: gengou
|
51
43
|
)
|
52
44
|
end
|
53
45
|
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# 月情報のうち元号を差し替える
|
49
|
+
#
|
50
|
+
# @param [Monthly::Month] month 月情報
|
51
|
+
# @param [Base::Gengou] gengou 元号
|
52
|
+
#
|
53
|
+
# @return [Monthly::Month] 月情報
|
54
|
+
#
|
55
|
+
def replace_gengou(month:, gengou:)
|
56
|
+
Monthly::Month.new(
|
57
|
+
context: month.context,
|
58
|
+
month_label: month.month_label,
|
59
|
+
first_day: Monthly::FirstDay.new(
|
60
|
+
remainder: month.first_day.remainder,
|
61
|
+
average_remainder: month.first_day.average_remainder,
|
62
|
+
western_date: gengou.start_date.clone
|
63
|
+
),
|
64
|
+
solar_terms: month.solar_terms, gengou: gengou,
|
65
|
+
meta: month.meta
|
66
|
+
)
|
67
|
+
end
|
54
68
|
end
|
55
69
|
end
|
56
70
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../../monthly/meta/meta_collector'
|
3
|
+
require_relative '../../monthly/internal/meta/meta_collector'
|
4
4
|
|
5
|
-
require_relative '../../../
|
5
|
+
require_relative '../../../tool/remainder_comparer'
|
6
6
|
|
7
7
|
# :nodoc:
|
8
8
|
module Zakuro
|
@@ -62,7 +62,7 @@ module Zakuro
|
|
62
62
|
# * 閏月は1回しか設定しない
|
63
63
|
# * 最大2回設定する(中気・節気)
|
64
64
|
4.times.each do |_index|
|
65
|
-
in_range =
|
65
|
+
in_range = Tool::RemainderComparer.in_range?(
|
66
66
|
target: solar_term.remainder, start: current_month.remainder,
|
67
67
|
last: next_month.remainder
|
68
68
|
)
|