zakuro 0.4.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -3
- data/VERSION +1 -0
- data/doc/operation/csv/month.csv +21 -0
- data/doc/operation/operation.xlsx +0 -0
- data/lib/zakuro/calculation/base/gengou.rb +82 -0
- data/lib/zakuro/calculation/base/linear_gengou.rb +76 -0
- data/lib/zakuro/calculation/base/operated_year.rb +5 -15
- data/lib/zakuro/calculation/base/year.rb +26 -14
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +0 -13
- data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
- data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
- data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/list.rb +244 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/range.rb +193 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +42 -0
- data/lib/zakuro/calculation/era/gengou/scroll.rb +211 -0
- data/lib/zakuro/calculation/era/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/era/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/era/version/version.rb +24 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +3 -2
- data/lib/zakuro/calculation/monthly/month.rb +49 -2
- data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
- data/lib/zakuro/calculation/range/full_range.rb +68 -107
- data/lib/zakuro/calculation/range/operated_range.rb +13 -9
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +36 -17
- data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +54 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +25 -21
- data/lib/zakuro/calculation/specifier/internal/month.rb +84 -0
- data/lib/zakuro/calculation/specifier/multiple_day.rb +162 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +15 -37
- data/lib/zakuro/calculation/summary/internal/operation.rb +98 -0
- data/lib/zakuro/calculation/summary/range.rb +120 -0
- data/lib/zakuro/calculation/summary/single.rb +45 -64
- data/lib/zakuro/condition.rb +14 -0
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +106 -0
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +165 -0
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +156 -0
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +184 -0
- data/lib/zakuro/era/japan/gengou/alignment.rb +42 -0
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +242 -0
- data/lib/zakuro/era/japan/gengou/resource/type.rb +292 -0
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +346 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou/resource.rb +32 -0
- data/lib/zakuro/era/japan/gengou.rb +35 -74
- data/lib/zakuro/era/japan/version.rb +151 -0
- data/lib/zakuro/era/{western.rb → western/calendar.rb} +0 -0
- data/lib/zakuro/merchant.rb +50 -3
- data/lib/zakuro/operation/month/parser.rb +1 -1
- data/lib/zakuro/operation/month/type.rb +1 -1
- data/lib/zakuro/operation/month/validator.rb +2 -2
- data/lib/zakuro/operation/yaml/month.yaml +672 -0
- data/lib/zakuro/output/response.rb +5 -5
- data/lib/zakuro/result/result.rb +17 -0
- data/lib/zakuro/tools/typeconv.rb +38 -0
- data/lib/zakuro/tools/typeof.rb +4 -1
- data/lib/zakuro/version/context.rb +24 -3
- data/lib/zakuro/version/daien/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/daien/daien.rb +1 -26
- data/lib/zakuro/version/daien/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/genka/const/number.rb +43 -0
- data/lib/zakuro/version/genka/const/remainder.rb +33 -0
- data/lib/zakuro/version/genka/cycle/remainder.rb +92 -0
- data/lib/zakuro/version/genka/cycle/solar_term.rb +34 -0
- data/lib/zakuro/version/genka/genka.rb +1 -9
- data/lib/zakuro/version/genka/monthly/lunar_phase.rb +95 -0
- data/lib/zakuro/version/genka/range/annual_range.rb +77 -0
- data/lib/zakuro/version/genka/stella/origin/first_term.rb +55 -0
- data/lib/zakuro/version/genka/stella/origin/january.rb +49 -0
- data/lib/zakuro/version/genka/stella/solar/average.rb +41 -0
- data/lib/zakuro/version/gihou/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gihou/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/gregorio/gregorio.rb +1 -9
- data/lib/zakuro/version/houryaku/houryaku.rb +1 -9
- data/lib/zakuro/version/joukyou/joukyou.rb +1 -9
- data/lib/zakuro/version/kansei/kansei.rb +1 -9
- data/lib/zakuro/version/senmyou/README.md +11 -7
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +26 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +2 -2
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/lib/zakuro/version/version_class_resolver.rb +4 -0
- data/zakuro.gemspec +1 -3
- metadata +45 -16
- data/lib/zakuro/calculation/base/multi_gengou.rb +0 -101
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +0 -218
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +0 -82
- data/lib/zakuro/era/japan/gengou/parser.rb +0 -167
- data/lib/zakuro/era/japan/gengou/type.rb +0 -178
- data/lib/zakuro/era/japan/gengou/validator.rb +0 -236
- data/lib/zakuro/era/japan/reki.rb +0 -91
- data/lib/zakuro/era/japan/yaml/set-001-until-south.yaml +0 -1121
- data/lib/zakuro/era/japan/yaml/set-002-from-north.yaml +0 -485
- data/lib/zakuro/era/japan/yaml/set-003-modern.yaml +0 -28
- data/lib/zakuro/version/abstract_version.rb +0 -29
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,214 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/japan/gengou/resource'
|
4
|
+
require_relative '../../../../era/japan/calendar'
|
5
|
+
require_relative '../../../../era/western/calendar'
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
module Zakuro
|
9
|
+
# :nodoc:
|
10
|
+
module Calculation
|
11
|
+
# :nodoc:
|
12
|
+
module Gengou
|
13
|
+
#
|
14
|
+
# Counter 加算元号
|
15
|
+
#
|
16
|
+
class Counter
|
17
|
+
# @return [Integer] 不正値
|
18
|
+
INVALID_YEAR = -1
|
19
|
+
|
20
|
+
# @return [Japan::Resource::Gengou] 元号
|
21
|
+
attr_reader :gengou
|
22
|
+
# @return [Integer] 元号年
|
23
|
+
attr_reader :japan_year
|
24
|
+
# @return [Integer] 西暦年
|
25
|
+
attr_reader :western_year
|
26
|
+
# @return [Western::Calendar] 西暦開始年
|
27
|
+
attr_reader :start_date
|
28
|
+
# @return [Western::Calendar] 西暦終了年
|
29
|
+
attr_reader :last_date
|
30
|
+
|
31
|
+
#
|
32
|
+
# 初期化
|
33
|
+
#
|
34
|
+
# @param [Japan::Resource::Gengou] gengou 元号
|
35
|
+
# @param [Western::Calendar] start_date 西暦開始年
|
36
|
+
# @param [Western::Calendar] last_date 西暦終了年
|
37
|
+
# @param [Integer] japan_year 和暦年
|
38
|
+
#
|
39
|
+
def initialize(gengou: Japan::Resource::Gengou.new,
|
40
|
+
start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
41
|
+
japan_year: INVALID_YEAR)
|
42
|
+
@gengou = gengou
|
43
|
+
@japan_year = japan_year
|
44
|
+
@japan_year = gengou.both_start_year.japan if @japan_year == INVALID_YEAR
|
45
|
+
@western_year = gengou.both_start_year.western
|
46
|
+
|
47
|
+
@start_date = start_date.clone
|
48
|
+
@last_date = last_date.clone
|
49
|
+
|
50
|
+
select_valid_date
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# 和暦開始日を取得する
|
55
|
+
#
|
56
|
+
# @return [Japan::Calendar] 和暦開始日
|
57
|
+
#
|
58
|
+
def japan_start_date
|
59
|
+
return Japan::Calendar.new if @gengou.invalid?
|
60
|
+
|
61
|
+
@gengou.both_start_date.japan
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# 西暦開始日を取得する
|
66
|
+
#
|
67
|
+
# @return [Western::Calendar] 西暦開始日
|
68
|
+
#
|
69
|
+
def western_start_date
|
70
|
+
return Western::Calendar.new if @gengou.invalid?
|
71
|
+
|
72
|
+
@start_date
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# 西暦終了日を取得する
|
77
|
+
#
|
78
|
+
# @return [Western::Calendar] 西暦終了日
|
79
|
+
#
|
80
|
+
def western_last_date
|
81
|
+
return Western::Calendar.new if @gengou.invalid?
|
82
|
+
|
83
|
+
@last_date
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# 次年にする
|
88
|
+
#
|
89
|
+
# @return [MultiGengou] 自身
|
90
|
+
#
|
91
|
+
def next_year
|
92
|
+
@japan_year += 1
|
93
|
+
@western_year += 1
|
94
|
+
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# 元号名を取得する
|
100
|
+
#
|
101
|
+
# @return [String] 元号名
|
102
|
+
#
|
103
|
+
def name
|
104
|
+
return '' unless @gengou
|
105
|
+
|
106
|
+
@gengou.name
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# 不正か
|
111
|
+
#
|
112
|
+
# @return [True] 不正
|
113
|
+
# @return [False] 不正なし
|
114
|
+
#
|
115
|
+
def invalid?
|
116
|
+
@gengou.invalid? || @japan_year == INVALID_YEAR || @western_year == INVALID_YEAR
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# 指定した日が元号に含まれるか
|
121
|
+
#
|
122
|
+
# @param [Western::Calendar] date 日
|
123
|
+
#
|
124
|
+
# @return [True] 含まれる
|
125
|
+
# @return [False] 含まれない
|
126
|
+
#
|
127
|
+
def include?
|
128
|
+
@gengou.include?
|
129
|
+
end
|
130
|
+
|
131
|
+
#
|
132
|
+
# 元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
|
133
|
+
#
|
134
|
+
# @return [True] 存在する
|
135
|
+
# @return [False] 存在しない
|
136
|
+
#
|
137
|
+
def changed?
|
138
|
+
return true if change_start_date?
|
139
|
+
|
140
|
+
return true if change_last_date?
|
141
|
+
|
142
|
+
false
|
143
|
+
end
|
144
|
+
|
145
|
+
#
|
146
|
+
# 開始日が設定された開始日と異なるか(行が変更されているか)
|
147
|
+
#
|
148
|
+
# @return [True] 異なる
|
149
|
+
# @return [False] 同一
|
150
|
+
#
|
151
|
+
def change_start_date?
|
152
|
+
return false if invalid?
|
153
|
+
|
154
|
+
@start_date != native_start_date
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# 終了日が設定された終了日と異なるか(行が変更されているか)
|
159
|
+
#
|
160
|
+
# @return [True] 異なる
|
161
|
+
# @return [False] 同一
|
162
|
+
#
|
163
|
+
def change_last_date?
|
164
|
+
return false if invalid?
|
165
|
+
|
166
|
+
@last_date != native_last_date
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# ディープコピー
|
171
|
+
#
|
172
|
+
# @param [MultiGengou] obj 自身
|
173
|
+
#
|
174
|
+
def initialize_copy(obj)
|
175
|
+
@gengou = obj.gengou.clone
|
176
|
+
@japan_year = obj.japan_year
|
177
|
+
@western_year = obj.western_year
|
178
|
+
@start_date = obj.start_date.clone
|
179
|
+
@last_date = obj.last_date.clone
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
#
|
185
|
+
# 有効な日付範囲を選択する
|
186
|
+
#
|
187
|
+
def select_valid_date
|
188
|
+
return if @gengou.invalid?
|
189
|
+
|
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
|
+
end
|
193
|
+
|
194
|
+
#
|
195
|
+
# 設定された元号の開始日を取得する
|
196
|
+
#
|
197
|
+
# @return [Western::Calendar]設定された元号の開始日
|
198
|
+
#
|
199
|
+
def native_start_date
|
200
|
+
@gengou.both_start_date.western
|
201
|
+
end
|
202
|
+
|
203
|
+
#
|
204
|
+
# 設定された元号の終了日を取得する
|
205
|
+
#
|
206
|
+
# @return [Western::Calendar] 設定された元号の終了日
|
207
|
+
#
|
208
|
+
def native_last_date
|
209
|
+
@gengou.last_date
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../era/western/calendar'
|
4
|
+
require_relative '../../../base/linear_gengou'
|
5
|
+
|
6
|
+
# :nodoc:
|
7
|
+
module Zakuro
|
8
|
+
# :nodoc:
|
9
|
+
module Calculation
|
10
|
+
# :nodoc:
|
11
|
+
module Gengou
|
12
|
+
# Publisher
|
13
|
+
#
|
14
|
+
# 元号発行
|
15
|
+
#
|
16
|
+
module Publisher
|
17
|
+
#
|
18
|
+
# 発行する
|
19
|
+
#
|
20
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
21
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
22
|
+
# @param [Array<Counter>] first_gengou 1行目元号
|
23
|
+
# @param [Array<Counter>] second_gengou 2行目元号
|
24
|
+
#
|
25
|
+
# @return [Base::Gengou] 元号
|
26
|
+
#
|
27
|
+
def self.run(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
28
|
+
first_gengou: [], second_gengou: [])
|
29
|
+
|
30
|
+
Base::Gengou.new(
|
31
|
+
start_date: start_date,
|
32
|
+
last_date: last_date,
|
33
|
+
first_line: to_linear_gengou(
|
34
|
+
start_date: start_date, last_date: last_date, gengou_list: first_gengou
|
35
|
+
),
|
36
|
+
second_line: to_linear_gengou(
|
37
|
+
start_date: start_date, last_date: last_date, gengou_list: second_gengou
|
38
|
+
)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
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?
|
57
|
+
|
58
|
+
result = []
|
59
|
+
|
60
|
+
gengou_list.each do |gengou|
|
61
|
+
if gengou.invalid?
|
62
|
+
# 無効元号は無効のままにする
|
63
|
+
result.push(Base::LinearGengou.new)
|
64
|
+
next
|
65
|
+
end
|
66
|
+
|
67
|
+
linear_gengou = to_limited_linear_gengou(
|
68
|
+
start_date: start_date,
|
69
|
+
last_date: last_date,
|
70
|
+
gengou: gengou
|
71
|
+
)
|
72
|
+
result.push(linear_gengou)
|
73
|
+
end
|
74
|
+
|
75
|
+
result
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# 範囲を限定した直列元号に変換する
|
80
|
+
#
|
81
|
+
# * 開始日・終了日により範囲を狭める
|
82
|
+
#
|
83
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
84
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
85
|
+
# @param [Counter] gengou 加算元号
|
86
|
+
#
|
87
|
+
# @return [Base::LinearGengou] 元号
|
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
|
92
|
+
|
93
|
+
gengou_start_date = start_date.clone if start_date > gengou_start_date
|
94
|
+
gengou_last_date = last_date.clone if last_date < gengou_last_date
|
95
|
+
|
96
|
+
Base::LinearGengou.new(
|
97
|
+
start_date: gengou_start_date, last_date: gengou_last_date,
|
98
|
+
name: gengou.name, year: gengou.japan_year
|
99
|
+
)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../../era/japan/gengou/resource'
|
4
|
+
require_relative '../../../../../era/japan/gengou'
|
5
|
+
require_relative '../../../../../era/japan/calendar'
|
6
|
+
require_relative '../../../../../era/western/calendar'
|
7
|
+
|
8
|
+
require_relative '../counter'
|
9
|
+
|
10
|
+
# :nodoc:
|
11
|
+
module Zakuro
|
12
|
+
# :nodoc:
|
13
|
+
module Calculation
|
14
|
+
# :nodoc:
|
15
|
+
module Gengou
|
16
|
+
# :nodoc:
|
17
|
+
module Reserve
|
18
|
+
# List
|
19
|
+
#
|
20
|
+
# 予約元号一覧
|
21
|
+
#
|
22
|
+
class List
|
23
|
+
# @return [Integer] 不正年
|
24
|
+
INVALID_YEAR = -1
|
25
|
+
# @return [Integer] 最大月日数
|
26
|
+
MAX_MONTH_DAYS = 30
|
27
|
+
|
28
|
+
# @return [Symbol] 行番号
|
29
|
+
attr_reader :index
|
30
|
+
# @return [Western::Calendar] 開始日
|
31
|
+
attr_reader :start_date
|
32
|
+
# @return [Western::Calendar] 終了日
|
33
|
+
attr_reader :last_date
|
34
|
+
# @return [Array<Japan::Alignment::LinearGengou>] 予約元号一覧
|
35
|
+
attr_reader :list
|
36
|
+
|
37
|
+
#
|
38
|
+
# 初期化
|
39
|
+
#
|
40
|
+
# @param [True, False] first true:1行目元号, false:2行目元号
|
41
|
+
# @param [Western::Calendar] start_date 開始日
|
42
|
+
# @param [Western::Calendar] last_date 終了日
|
43
|
+
#
|
44
|
+
def initialize(first: true, start_date: Western::Calendar.new,
|
45
|
+
last_date: Western::Calendar)
|
46
|
+
@index = first ? Japan::Gengou::FIRST_LINE : Japan::Gengou::SECOND_LINE
|
47
|
+
@start_date = start_date.clone
|
48
|
+
@last_date = last_date.invalid? ? start_date.clone : last_date.clone
|
49
|
+
@list = []
|
50
|
+
|
51
|
+
update
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# 元号を取得する
|
56
|
+
#
|
57
|
+
# @param [Western::Calendar] western_date 西暦日
|
58
|
+
#
|
59
|
+
# @return [Gengou::Counter] 加算元号
|
60
|
+
#
|
61
|
+
def get(western_date: Western::Calendar.new)
|
62
|
+
@list.each do |linear_gengou|
|
63
|
+
next if linear_gengou.out?(start_date: western_date, last_date: western_date)
|
64
|
+
|
65
|
+
Gengou::Counter.new(gengou: linear_gengou.gengou).clone
|
66
|
+
end
|
67
|
+
|
68
|
+
Gengou::Counter.new
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# 範囲内元号を取得する
|
73
|
+
#
|
74
|
+
# @param [Western::Calendar] start_date 西暦開始日
|
75
|
+
# @param [Western::Calendar] last_date 西暦終了日
|
76
|
+
#
|
77
|
+
# @return [Array<Gengou::Counter>] 範囲内元号
|
78
|
+
#
|
79
|
+
def collect(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
|
80
|
+
result = []
|
81
|
+
|
82
|
+
@list.each do |linear_gengou|
|
83
|
+
next if linear_gengou.out?(start_date: start_date, last_date: last_date)
|
84
|
+
|
85
|
+
result.push(
|
86
|
+
Gengou::Counter.new(
|
87
|
+
gengou: linear_gengou.gengou.clone,
|
88
|
+
start_date: linear_gengou.start_date.clone,
|
89
|
+
last_date: linear_gengou.last_date.clone
|
90
|
+
)
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: refactor
|
95
|
+
if result.size.zero?
|
96
|
+
result.push(
|
97
|
+
Gengou::Counter.new(
|
98
|
+
gengou: Japan::Resource::Gengou.new(
|
99
|
+
both_start_date: Japan::Resource::Both::Date.new(
|
100
|
+
western: start_date.clone
|
101
|
+
),
|
102
|
+
last_date: last_date.clone
|
103
|
+
)
|
104
|
+
)
|
105
|
+
)
|
106
|
+
return result
|
107
|
+
end
|
108
|
+
|
109
|
+
# FIXME: 有効元号の前後しか見ていない
|
110
|
+
if start_date < result[0].start_date
|
111
|
+
result.unshift(
|
112
|
+
Gengou::Counter.new(
|
113
|
+
gengou: Japan::Resource::Gengou.new,
|
114
|
+
start_date: start_date.clone,
|
115
|
+
last_date: result[0].start_date.clone - 1
|
116
|
+
)
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
if last_date > result[-1].last_date
|
121
|
+
result.push(
|
122
|
+
Gengou::Counter.new(
|
123
|
+
gengou: Japan::Resource::Gengou.new,
|
124
|
+
start_date: result[0].last_date.clone + 1,
|
125
|
+
last_date: last_date.clone
|
126
|
+
)
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# 和暦開始日を取得する
|
135
|
+
#
|
136
|
+
# @return [Japan::Calendar] 和暦開始日
|
137
|
+
#
|
138
|
+
def japan_start_date
|
139
|
+
return Japan::Calendar.new if invalid?
|
140
|
+
|
141
|
+
@list[0].gengou.both_start_date.japan.clone
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# 西暦開始日を取得する
|
146
|
+
#
|
147
|
+
# @return [Western::Calendar] 西暦開始日
|
148
|
+
#
|
149
|
+
def western_start_date
|
150
|
+
return Western::Calendar.new if invalid?
|
151
|
+
|
152
|
+
@list[0].gengou.both_start_date.western.clone
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# 西暦開始年を取得する
|
157
|
+
#
|
158
|
+
# @return [Integer] 西暦開始年
|
159
|
+
#
|
160
|
+
def western_start_year
|
161
|
+
return INVALID_YEAR if invalid?
|
162
|
+
|
163
|
+
@list[0].gengou.both_start_year.western.clone
|
164
|
+
end
|
165
|
+
|
166
|
+
#
|
167
|
+
# 西暦終了年を取得する
|
168
|
+
#
|
169
|
+
# @return [Integer] 西暦終了年
|
170
|
+
#
|
171
|
+
def western_last_year
|
172
|
+
return INVALID_YEAR if invalid?
|
173
|
+
|
174
|
+
return INVALID_YEAR if @list.size.zero?
|
175
|
+
|
176
|
+
@list[-1].gengou.last_year
|
177
|
+
end
|
178
|
+
|
179
|
+
#
|
180
|
+
# 不正か
|
181
|
+
#
|
182
|
+
# @return [True] 不正
|
183
|
+
# @return [False] 不正なし
|
184
|
+
#
|
185
|
+
def invalid?
|
186
|
+
return true unless @list
|
187
|
+
|
188
|
+
return true if @list.size.zero?
|
189
|
+
|
190
|
+
false
|
191
|
+
end
|
192
|
+
|
193
|
+
#
|
194
|
+
# 設定された元号の開始日を取得する
|
195
|
+
#
|
196
|
+
# @return [Western::Calendar]設定された元号の開始日
|
197
|
+
#
|
198
|
+
def native_start_date
|
199
|
+
return Western::Calendar.new if @list.size.zero?
|
200
|
+
|
201
|
+
@list[0].native_start_date
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# 開始日が設定された開始日と異なるか(行が変更されているか)
|
206
|
+
#
|
207
|
+
# @return [True] 異なる
|
208
|
+
# @return [False] 同一
|
209
|
+
#
|
210
|
+
def change_start_date?
|
211
|
+
return false if @list.size.zero?
|
212
|
+
|
213
|
+
@list[0].change_start_date?
|
214
|
+
end
|
215
|
+
|
216
|
+
private
|
217
|
+
|
218
|
+
#
|
219
|
+
# 予約元号一覧を更新する
|
220
|
+
#
|
221
|
+
def update
|
222
|
+
# 開始日の30日前に前の元号がある場合は、前の元号を設定する
|
223
|
+
start_date = @start_date.clone - (MAX_MONTH_DAYS + 1)
|
224
|
+
# 開始日の30日後に次の元号がある場合は、次の元号を設定する
|
225
|
+
last_date = @last_date.clone + (MAX_MONTH_DAYS + 1)
|
226
|
+
|
227
|
+
@list |= line(start_date: start_date, last_date: last_date)
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# 元号
|
232
|
+
#
|
233
|
+
# @param [Western::Calendar] date 日付
|
234
|
+
#
|
235
|
+
# @return [Array<Japan::Alignment::LinearGengou>] 元号
|
236
|
+
#
|
237
|
+
def line(start_date:, last_date:)
|
238
|
+
Japan::Gengou.line(line: @index, start_date: start_date, last_date: last_date)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|