zakuro 0.7.2 → 0.8.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 +3 -3
- data/VERSION +1 -1
- 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 +23 -21
- data/lib/zakuro/calculation/base/year.rb +3 -3
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +50 -44
- 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 +39 -37
- data/lib/zakuro/calculation/monthly/month.rb +15 -15
- data/lib/zakuro/calculation/monthly/month_label.rb +4 -4
- data/lib/zakuro/calculation/monthly/operated_month.rb +36 -85
- data/lib/zakuro/calculation/monthly/operated_solar_term.rb +80 -0
- data/lib/zakuro/calculation/range/abstract_full_range.rb +34 -21
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +109 -107
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- 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 +5 -5
- data/lib/zakuro/calculation/stella/solar/choukei_value.rb +114 -114
- data/lib/zakuro/calculation/summary/internal/day.rb +21 -19
- data/lib/zakuro/calculation/summary/internal/month.rb +25 -12
- data/lib/zakuro/calculation/summary/internal/operation.rb +68 -67
- data/lib/zakuro/calculation/summary/internal/option.rb +66 -50
- data/lib/zakuro/calculation/summary/japan/range.rb +145 -124
- data/lib/zakuro/calculation/summary/japan/single.rb +87 -87
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +54 -52
- 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 -124
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +60 -58
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/condition.rb +121 -111
- data/lib/zakuro/context/context.rb +1 -1
- data/lib/zakuro/context/option.rb +31 -29
- data/lib/zakuro/context/version_class_resolver.rb +26 -24
- data/lib/zakuro/era/japan/calendar.rb +35 -33
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -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 -36
- data/lib/zakuro/era/japan/gengou/resource/type.rb +39 -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 +102 -90
- data/lib/zakuro/exception/case/preset.rb +2 -2
- data/lib/zakuro/exception/exception.rb +15 -13
- data/lib/zakuro/exception/zakuro_error.rb +1 -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 +1 -1
- data/lib/zakuro/gateway/single.rb +13 -2
- data/lib/zakuro/merchant.rb +1 -1
- data/lib/zakuro/operation/month/parser.rb +252 -251
- 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/output/response.rb +112 -113
- 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 +66 -64
- data/lib/zakuro/tools/typeconv.rb +17 -15
- data/lib/zakuro/tools/typeof.rb +15 -13
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +10 -12
- data/lib/zakuro/version/daien/range/annual_range.rb +19 -17
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/daien/stella/lunar/value.rb +52 -49
- 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 +2 -2
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +7 -5
- 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/monthly/lunar_phase.rb +9 -9
- data/lib/zakuro/version/gihou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +42 -39
- data/lib/zakuro/version/gihou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +52 -49
- 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/monthly/lunar_phase.rb +10 -10
- data/lib/zakuro/version/senmyou/range/annual_range.rb +19 -17
- data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +42 -38
- data/lib/zakuro/version/senmyou/stella/lunar/localization.rb +16 -14
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +39 -36
- 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 +12 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -218
- data/lib/zakuro/result/operation/bundle.rb +0 -44
- data/lib/zakuro/result/operation/month/bundle.rb +0 -36
@@ -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
|
@@ -23,134 +23,132 @@ module Zakuro
|
|
23
23
|
# * もし元号が存在しない期間があれば、空の元号を生成する
|
24
24
|
#
|
25
25
|
module EmptyLink
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
counters.
|
26
|
+
class << self
|
27
|
+
#
|
28
|
+
# 空元号で満たす
|
29
|
+
#
|
30
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] last_date 終了日
|
33
|
+
#
|
34
|
+
def fill(counters:, start_date: Western::Calendar.new,
|
35
|
+
last_date: Western::Calendar.new)
|
36
|
+
if counters.size.zero?
|
37
|
+
counters.push(
|
38
|
+
create_empty_counter(
|
39
|
+
start_date: start_date.clone,
|
40
|
+
last_date: last_date.clone
|
41
|
+
)
|
42
|
+
)
|
43
|
+
return counters
|
44
|
+
end
|
45
|
+
|
46
|
+
fill_both_ends(counters: counters, start_date: start_date, last_date: last_date)
|
47
|
+
|
48
|
+
fill_middle(counters: counters)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
#
|
54
|
+
# リストの両端を空元号で満たす
|
55
|
+
#
|
56
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
57
|
+
# @param [Western::Calendar] start_date 開始日
|
58
|
+
# @param [Western::Calendar] last_date 終了日
|
59
|
+
#
|
60
|
+
def fill_both_ends(counters:, start_date: Western::Calendar.new,
|
61
|
+
last_date: Western::Calendar.new)
|
62
|
+
fill_by_start(counters: counters, start_date: start_date)
|
63
|
+
|
64
|
+
fill_by_last(counters: counters, last_date: last_date)
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# 先頭要素の手前を空元号で満たす
|
69
|
+
#
|
70
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
71
|
+
# @param [Western::Calendar] start_date 開始日
|
72
|
+
#
|
73
|
+
def fill_by_start(counters:, start_date:)
|
74
|
+
return unless start_date < counters[0].start_date
|
75
|
+
|
76
|
+
counters.unshift(
|
37
77
|
create_empty_counter(
|
38
78
|
start_date: start_date.clone,
|
79
|
+
last_date: counters[0].start_date.clone - 1
|
80
|
+
)
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# 最終要素の手前を空元号で満たす
|
86
|
+
#
|
87
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
88
|
+
# @param [Western::Calendar] last_date 終了日
|
89
|
+
#
|
90
|
+
def fill_by_last(counters:, last_date:)
|
91
|
+
return unless last_date > counters[-1].last_date
|
92
|
+
|
93
|
+
counters.push(
|
94
|
+
create_empty_counter(
|
95
|
+
start_date: counters[-1].last_date.clone + 1,
|
39
96
|
last_date: last_date.clone
|
40
97
|
)
|
41
98
|
)
|
42
|
-
return counters
|
43
99
|
end
|
44
100
|
|
45
|
-
|
101
|
+
#
|
102
|
+
# 元号間を空元号で満たす
|
103
|
+
#
|
104
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
105
|
+
#
|
106
|
+
def fill_middle(counters:)
|
107
|
+
return if counters.size.zero?
|
46
108
|
|
47
|
-
|
48
|
-
|
109
|
+
size = counters.size - 1
|
110
|
+
(0..size).reverse_each do |index|
|
111
|
+
break if index <= 0
|
49
112
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
54
|
-
# @param [Western::Calendar] start_date 開始日
|
55
|
-
# @param [Western::Calendar] last_date 終了日
|
56
|
-
#
|
57
|
-
def self.fill_both_ends(counters:, start_date: Western::Calendar.new,
|
58
|
-
last_date: Western::Calendar.new)
|
59
|
-
fill_by_start(counters: counters, start_date: start_date)
|
60
|
-
|
61
|
-
fill_by_last(counters: counters, last_date: last_date)
|
62
|
-
end
|
63
|
-
private_class_method :fill_both_ends
|
64
|
-
|
65
|
-
#
|
66
|
-
# 先頭要素の手前を空元号で満たす
|
67
|
-
#
|
68
|
-
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
69
|
-
# @param [Western::Calendar] start_date 開始日
|
70
|
-
#
|
71
|
-
def self.fill_by_start(counters:, start_date:)
|
72
|
-
return unless start_date < counters[0].start_date
|
73
|
-
|
74
|
-
counters.unshift(
|
75
|
-
create_empty_counter(
|
76
|
-
start_date: start_date.clone,
|
77
|
-
last_date: counters[0].start_date.clone - 1
|
78
|
-
)
|
79
|
-
)
|
80
|
-
end
|
81
|
-
private_class_method :fill_by_start
|
82
|
-
|
83
|
-
#
|
84
|
-
# 最終要素の手前を空元号で満たす
|
85
|
-
#
|
86
|
-
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
87
|
-
# @param [Western::Calendar] last_date 終了日
|
88
|
-
#
|
89
|
-
def self.fill_by_last(counters:, last_date:)
|
90
|
-
return unless last_date > counters[-1].last_date
|
91
|
-
|
92
|
-
counters.push(
|
93
|
-
create_empty_counter(
|
94
|
-
start_date: counters[-1].last_date.clone + 1,
|
95
|
-
last_date: last_date.clone
|
96
|
-
)
|
97
|
-
)
|
98
|
-
end
|
99
|
-
private_class_method :fill_by_last
|
113
|
+
insert(counters: counters, index: index)
|
114
|
+
end
|
115
|
+
end
|
100
116
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
117
|
+
#
|
118
|
+
# 対象要素に空元号を追加する
|
119
|
+
#
|
120
|
+
# @param [Array<Gengou::Counter>] counters 加算元号リスト
|
121
|
+
# @param [Integer] index 要素番号
|
122
|
+
#
|
123
|
+
def insert(counters:, index:)
|
124
|
+
before_last_date = counters[index - 1].last_date.clone
|
125
|
+
current_start_date = counters[index].start_date.clone
|
108
126
|
|
109
|
-
|
110
|
-
(0..size).reverse_each do |index|
|
111
|
-
break if index <= 0
|
127
|
+
return if (before_last_date.clone + 1) == current_start_date
|
112
128
|
|
113
|
-
insert(
|
129
|
+
counters.insert(
|
130
|
+
index,
|
131
|
+
create_empty_counter(
|
132
|
+
start_date: before_last_date + 1, last_date: current_start_date - 1
|
133
|
+
)
|
134
|
+
)
|
114
135
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
return if (before_last_date.clone + 1) == current_start_date
|
129
|
-
|
130
|
-
counters.insert(
|
131
|
-
index,
|
132
|
-
create_empty_counter(
|
133
|
-
start_date: before_last_date + 1, last_date: current_start_date - 1
|
136
|
+
|
137
|
+
#
|
138
|
+
# 空元号を生成する
|
139
|
+
#
|
140
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
141
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
142
|
+
#
|
143
|
+
# @return [Gengou::Counter] 加算元号(空元号)
|
144
|
+
#
|
145
|
+
def create_empty_counter(start_date:, last_date:)
|
146
|
+
Gengou::Counter.new(
|
147
|
+
gengou: Japan::Gengou::Resource::Gengou.new,
|
148
|
+
start_date: start_date, last_date: last_date
|
134
149
|
)
|
135
|
-
|
136
|
-
end
|
137
|
-
private_class_method :insert
|
138
|
-
|
139
|
-
#
|
140
|
-
# 空元号を生成する
|
141
|
-
#
|
142
|
-
# @param [Western::Calendar] start_date 西暦開始日
|
143
|
-
# @param [Western::Calendar] last_date 西暦終了日
|
144
|
-
#
|
145
|
-
# @return [Gengou::Counter] 加算元号(空元号)
|
146
|
-
#
|
147
|
-
def self.create_empty_counter(start_date:, last_date:)
|
148
|
-
Gengou::Counter.new(
|
149
|
-
gengou: Japan::Gengou::Resource::Gengou.new,
|
150
|
-
start_date: start_date, last_date: last_date
|
151
|
-
)
|
150
|
+
end
|
152
151
|
end
|
153
|
-
private_class_method :create_empty_counter
|
154
152
|
end
|
155
153
|
end
|
156
154
|
end
|
@@ -31,7 +31,7 @@ module Zakuro
|
|
31
31
|
@last_date = Western::Calendar.new
|
32
32
|
|
33
33
|
locate(start_name: start_name, last_name: last_name)
|
34
|
-
super(index:
|
34
|
+
super(index: index, start_date: start_date, last_date: last_date)
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
@@ -71,12 +71,12 @@ module Zakuro
|
|
71
71
|
def choise_start_date(date:)
|
72
72
|
return if date.invalid?
|
73
73
|
|
74
|
-
if
|
74
|
+
if start_date.invalid?
|
75
75
|
@start_date = date
|
76
76
|
return
|
77
77
|
end
|
78
78
|
|
79
|
-
return if date >
|
79
|
+
return if date > start_date
|
80
80
|
|
81
81
|
@start_date = date
|
82
82
|
end
|
@@ -89,12 +89,12 @@ module Zakuro
|
|
89
89
|
def choise_last_date(date:)
|
90
90
|
return if date.invalid?
|
91
91
|
|
92
|
-
if
|
92
|
+
if last_date.invalid?
|
93
93
|
@last_date = date
|
94
94
|
return
|
95
95
|
end
|
96
96
|
|
97
|
-
return if date <
|
97
|
+
return if date < last_date
|
98
98
|
|
99
99
|
@last_date = date
|
100
100
|
end
|
@@ -107,7 +107,7 @@ module Zakuro
|
|
107
107
|
# @return [Array<Japan::Alignment::LinearGengou>] 元号
|
108
108
|
#
|
109
109
|
def line_by_name(name:)
|
110
|
-
Japan::Gengou.line_by_name(line:
|
110
|
+
Japan::Gengou.line_by_name(line: index, name: name)
|
111
111
|
end
|
112
112
|
|
113
113
|
#
|
@@ -53,20 +53,18 @@ module Zakuro
|
|
53
53
|
# @return [List] 最新の元号
|
54
54
|
#
|
55
55
|
def newest_list
|
56
|
-
return
|
56
|
+
return first_list if invalid_list?
|
57
57
|
|
58
|
-
|
58
|
+
first_western_date = first_list.western_last_date
|
59
|
+
second_western_date = second_list.western_last_date
|
59
60
|
|
60
|
-
|
61
|
-
second_western_date = @second_list.western_last_date
|
61
|
+
return first_list if first_western_date.invalid?
|
62
62
|
|
63
|
-
return
|
63
|
+
return first_list if second_western_date.invalid?
|
64
64
|
|
65
|
-
return
|
65
|
+
return first_list if first_western_date > second_western_date
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
@second_list
|
67
|
+
second_list
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -14,26 +14,28 @@ module Zakuro
|
|
14
14
|
# 元号に基づき計算範囲を予約する
|
15
15
|
#
|
16
16
|
module Reserve
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
17
|
+
class << self
|
18
|
+
#
|
19
|
+
# 予約結果を取得する
|
20
|
+
#
|
21
|
+
# * 開始日・終了日から計算する範囲を求める
|
22
|
+
# * 開始日・終了日の範囲内にある元号全てが対象となる
|
23
|
+
# * 元号に応じて計算範囲は変化する
|
24
|
+
# * 元号の開始日(改元日)が開始日よりも前であれば、結果開始日は前者になる
|
25
|
+
# * 元号の終了日(改元前日)が終了日よりも後であれば、結果終了日は前者になる
|
26
|
+
# * 南北朝のように複数元号に属する場合、より広い範囲の元号に合わせる
|
27
|
+
# * 属する元号よりもさらに範囲を広げる場合がある
|
28
|
+
# * 開始日が最初の元号の改元後30日以内の場合、さらに前の元号まで対象にする
|
29
|
+
# * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
|
30
|
+
#
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] last_date 終了日
|
33
|
+
#
|
34
|
+
# @return [Range] 予約済み計算範囲
|
35
|
+
#
|
36
|
+
def get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
37
|
+
DatedRange.new(start_date: start_date, last_date: last_date)
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -13,37 +13,54 @@ module Zakuro
|
|
13
13
|
# 暦検索
|
14
14
|
#
|
15
15
|
module Crawler
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
result = []
|
28
|
-
|
29
|
-
ranges.each do |range|
|
30
|
-
next unless range.released
|
16
|
+
class << self
|
17
|
+
#
|
18
|
+
# 暦の範囲を取得する
|
19
|
+
#
|
20
|
+
# @param [Integer] start_year 開始西暦年
|
21
|
+
# @param [Integer] last_year 終了西暦年
|
22
|
+
#
|
23
|
+
# @return [Array<Range>] 暦の範囲
|
24
|
+
#
|
25
|
+
def get(start_year:, last_year:)
|
26
|
+
ranges = Japan::Version.ranges_with_year(start_year: start_year, last_year: last_year)
|
31
27
|
|
28
|
+
result = []
|
29
|
+
|
30
|
+
ranges.each do |range|
|
31
|
+
next unless range.released
|
32
|
+
|
33
|
+
narrowed_range = narrow(range: range, start_year: start_year, last_year: last_year)
|
34
|
+
|
35
|
+
result.push(narrowed_range)
|
36
|
+
end
|
37
|
+
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
#
|
44
|
+
# 範囲を開始年・終了年に合わせて狭める
|
45
|
+
#
|
46
|
+
# @param [Range] range 範囲
|
47
|
+
# @param [Integer] start_year 開始西暦年
|
48
|
+
# @param [Integer] last_year 終了西暦年
|
49
|
+
#
|
50
|
+
# @return [Range] 範囲
|
51
|
+
#
|
52
|
+
def narrow(range:, start_year:, last_year:)
|
32
53
|
range_start_year = range.start_year
|
33
54
|
range_start_year = start_year if start_year > range.start_year
|
34
55
|
|
35
56
|
range_last_year = range.last_year
|
36
57
|
range_last_year = last_year if last_year < range.last_year
|
37
58
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
start_year: range_start_year, last_year: range_last_year
|
42
|
-
)
|
59
|
+
Range.new(
|
60
|
+
name: range.name, start_date: range.start_date.clone,
|
61
|
+
start_year: range_start_year, last_year: range_last_year
|
43
62
|
)
|
44
63
|
end
|
45
|
-
|
46
|
-
result
|
47
64
|
end
|
48
65
|
end
|
49
66
|
end
|
@@ -8,16 +8,18 @@ module Zakuro
|
|
8
8
|
module Calculation
|
9
9
|
# :nodoc:
|
10
10
|
module Version
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
class << self
|
12
|
+
#
|
13
|
+
# 暦の範囲を取得する
|
14
|
+
#
|
15
|
+
# @param [Integer] start_year 開始西暦年
|
16
|
+
# @param [Integer] last_year 終了西暦年
|
17
|
+
#
|
18
|
+
# @return [Array<Range>] 暦の範囲
|
19
|
+
#
|
20
|
+
def get(start_year:, last_year:)
|
21
|
+
Crawler.get(start_year: start_year, last_year: last_year)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|