zakuro 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -13
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/csv/month.csv +100 -79
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +5 -5
- data/lib/zakuro/calculation/base/linear_gengou.rb +5 -5
- data/lib/zakuro/calculation/base/operated_year.rb +26 -24
- data/lib/zakuro/calculation/base/year.rb +7 -7
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +55 -47
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +28 -24
- data/lib/zakuro/calculation/cycle/zodiac.rb +22 -20
- data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +38 -29
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +4 -4
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +74 -72
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +16 -16
- data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +58 -35
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +3 -3
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +111 -113
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +6 -6
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +7 -9
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +22 -20
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +39 -22
- data/lib/zakuro/calculation/era/version/version.rb +12 -10
- data/lib/zakuro/calculation/monthly/abstract_lunar_phase.rb +13 -9
- data/lib/zakuro/calculation/monthly/const.rb +18 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +40 -38
- data/lib/zakuro/calculation/monthly/month.rb +17 -17
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +37 -86
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
- data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +40 -25
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +111 -109
- data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
- data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
- data/lib/zakuro/calculation/range/operated_solar_term.rb +220 -0
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +32 -29
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +115 -117
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +1 -1
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +48 -46
- data/lib/zakuro/calculation/stella/solar/abstract_average.rb +31 -26
- data/lib/zakuro/calculation/stella/solar/abstract_location.rb +7 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +42 -0
- data/lib/zakuro/calculation/summary/internal/month.rb +32 -11
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +101 -0
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -118
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +57 -50
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +95 -92
- data/lib/zakuro/calculation/summary/western/single.rb +78 -76
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +123 -119
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +63 -56
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +142 -92
- data/lib/zakuro/context/context.rb +44 -0
- data/lib/zakuro/context/option.rb +119 -0
- data/lib/zakuro/context/version_class_resolver.rb +112 -0
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +8 -4
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +117 -118
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +7 -5
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +20 -14
- data/lib/zakuro/era/japan/gengou/alignment.rb +27 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +51 -34
- data/lib/zakuro/era/japan/gengou/resource/type.rb +45 -37
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +34 -32
- data/lib/zakuro/era/japan/gengou.rb +28 -26
- data/lib/zakuro/era/japan/version.rb +18 -16
- data/lib/zakuro/era/western/calendar.rb +104 -88
- data/lib/zakuro/exception/case/pattern.rb +39 -3
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +17 -15
- data/lib/zakuro/exception/zakuro_error.rb +19 -1
- data/lib/zakuro/gateway/locale/date.rb +2 -2
- data/lib/zakuro/gateway/locale/range.rb +3 -3
- data/lib/zakuro/gateway/range.rb +3 -3
- data/lib/zakuro/gateway/single.rb +14 -3
- data/lib/zakuro/merchant.rb +79 -9
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +17 -8
- data/lib/zakuro/operation/month/validator.rb +148 -144
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +955 -281
- data/lib/zakuro/output/response.rb +107 -141
- data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
- data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
- data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
- data/lib/zakuro/result/data/single_day.rb +9 -1
- data/lib/zakuro/result/operation/month/annotation.rb +2 -2
- data/lib/zakuro/result/operation/month/history.rb +2 -2
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +39 -0
- data/lib/zakuro/result/result.rb +3 -3
- data/lib/zakuro/tools/stringifier.rb +67 -42
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/daien/stella/solar/average.rb +53 -51
- data/lib/zakuro/version/daien/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/daien/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/genka/cycle/remainder.rb +4 -4
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +48 -44
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +30 -28
- data/lib/zakuro/version/genka/stella/origin/january.rb +22 -20
- data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -37
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -47
- data/lib/zakuro/version/gihou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/gihou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/gihou/stella/origin/winter_solstice.rb +24 -22
- data/lib/zakuro/version/gihou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/gihou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/gihou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/gihou/stella/solar/value.rb +13 -11
- data/lib/zakuro/version/senmyou/const/remainder.rb +7 -1
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -36
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -34
- data/lib/zakuro/version/senmyou/stella/origin/average_november.rb +15 -13
- data/lib/zakuro/version/senmyou/stella/origin/lunar_age.rb +23 -21
- data/lib/zakuro/version/senmyou/stella/origin/winter_solstice.rb +22 -20
- data/lib/zakuro/version/senmyou/stella/solar/adjustment.rb +12 -10
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +52 -50
- data/lib/zakuro/version/senmyou/stella/solar/interval.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/solar/value.rb +13 -11
- metadata +27 -7
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
- data/lib/zakuro/result/operation/operation.rb +0 -44
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -60,7 +60,7 @@ module Zakuro
|
|
60
60
|
#
|
61
61
|
def replace(gengou:)
|
62
62
|
matched_index = -1
|
63
|
-
|
63
|
+
unsolved_list.each_with_index do |unsolved, index|
|
64
64
|
next unless unsolved.name == gengou.name
|
65
65
|
|
66
66
|
matched_index = index
|
@@ -68,18 +68,18 @@ module Zakuro
|
|
68
68
|
end
|
69
69
|
|
70
70
|
if matched_index == -1
|
71
|
-
|
71
|
+
unsolved_list.push(gengou)
|
72
72
|
return gengou
|
73
73
|
end
|
74
74
|
|
75
|
-
matched =
|
75
|
+
matched = unsolved_list[matched_index]
|
76
76
|
|
77
77
|
result = recreate(gengou: gengou, unsolved: matched)
|
78
78
|
|
79
79
|
@unsolved_list[matched_index] = result
|
80
80
|
|
81
81
|
# 分離した元号の末尾まで到達した
|
82
|
-
|
82
|
+
unsolved_list.delete_at(matched_index) unless result.change_last_date?
|
83
83
|
|
84
84
|
result
|
85
85
|
end
|
@@ -56,9 +56,9 @@ module Zakuro
|
|
56
56
|
# @return [Japan::Calendar] 和暦開始日
|
57
57
|
#
|
58
58
|
def japan_start_date
|
59
|
-
return Japan::Calendar.new if
|
59
|
+
return Japan::Calendar.new if gengou.invalid?
|
60
60
|
|
61
|
-
|
61
|
+
gengou.both_start_date.japan
|
62
62
|
end
|
63
63
|
|
64
64
|
#
|
@@ -67,9 +67,9 @@ module Zakuro
|
|
67
67
|
# @return [Western::Calendar] 西暦開始日
|
68
68
|
#
|
69
69
|
def western_start_date
|
70
|
-
return Western::Calendar.new if
|
70
|
+
return Western::Calendar.new if gengou.invalid?
|
71
71
|
|
72
|
-
|
72
|
+
start_date
|
73
73
|
end
|
74
74
|
|
75
75
|
#
|
@@ -78,9 +78,9 @@ module Zakuro
|
|
78
78
|
# @return [Western::Calendar] 西暦終了日
|
79
79
|
#
|
80
80
|
def western_last_date
|
81
|
-
return Western::Calendar.new if
|
81
|
+
return Western::Calendar.new if gengou.invalid?
|
82
82
|
|
83
|
-
|
83
|
+
last_date
|
84
84
|
end
|
85
85
|
|
86
86
|
#
|
@@ -103,7 +103,7 @@ module Zakuro
|
|
103
103
|
def name
|
104
104
|
return '' unless @gengou
|
105
105
|
|
106
|
-
|
106
|
+
gengou.name
|
107
107
|
end
|
108
108
|
|
109
109
|
#
|
@@ -113,7 +113,7 @@ module Zakuro
|
|
113
113
|
# @return [False] 不正なし
|
114
114
|
#
|
115
115
|
def invalid?
|
116
|
-
|
116
|
+
gengou.invalid? || japan_year == INVALID_YEAR || western_year == INVALID_YEAR
|
117
117
|
end
|
118
118
|
|
119
119
|
#
|
@@ -125,7 +125,7 @@ module Zakuro
|
|
125
125
|
# @return [False] 含まれない
|
126
126
|
#
|
127
127
|
def include?
|
128
|
-
|
128
|
+
gengou.include?
|
129
129
|
end
|
130
130
|
|
131
131
|
#
|
@@ -151,7 +151,7 @@ module Zakuro
|
|
151
151
|
def change_start_date?
|
152
152
|
return false if invalid?
|
153
153
|
|
154
|
-
|
154
|
+
start_date != native_start_date
|
155
155
|
end
|
156
156
|
|
157
157
|
#
|
@@ -163,7 +163,7 @@ module Zakuro
|
|
163
163
|
def change_last_date?
|
164
164
|
return false if invalid?
|
165
165
|
|
166
|
-
|
166
|
+
last_date != native_last_date
|
167
167
|
end
|
168
168
|
|
169
169
|
#
|
@@ -185,10 +185,10 @@ module Zakuro
|
|
185
185
|
# 有効な日付範囲を選択する
|
186
186
|
#
|
187
187
|
def select_valid_date
|
188
|
-
return if
|
188
|
+
return if gengou.invalid?
|
189
189
|
|
190
|
-
@start_date =
|
191
|
-
@last_date =
|
190
|
+
@start_date = gengou.both_start_date.western.clone if start_date.invalid?
|
191
|
+
@last_date = gengou.last_date.clone if last_date.invalid?
|
192
192
|
end
|
193
193
|
|
194
194
|
#
|
@@ -197,7 +197,7 @@ module Zakuro
|
|
197
197
|
# @return [Western::Calendar]設定された元号の開始日
|
198
198
|
#
|
199
199
|
def native_start_date
|
200
|
-
|
200
|
+
gengou.both_start_date.western
|
201
201
|
end
|
202
202
|
|
203
203
|
#
|
@@ -206,7 +206,7 @@ module Zakuro
|
|
206
206
|
# @return [Western::Calendar] 設定された元号の終了日
|
207
207
|
#
|
208
208
|
def native_last_date
|
209
|
-
|
209
|
+
gengou.last_date
|
210
210
|
end
|
211
211
|
end
|
212
212
|
end
|
@@ -14,89 +14,91 @@ module Zakuro
|
|
14
14
|
# 元号発行
|
15
15
|
#
|
16
16
|
module Publisher
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
17
|
+
class << self
|
18
|
+
#
|
19
|
+
# 発行する
|
20
|
+
#
|
21
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
22
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
23
|
+
# @param [Array<Counter>] first_gengou 1行目元号
|
24
|
+
# @param [Array<Counter>] second_gengou 2行目元号
|
25
|
+
#
|
26
|
+
# @return [Base::Gengou] 元号
|
27
|
+
#
|
28
|
+
def run(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
29
|
+
first_gengou: [], second_gengou: [])
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
Base::Gengou.new(
|
32
|
+
start_date: start_date,
|
33
|
+
last_date: last_date,
|
34
|
+
first_line: to_linear_gengou(
|
35
|
+
start_date: start_date, last_date: last_date, gengou_list: first_gengou
|
36
|
+
),
|
37
|
+
second_line: to_linear_gengou(
|
38
|
+
start_date: start_date, last_date: last_date, gengou_list: second_gengou
|
39
|
+
)
|
38
40
|
)
|
39
|
-
|
40
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# 直列元号に変換する
|
45
|
+
#
|
46
|
+
# * 最初の元号:開始日~その元号の終了日
|
47
|
+
# * 中間の元号:その元号の開始日~その元号の終了日
|
48
|
+
# * 最後の元号:その元号の開始日~終了日
|
49
|
+
#
|
50
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
51
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
52
|
+
# @param [Array<Counter>] gengou_list 元号リスト
|
53
|
+
#
|
54
|
+
# @return [Array<Base::LinearGengou>] 元号リスト
|
55
|
+
#
|
56
|
+
def to_linear_gengou(start_date:, last_date:, gengou_list: [])
|
57
|
+
return [] if gengou_list.size.zero?
|
41
58
|
|
42
|
-
|
43
|
-
# 直列元号に変換する
|
44
|
-
#
|
45
|
-
# * 最初の元号:開始日~その元号の終了日
|
46
|
-
# * 中間の元号:その元号の開始日~その元号の終了日
|
47
|
-
# * 最後の元号:その元号の開始日~終了日
|
48
|
-
#
|
49
|
-
# @param [Western::Calendar] start_date 西暦開始日
|
50
|
-
# @param [Western::Calendar] last_date 西暦終了日
|
51
|
-
# @param [Array<Counter>] gengou_list 元号リスト
|
52
|
-
#
|
53
|
-
# @return [Array<Base::LinearGengou>] 元号リスト
|
54
|
-
#
|
55
|
-
def self.to_linear_gengou(start_date:, last_date:, gengou_list: [])
|
56
|
-
return [] if gengou_list.size.zero?
|
59
|
+
result = []
|
57
60
|
|
58
|
-
|
61
|
+
gengou_list.each do |gengou|
|
62
|
+
if gengou.invalid?
|
63
|
+
# 無効元号は無効のままにする
|
64
|
+
result.push(Base::LinearGengou.new)
|
65
|
+
next
|
66
|
+
end
|
59
67
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
68
|
+
linear_gengou = to_limited_linear_gengou(
|
69
|
+
start_date: start_date,
|
70
|
+
last_date: last_date,
|
71
|
+
gengou: gengou
|
72
|
+
)
|
73
|
+
result.push(linear_gengou)
|
65
74
|
end
|
66
75
|
|
67
|
-
|
68
|
-
start_date: start_date,
|
69
|
-
last_date: last_date,
|
70
|
-
gengou: gengou
|
71
|
-
)
|
72
|
-
result.push(linear_gengou)
|
76
|
+
result
|
73
77
|
end
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
def self.to_limited_linear_gengou(start_date:, last_date:, gengou:)
|
90
|
-
gengou_start_date = gengou.western_start_date.clone
|
91
|
-
gengou_last_date = gengou.western_last_date.clone
|
79
|
+
#
|
80
|
+
# 範囲を限定した直列元号に変換する
|
81
|
+
#
|
82
|
+
# * 開始日・終了日により範囲を狭める
|
83
|
+
#
|
84
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
85
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
86
|
+
# @param [Counter] gengou 加算元号
|
87
|
+
#
|
88
|
+
# @return [Base::LinearGengou] 元号
|
89
|
+
#
|
90
|
+
def to_limited_linear_gengou(start_date:, last_date:, gengou:)
|
91
|
+
gengou_start_date = gengou.western_start_date.clone
|
92
|
+
gengou_last_date = gengou.western_last_date.clone
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
gengou_start_date = start_date.clone if start_date > gengou_start_date
|
95
|
+
gengou_last_date = last_date.clone if last_date < gengou_last_date
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
Base::LinearGengou.new(
|
98
|
+
start_date: gengou_start_date, last_date: gengou_last_date,
|
99
|
+
name: gengou.name, year: gengou.japan_year
|
100
|
+
)
|
101
|
+
end
|
100
102
|
end
|
101
103
|
end
|
102
104
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../../../../era/japan/gengou/resource'
|
4
4
|
require_relative '../../../../../era/japan/gengou'
|
@@ -61,7 +61,7 @@ module Zakuro
|
|
61
61
|
# @return [Gengou::Counter] 加算元号
|
62
62
|
#
|
63
63
|
def get(western_date: Western::Calendar.new)
|
64
|
-
|
64
|
+
list.each do |linear_gengou|
|
65
65
|
next if linear_gengou.out?(start_date: western_date, last_date: western_date)
|
66
66
|
|
67
67
|
Gengou::Counter.new(gengou: linear_gengou.gengou).clone
|
@@ -81,7 +81,7 @@ module Zakuro
|
|
81
81
|
def collect(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
82
82
|
result = []
|
83
83
|
|
84
|
-
|
84
|
+
list.each do |linear_gengou|
|
85
85
|
next if linear_gengou.out?(start_date: start_date, last_date: last_date)
|
86
86
|
|
87
87
|
result.push(
|
@@ -106,7 +106,7 @@ module Zakuro
|
|
106
106
|
def japan_start_date
|
107
107
|
return Japan::Calendar.new if invalid?
|
108
108
|
|
109
|
-
|
109
|
+
list[0].gengou.both_start_date.japan.clone
|
110
110
|
end
|
111
111
|
|
112
112
|
#
|
@@ -117,7 +117,7 @@ module Zakuro
|
|
117
117
|
def western_start_date
|
118
118
|
return Western::Calendar.new if invalid?
|
119
119
|
|
120
|
-
|
120
|
+
list[0].gengou.both_start_date.western.clone
|
121
121
|
end
|
122
122
|
|
123
123
|
#
|
@@ -128,7 +128,7 @@ module Zakuro
|
|
128
128
|
def western_last_date
|
129
129
|
return Western::Calendar.new if invalid?
|
130
130
|
|
131
|
-
|
131
|
+
list[-1].gengou.last_date.clone
|
132
132
|
end
|
133
133
|
|
134
134
|
#
|
@@ -139,7 +139,7 @@ module Zakuro
|
|
139
139
|
def western_start_year
|
140
140
|
return INVALID_YEAR if invalid?
|
141
141
|
|
142
|
-
|
142
|
+
list[0].gengou.both_start_year.western.clone
|
143
143
|
end
|
144
144
|
|
145
145
|
#
|
@@ -150,9 +150,9 @@ module Zakuro
|
|
150
150
|
def western_last_year
|
151
151
|
return INVALID_YEAR if invalid?
|
152
152
|
|
153
|
-
return INVALID_YEAR if
|
153
|
+
return INVALID_YEAR if list.size.zero?
|
154
154
|
|
155
|
-
|
155
|
+
list[-1].gengou.last_year
|
156
156
|
end
|
157
157
|
|
158
158
|
#
|
@@ -162,9 +162,9 @@ module Zakuro
|
|
162
162
|
# @return [False] 不正なし
|
163
163
|
#
|
164
164
|
def invalid?
|
165
|
-
return true unless
|
165
|
+
return true unless list
|
166
166
|
|
167
|
-
return true if
|
167
|
+
return true if list.size.zero?
|
168
168
|
|
169
169
|
false
|
170
170
|
end
|
@@ -175,9 +175,9 @@ module Zakuro
|
|
175
175
|
# @return [Western::Calendar]設定された元号の開始日
|
176
176
|
#
|
177
177
|
def native_start_date
|
178
|
-
return Western::Calendar.new if
|
178
|
+
return Western::Calendar.new if list.size.zero?
|
179
179
|
|
180
|
-
|
180
|
+
list[0].native_start_date
|
181
181
|
end
|
182
182
|
|
183
183
|
#
|
@@ -187,9 +187,9 @@ module Zakuro
|
|
187
187
|
# @return [False] 同一
|
188
188
|
#
|
189
189
|
def change_start_date?
|
190
|
-
return false if
|
190
|
+
return false if list.size.zero?
|
191
191
|
|
192
|
-
|
192
|
+
list[0].change_start_date?
|
193
193
|
end
|
194
194
|
|
195
195
|
private
|
@@ -210,7 +210,7 @@ module Zakuro
|
|
210
210
|
# @return [Array<Japan::Alignment::LinearGengou>] 元号
|
211
211
|
#
|
212
212
|
def line(start_date:, last_date:)
|
213
|
-
Japan::Gengou.line(line:
|
213
|
+
Japan::Gengou.line(line: index, start_date: start_date, last_date: last_date)
|
214
214
|
end
|
215
215
|
|
216
216
|
#
|
@@ -43,25 +43,13 @@ module Zakuro
|
|
43
43
|
# @param [Western::Calendar] last_date 西暦終了日
|
44
44
|
#
|
45
45
|
def renew(last_date: Western::Calendar.new)
|
46
|
-
|
47
|
-
[@first_list, @second_list].each do |list|
|
48
|
-
next unless list.change_start_date?
|
49
|
-
|
50
|
-
if native_start_date.invalid?
|
51
|
-
native_start_date = list.native_start_date.clone
|
52
|
-
next
|
53
|
-
end
|
54
|
-
|
55
|
-
next if native_start_date <= list.native_start_date
|
56
|
-
|
57
|
-
native_start_date = list.native_start_date.clone
|
58
|
-
end
|
46
|
+
start_date = native_start_date
|
59
47
|
|
60
|
-
return if
|
48
|
+
return if start_date.invalid?
|
61
49
|
|
62
|
-
@first_list = DatedList.new(first: true, start_date:
|
50
|
+
@first_list = DatedList.new(first: true, start_date: start_date,
|
63
51
|
last_date: last_date)
|
64
|
-
@second_list = DatedList.new(first: false, start_date:
|
52
|
+
@second_list = DatedList.new(first: false, start_date: start_date,
|
65
53
|
last_date: last_date)
|
66
54
|
end
|
67
55
|
|
@@ -72,7 +60,7 @@ module Zakuro
|
|
72
60
|
# @return [False] 不正なし
|
73
61
|
#
|
74
62
|
def invalid?
|
75
|
-
|
63
|
+
first_list.invalid?
|
76
64
|
end
|
77
65
|
|
78
66
|
#
|
@@ -85,7 +73,7 @@ module Zakuro
|
|
85
73
|
#
|
86
74
|
def collect_first(start_date: Western::Calendar.new,
|
87
75
|
last_date: Western::Calendar.new)
|
88
|
-
|
76
|
+
first_list.collect(start_date: start_date, last_date: last_date)
|
89
77
|
end
|
90
78
|
|
91
79
|
#
|
@@ -98,7 +86,7 @@ module Zakuro
|
|
98
86
|
#
|
99
87
|
def collect_second(start_date: Western::Calendar.new,
|
100
88
|
last_date: Western::Calendar.new)
|
101
|
-
|
89
|
+
second_list.collect(start_date: start_date, last_date: last_date)
|
102
90
|
end
|
103
91
|
|
104
92
|
#
|
@@ -133,12 +121,12 @@ module Zakuro
|
|
133
121
|
# @return [Integer] 開始西暦年
|
134
122
|
#
|
135
123
|
def western_start_year
|
136
|
-
first_start_year =
|
137
|
-
second_start_year =
|
124
|
+
first_start_year = first_list.western_start_year
|
125
|
+
second_start_year = second_list.western_start_year
|
138
126
|
|
139
|
-
return first_start_year if
|
127
|
+
return first_start_year if first_list.invalid?
|
140
128
|
|
141
|
-
return first_start_year if
|
129
|
+
return first_start_year if second_list.invalid?
|
142
130
|
|
143
131
|
return first_start_year if first_start_year < second_start_year
|
144
132
|
|
@@ -151,12 +139,12 @@ module Zakuro
|
|
151
139
|
# @return [Integer] 終了西暦年
|
152
140
|
#
|
153
141
|
def western_last_year
|
154
|
-
first_last_year =
|
155
|
-
second_last_year =
|
142
|
+
first_last_year = first_list.western_last_year
|
143
|
+
second_last_year = second_list.western_last_year
|
156
144
|
|
157
|
-
return first_last_year if
|
145
|
+
return first_last_year if first_list.invalid?
|
158
146
|
|
159
|
-
return first_last_year if
|
147
|
+
return first_last_year if second_list.invalid?
|
160
148
|
|
161
149
|
return first_last_year if first_last_year > second_last_year
|
162
150
|
|
@@ -165,26 +153,61 @@ module Zakuro
|
|
165
153
|
|
166
154
|
private
|
167
155
|
|
156
|
+
#
|
157
|
+
# 設定された元号の開始日を取得する
|
158
|
+
#
|
159
|
+
# @return [Western::Calendar] 設定された元号の開始日
|
160
|
+
#
|
161
|
+
def native_start_date
|
162
|
+
result = Western::Calendar.new
|
163
|
+
[first_list, second_list].each do |list|
|
164
|
+
next unless list.change_start_date?
|
165
|
+
|
166
|
+
if result.invalid?
|
167
|
+
result = list.native_start_date.clone
|
168
|
+
next
|
169
|
+
end
|
170
|
+
|
171
|
+
next if result <= list.native_start_date
|
172
|
+
|
173
|
+
result = list.native_start_date.clone
|
174
|
+
end
|
175
|
+
|
176
|
+
result
|
177
|
+
end
|
178
|
+
|
168
179
|
#
|
169
180
|
# 最古の元号を取得する
|
170
181
|
#
|
171
182
|
# @return [List] 最古の元号
|
172
183
|
#
|
173
184
|
def oldest_list
|
174
|
-
return
|
185
|
+
return first_list if invalid_list?
|
186
|
+
|
187
|
+
first_western_date = first_list.western_start_date
|
188
|
+
second_western_date = second_list.western_start_date
|
175
189
|
|
176
|
-
return
|
190
|
+
return first_list if first_western_date.invalid?
|
177
191
|
|
178
|
-
|
179
|
-
second_western_date = @second_list.western_start_date
|
192
|
+
return first_list if second_western_date.invalid?
|
180
193
|
|
181
|
-
return
|
194
|
+
return first_list if first_western_date < second_western_date
|
182
195
|
|
183
|
-
|
196
|
+
second_list
|
197
|
+
end
|
198
|
+
|
199
|
+
#
|
200
|
+
# 元号リストが不正か
|
201
|
+
#
|
202
|
+
# @return [True] 不正
|
203
|
+
# @return [False] 不正なし
|
204
|
+
#
|
205
|
+
def invalid_list?
|
206
|
+
return true if first_list.invalid?
|
184
207
|
|
185
|
-
return
|
208
|
+
return true if second_list.invalid?
|
186
209
|
|
187
|
-
|
210
|
+
false
|
188
211
|
end
|
189
212
|
end
|
190
213
|
end
|
@@ -35,11 +35,11 @@ module Zakuro
|
|
35
35
|
#
|
36
36
|
def update
|
37
37
|
# 開始日の30日前に前の元号がある場合は、前の元号を設定する
|
38
|
-
|
38
|
+
start = start_date.clone - (MAX_MONTH_DAYS + 1)
|
39
39
|
# 開始日の30日後に次の元号がある場合は、次の元号を設定する
|
40
|
-
|
40
|
+
last = last_date.clone + (MAX_MONTH_DAYS + 1)
|
41
41
|
|
42
|
-
@list |= line(start_date:
|
42
|
+
@list |= line(start_date: start, last_date: last)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|