zakuro 0.2.0 → 0.6.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 +17 -1
- data/VERSION +1 -0
- data/doc/gengou.md +22 -22
- data/doc/operation/csv/month.csv +468 -202
- 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 +104 -0
- data/lib/zakuro/calculation/base/year.rb +28 -13
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +29 -29
- data/lib/zakuro/calculation/gengou/internal/counter.rb +129 -0
- data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +183 -0
- data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +382 -0
- data/lib/zakuro/calculation/gengou/internal/reserve.rb +42 -0
- data/lib/zakuro/calculation/gengou/scroll.rb +262 -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 +49 -5
- data/lib/zakuro/calculation/range/full_range.rb +65 -103
- data/lib/zakuro/calculation/range/operated_range.rb +73 -23
- 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/single_day.rb +13 -35
- data/lib/zakuro/calculation/stella/lunar/abstract_location.rb +9 -7
- data/lib/zakuro/calculation/stella/lunar/choukei_value.rb +19 -0
- data/lib/zakuro/calculation/summary/single.rb +5 -2
- data/lib/zakuro/calculation/version/internal/crawler.rb +51 -0
- data/lib/zakuro/calculation/version/internal/range.rb +39 -0
- data/lib/zakuro/calculation/version/version.rb +24 -0
- data/lib/zakuro/era/japan/calendar.rb +133 -0
- data/lib/zakuro/era/japan/gengou/parser.rb +95 -25
- data/lib/zakuro/era/japan/gengou/type.rb +148 -41
- data/lib/zakuro/era/japan/gengou/validator.rb +157 -52
- data/lib/zakuro/era/japan/gengou/yaml/set-001-until-south.yaml +1870 -0
- data/lib/zakuro/era/japan/gengou/yaml/set-002-from-north.yaml +810 -0
- data/lib/zakuro/era/japan/gengou/yaml/set-003-modern.yaml +50 -0
- data/lib/zakuro/era/japan/gengou.rb +5 -5
- 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 +12 -3
- data/lib/zakuro/operation/month/parser.rb +1 -1
- data/lib/zakuro/operation/month/type.rb +59 -1
- data/lib/zakuro/operation/month/validator.rb +1 -1
- data/lib/zakuro/operation/yaml/month.yaml +8512 -0
- data/lib/zakuro/output/response.rb +5 -5
- data/lib/zakuro/tools/typeconv.rb +38 -0
- data/lib/zakuro/tools/typeof.rb +4 -1
- data/lib/zakuro/version/context.rb +25 -4
- data/lib/zakuro/version/daien/const/number.rb +55 -0
- data/lib/zakuro/version/daien/const/remainder.rb +53 -0
- data/lib/zakuro/version/daien/cycle/remainder.rb +85 -0
- data/lib/zakuro/version/daien/cycle/solar_term.rb +34 -0
- data/lib/zakuro/version/daien/daien.rb +11 -0
- data/lib/zakuro/version/daien/monthly/lunar_phase.rb +106 -0
- data/lib/zakuro/version/daien/range/annual_range.rb +39 -0
- data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +240 -0
- data/lib/zakuro/version/daien/stella/lunar/localization.rb +44 -0
- data/lib/zakuro/version/daien/stella/lunar/location.rb +80 -0
- data/lib/zakuro/version/daien/stella/lunar/value.rb +75 -0
- data/lib/zakuro/version/daien/stella/origin/average_november.rb +34 -0
- data/lib/zakuro/version/daien/stella/origin/lunar_age.rb +62 -0
- data/lib/zakuro/version/daien/stella/origin/winter_solstice.rb +55 -0
- data/lib/zakuro/version/daien/stella/solar/adjustment.rb +93 -0
- data/lib/zakuro/version/daien/stella/solar/average.rb +98 -0
- data/lib/zakuro/version/daien/stella/solar/interval.rb +108 -0
- data/lib/zakuro/version/daien/stella/solar/location.rb +61 -0
- data/lib/zakuro/version/daien/stella/solar/value.rb +36 -0
- 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/const/remainder.rb +0 -2
- data/lib/zakuro/version/gihou/cycle/remainder.rb +27 -6
- data/lib/zakuro/version/gihou/gihou.rb +1 -30
- data/lib/zakuro/version/gihou/monthly/lunar_phase.rb +1 -1
- data/lib/zakuro/version/gihou/stella/lunar/location.rb +2 -8
- data/lib/zakuro/version/gihou/stella/lunar/value.rb +3 -2
- data/lib/zakuro/version/gihou/stella/solar/average.rb +3 -3
- 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/const/remainder.rb +0 -2
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +27 -6
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +1 -1
- data/lib/zakuro/version/senmyou/senmyou.rb +1 -30
- data/lib/zakuro/version/senmyou/stella/lunar/location.rb +2 -8
- data/lib/zakuro/version/senmyou/stella/lunar/value.rb +3 -2
- data/lib/zakuro/version/senmyou/stella/solar/average.rb +3 -3
- data/lib/zakuro/version/tenpou/tenpou.rb +1 -9
- data/lib/zakuro/version/version_class_resolver.rb +8 -0
- data/zakuro.gemspec +1 -3
- metadata +50 -14
- 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/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/taien/taien.rb +0 -19
- data/lib/zakuro/version.rb +0 -7
- data/lib/zakuro/version_factory.rb +0 -59
@@ -0,0 +1,133 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../tools/typeconv'
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
module Zakuro
|
7
|
+
#
|
8
|
+
# Japan 和暦
|
9
|
+
#
|
10
|
+
module Japan
|
11
|
+
#
|
12
|
+
# Calendar 年月日情報(和暦)
|
13
|
+
#
|
14
|
+
class Calendar
|
15
|
+
# @return [Integer] 無効値
|
16
|
+
INVALID = -1
|
17
|
+
# @return [String] 空文字列
|
18
|
+
EMPTY = ''
|
19
|
+
# @return [String] 閏を示す文字列
|
20
|
+
LEAPED_TEXT = '閏'
|
21
|
+
# @return [Regexp] 和暦日フォーマット
|
22
|
+
FORMAT = /^([一-龥]{2,4})([0-9]+)年(#{LEAPED_TEXT})?([0-9]+)月([0-9]+)日$/.freeze
|
23
|
+
# @return [String] 出力用デフォルトフォーマット
|
24
|
+
DEFAULT_OUTPUT_FORM = '%s%02d年%s%02d月%02d日'
|
25
|
+
|
26
|
+
# @return [String] 元号
|
27
|
+
attr_reader :gengou
|
28
|
+
# @return [Integer] 元号年
|
29
|
+
attr_reader :year
|
30
|
+
# @return [True] 閏あり
|
31
|
+
# @return [False] 閏なし
|
32
|
+
attr_reader :leaped
|
33
|
+
# @return [Integer] 月
|
34
|
+
attr_reader :month
|
35
|
+
# @return [Integer] 日
|
36
|
+
attr_reader :day
|
37
|
+
|
38
|
+
#
|
39
|
+
# 初期化
|
40
|
+
#
|
41
|
+
# @param [String] gengou 元号
|
42
|
+
# @param [Integer] year 元号年
|
43
|
+
# @param [True, False] leaped 閏
|
44
|
+
# @param [Integer] month 月
|
45
|
+
# @param [Integer] day 日
|
46
|
+
#
|
47
|
+
def initialize(gengou: EMPTY, year: INVALID, leaped: false, month: INVALID, day: INVALID)
|
48
|
+
@gengou = gengou
|
49
|
+
@year = year
|
50
|
+
@leaped = leaped
|
51
|
+
@month = month
|
52
|
+
@day = day
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# 無効か
|
57
|
+
#
|
58
|
+
# @return [True] 無効
|
59
|
+
# @return [False] 有効
|
60
|
+
#
|
61
|
+
def invalid?
|
62
|
+
@gengou == EMPTY || @year == INVALID || @month == INVALID || @day == INVALID
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# 文字列にする
|
67
|
+
#
|
68
|
+
# @return [String] 和暦日フォーマット文字列
|
69
|
+
#
|
70
|
+
def format(form: DEFAULT_OUTPUT_FORM)
|
71
|
+
leaped_text = @leaped ? LEAPED_TEXT : ''
|
72
|
+
super(form, @gengou, @year, leaped_text, @month, @day)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# 同月か
|
77
|
+
# 年と日は無視する
|
78
|
+
#
|
79
|
+
# @param [True, False] leaped 閏
|
80
|
+
# @param [Integer] month 月
|
81
|
+
#
|
82
|
+
# @return [True] 同月
|
83
|
+
# @return [True] 同月ではない
|
84
|
+
#
|
85
|
+
def same_month?(leaped:, month:)
|
86
|
+
return false unless @leaped == leaped
|
87
|
+
|
88
|
+
@month == month
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# 年月日情報(和暦)を生成する
|
93
|
+
#
|
94
|
+
# @param [Regexp] regex 正規表現
|
95
|
+
# @param [String] text 和暦日文字列
|
96
|
+
#
|
97
|
+
# @return [Calendar] 年月日情報(和暦)
|
98
|
+
#
|
99
|
+
def self.parse(regex: FORMAT, text: '')
|
100
|
+
return Calendar.new unless valid_date_string(regex: regex, text: text)
|
101
|
+
|
102
|
+
matched = text.match(regex)
|
103
|
+
|
104
|
+
Calendar.new(
|
105
|
+
gengou: matched[1],
|
106
|
+
year: Tools::Typeconv.to_i(text: matched[2], default: INVALID),
|
107
|
+
leaped: matched[3] ? true : false,
|
108
|
+
month: Tools::Typeconv.to_i(text: matched[4], default: INVALID),
|
109
|
+
day: Tools::Typeconv.to_i(text: matched[5], default: INVALID)
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# 日付文字列を検証する
|
115
|
+
#
|
116
|
+
# @param [Regexp] regex 正規表現
|
117
|
+
# @param [String] text 和暦日文字列
|
118
|
+
#
|
119
|
+
# @return [True] 正しい
|
120
|
+
# @return [True] 正しくない
|
121
|
+
#
|
122
|
+
def self.valid_date_string(regex: FORMAT, text: '')
|
123
|
+
return false unless text
|
124
|
+
|
125
|
+
matched = text.match(regex)
|
126
|
+
|
127
|
+
return false unless matched
|
128
|
+
|
129
|
+
matched.size == 6
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../../western'
|
3
|
+
require_relative '../../western/calendar'
|
4
4
|
require_relative './type'
|
5
5
|
require_relative './validator'
|
6
6
|
require 'yaml'
|
@@ -17,8 +17,6 @@ module Zakuro
|
|
17
17
|
# Parser yaml解析
|
18
18
|
#
|
19
19
|
module Parser
|
20
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
21
|
-
|
22
20
|
#
|
23
21
|
# GengouParser 元号情報の検証/展開を行う
|
24
22
|
#
|
@@ -27,12 +25,10 @@ module Zakuro
|
|
27
25
|
attr_reader :index
|
28
26
|
# @return [String] 元号名
|
29
27
|
attr_reader :name
|
30
|
-
# @return [String]
|
31
|
-
attr_reader :
|
32
|
-
# @return [String]
|
33
|
-
attr_reader :
|
34
|
-
# @return [String] 開始年
|
35
|
-
attr_reader :start_year
|
28
|
+
# @return [Hash<String, String>] 開始年
|
29
|
+
attr_reader :both_start_year
|
30
|
+
# @return [Hash<String, String>] 開始日
|
31
|
+
attr_reader :both_start_date
|
36
32
|
|
37
33
|
#
|
38
34
|
# 初期化
|
@@ -43,9 +39,8 @@ module Zakuro
|
|
43
39
|
def initialize(hash:, index:)
|
44
40
|
@index = index
|
45
41
|
@name = hash['name']
|
46
|
-
@
|
47
|
-
@
|
48
|
-
@start_year = hash['start_year']
|
42
|
+
@both_start_year = hash['start_year']
|
43
|
+
@both_start_date = hash['start_date']
|
49
44
|
end
|
50
45
|
|
51
46
|
#
|
@@ -54,12 +49,11 @@ module Zakuro
|
|
54
49
|
# @return [Gengou] 元号情報
|
55
50
|
#
|
56
51
|
def create
|
57
|
-
|
58
|
-
|
59
|
-
start_year = @start_year || 1
|
52
|
+
both_start_year = Both::YearParser.new(hash: @both_start_year).create
|
53
|
+
both_start_date = Both::DateParser.new(hash: @both_start_date).create
|
60
54
|
|
61
|
-
Gengou.new(name: @name,
|
62
|
-
|
55
|
+
Gengou.new(name: @name, both_start_year: both_start_year,
|
56
|
+
both_start_date: both_start_date)
|
63
57
|
end
|
64
58
|
end
|
65
59
|
|
@@ -71,8 +65,10 @@ module Zakuro
|
|
71
65
|
attr_reader :id
|
72
66
|
# @return [String] 元号セット名
|
73
67
|
attr_reader :name
|
74
|
-
# @return [String]
|
75
|
-
attr_reader :
|
68
|
+
# @return [Hash<String, String>] 終了年
|
69
|
+
attr_reader :both_end_year
|
70
|
+
# @return [Hash<String, String>] 終了日
|
71
|
+
attr_reader :both_end_date
|
76
72
|
# @return [Array<Hash<String, String>>] 元号情報
|
77
73
|
attr_reader :list
|
78
74
|
|
@@ -84,7 +80,8 @@ module Zakuro
|
|
84
80
|
def initialize(hash:)
|
85
81
|
@id = hash['id']
|
86
82
|
@name = hash['name']
|
87
|
-
@
|
83
|
+
@both_end_year = hash['end_year']
|
84
|
+
@both_end_date = hash['end_date']
|
88
85
|
@list = hash['list']
|
89
86
|
end
|
90
87
|
|
@@ -94,10 +91,10 @@ module Zakuro
|
|
94
91
|
# @return [Set] 元号セット情報
|
95
92
|
#
|
96
93
|
def create
|
97
|
-
|
94
|
+
both_end_date = Both::DateParser.new(hash: @both_end_date).create
|
98
95
|
list = create_list
|
99
96
|
Set.new(
|
100
|
-
id: @id, name: @name,
|
97
|
+
id: @id, name: @name, both_end_date: both_end_date, list: list
|
101
98
|
)
|
102
99
|
end
|
103
100
|
|
@@ -133,18 +130,91 @@ module Zakuro
|
|
133
130
|
#
|
134
131
|
def calc_end_date_on_gengou_data(next_index:, gengou:)
|
135
132
|
if next_index >= @list.size
|
136
|
-
|
133
|
+
gengou.write_end_year(end_year: @both_end_year['western'])
|
134
|
+
end_date = Western::Calendar.parse(str: @both_end_date['western'])
|
137
135
|
gengou.write_end_date(end_date: end_date)
|
138
136
|
return gengou
|
139
137
|
end
|
140
|
-
|
138
|
+
next_item = @list[next_index]
|
139
|
+
gengou.convert_next_start_year_to_end_year(
|
140
|
+
next_start_year: next_item['start_year']['western']
|
141
|
+
)
|
141
142
|
gengou.convert_next_start_date_to_end_date(
|
142
|
-
|
143
|
+
next_start_date: next_item['start_date']['western']
|
143
144
|
)
|
144
145
|
gengou
|
145
146
|
end
|
146
147
|
end
|
147
148
|
|
149
|
+
#
|
150
|
+
# 和暦/西暦
|
151
|
+
#
|
152
|
+
module Both
|
153
|
+
#
|
154
|
+
# YearParser 年
|
155
|
+
#
|
156
|
+
class YearParser
|
157
|
+
# @return [Integer] 和暦元号年
|
158
|
+
attr_reader :japan
|
159
|
+
# @return [Integer] 西暦年
|
160
|
+
attr_reader :western
|
161
|
+
|
162
|
+
#
|
163
|
+
# 初期化
|
164
|
+
#
|
165
|
+
# @param [Hash<String, Object>] hash 年情報
|
166
|
+
#
|
167
|
+
def initialize(hash:)
|
168
|
+
@japan = hash['japan']
|
169
|
+
@western = hash['western']
|
170
|
+
end
|
171
|
+
|
172
|
+
#
|
173
|
+
# 年情報を生成する
|
174
|
+
#
|
175
|
+
# @return [Both::Year] 年情報
|
176
|
+
#
|
177
|
+
def create
|
178
|
+
japan = @japan.to_i
|
179
|
+
western = @western.to_i
|
180
|
+
|
181
|
+
Japan::Both::Year.new(japan: japan, western: western)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
#
|
186
|
+
# DateParser 日
|
187
|
+
#
|
188
|
+
class DateParser
|
189
|
+
# @return [Japan::Calendar] 和暦日
|
190
|
+
attr_reader :japan
|
191
|
+
# @return [Western::Calendar] 西暦日
|
192
|
+
attr_reader :western
|
193
|
+
|
194
|
+
#
|
195
|
+
# 初期化
|
196
|
+
#
|
197
|
+
# @param [Hash<String, Object>] hash 日情報
|
198
|
+
#
|
199
|
+
def initialize(hash:)
|
200
|
+
@japan = hash['japan']
|
201
|
+
@western = hash['western']
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# 日情報を生成する
|
206
|
+
#
|
207
|
+
# @return [Both::Date] 日情報
|
208
|
+
#
|
209
|
+
def create
|
210
|
+
japan = Japan::Calendar.parse(text: @japan)
|
211
|
+
western = Western::Calendar.parse(str: @western)
|
212
|
+
|
213
|
+
Japan::Both::Date.new(japan: japan, western: western)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
148
218
|
#
|
149
219
|
# 解析/展開する
|
150
220
|
#
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../../western'
|
3
|
+
require_relative '../../western/calendar'
|
4
4
|
|
5
5
|
# :nodoc:
|
6
6
|
module Zakuro
|
@@ -8,40 +8,52 @@ module Zakuro
|
|
8
8
|
# Japan 和暦
|
9
9
|
#
|
10
10
|
module Japan
|
11
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 5 }
|
12
|
-
|
13
11
|
#
|
14
12
|
# Gengou 元号情報
|
15
13
|
#
|
16
14
|
class Gengou
|
17
15
|
# @return [String] 元号名
|
18
16
|
attr_reader :name
|
19
|
-
# @return [
|
20
|
-
attr_reader :
|
21
|
-
# @return [
|
22
|
-
attr_reader :
|
17
|
+
# @return [Both::Year] 開始年(和暦/西暦)
|
18
|
+
attr_reader :both_start_year
|
19
|
+
# @return [Both::Date] 開始日(和暦/西暦)
|
20
|
+
attr_reader :both_start_date
|
21
|
+
# @return [Integer] 終了年
|
22
|
+
attr_reader :end_year
|
23
23
|
# @return [Western::Calendar] 終了日
|
24
24
|
attr_reader :end_date
|
25
|
-
# @return [Integer] 元号年
|
26
|
-
attr_reader :year
|
27
25
|
|
28
26
|
#
|
29
27
|
# 初期化
|
30
28
|
#
|
31
29
|
# @param [String] name 元号名
|
32
|
-
# @param [
|
33
|
-
# @param [
|
30
|
+
# @param [Both::Year] both_start_year 開始年(和暦/西暦)
|
31
|
+
# @param [Both::Date] both_start_date 開始日(和暦/西暦)
|
32
|
+
# @param [Integer] end_date 終了年
|
34
33
|
# @param [Western::Calendar] end_date 終了日
|
35
|
-
# @param [Integer] year 元号年
|
36
34
|
#
|
37
|
-
def initialize(name: '',
|
38
|
-
|
39
|
-
end_date: Western::Calendar.new,
|
35
|
+
def initialize(name: '', both_start_year: Both::Year.new,
|
36
|
+
both_start_date: Both::Date.new,
|
37
|
+
end_date: Western::Calendar.new,
|
38
|
+
end_year: Both::Year::INVALID)
|
40
39
|
@name = name
|
41
|
-
@
|
42
|
-
@
|
40
|
+
@both_start_year = both_start_year
|
41
|
+
@both_start_date = both_start_date
|
42
|
+
@end_year = end_year
|
43
43
|
@end_date = end_date
|
44
|
-
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# 終了年を更新する
|
48
|
+
#
|
49
|
+
# @param [Integer] end_year 終了年
|
50
|
+
#
|
51
|
+
def write_end_year(end_year:)
|
52
|
+
unless Gengou.valid_year(year: end_year)
|
53
|
+
raise ArgumentError, "invalid year format. [#{end_year}]"
|
54
|
+
end
|
55
|
+
|
56
|
+
@end_year = end_year
|
45
57
|
end
|
46
58
|
|
47
59
|
#
|
@@ -59,12 +71,26 @@ module Zakuro
|
|
59
71
|
end
|
60
72
|
|
61
73
|
#
|
62
|
-
#
|
74
|
+
# 年が不正なしかどうかを確認する
|
75
|
+
#
|
76
|
+
# @param [Integer] year 年
|
77
|
+
#
|
78
|
+
# @return [True] 不正なし
|
79
|
+
# @return [False] 不正
|
80
|
+
#
|
81
|
+
def self.valid_year(year:)
|
82
|
+
return false unless year
|
83
|
+
|
84
|
+
year.is_a?(Integer)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# 日付が不正なしかどうかを確認する
|
63
89
|
#
|
64
90
|
# @param [Western::Calendar] date 日付
|
65
91
|
#
|
66
|
-
# @return [True]
|
67
|
-
# @return [False]
|
92
|
+
# @return [True] 不正なし
|
93
|
+
# @return [False] 不正
|
68
94
|
#
|
69
95
|
def self.valid_date(date:)
|
70
96
|
return false unless date
|
@@ -72,16 +98,33 @@ module Zakuro
|
|
72
98
|
date.is_a?(Western::Calendar)
|
73
99
|
end
|
74
100
|
|
101
|
+
#
|
102
|
+
# 次の元号の開始年から、元号の終了年に変換する
|
103
|
+
#
|
104
|
+
# @param [Integer] next_start_year 次回開始年
|
105
|
+
#
|
106
|
+
def convert_next_start_year_to_end_year(next_start_year:)
|
107
|
+
if @both_start_year.western >= next_start_year
|
108
|
+
@end_year = next_start_year
|
109
|
+
return
|
110
|
+
end
|
111
|
+
|
112
|
+
@end_year = next_start_year - 1
|
113
|
+
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
75
117
|
#
|
76
118
|
# 次の元号の開始日から、元号の終了日に変換する
|
77
119
|
#
|
78
|
-
# @param [String]
|
120
|
+
# @param [String] next_start_date 次回開始日
|
79
121
|
#
|
80
|
-
def convert_next_start_date_to_end_date(
|
81
|
-
raise ArgumentError, 'empty string cannot convert' if
|
122
|
+
def convert_next_start_date_to_end_date(next_start_date: '')
|
123
|
+
raise ArgumentError, 'empty string cannot convert' if next_start_date.empty?
|
82
124
|
|
83
|
-
start_date = Western::Calendar.parse(str:
|
125
|
+
start_date = Western::Calendar.parse(str: next_start_date)
|
84
126
|
@end_date = start_date - 1
|
127
|
+
|
85
128
|
nil
|
86
129
|
end
|
87
130
|
|
@@ -94,30 +137,31 @@ module Zakuro
|
|
94
137
|
# @return [False] 含まれない
|
95
138
|
#
|
96
139
|
def include?(date:)
|
97
|
-
date >= @
|
140
|
+
date >= @both_start_date.western && date <= @end_date
|
98
141
|
end
|
99
142
|
|
100
143
|
#
|
101
|
-
#
|
144
|
+
# 不正か
|
102
145
|
#
|
103
|
-
# @return [True]
|
104
|
-
# @return [
|
146
|
+
# @return [True] 不正
|
147
|
+
# @return [False] 不正なし
|
105
148
|
#
|
106
149
|
def invalid?
|
107
|
-
@
|
150
|
+
@both_start_year.japan == -1 || @both_start_year.invalid? ||
|
151
|
+
@both_start_date.invalid? || @end_date.invalid?
|
108
152
|
end
|
109
153
|
|
110
154
|
#
|
111
155
|
# 1元号年を追加する
|
112
156
|
#
|
113
|
-
def next_year
|
114
|
-
|
115
|
-
|
116
|
-
end
|
157
|
+
# def next_year
|
158
|
+
# @year += 1 unless invalid?
|
159
|
+
# nil
|
160
|
+
# end
|
117
161
|
|
118
162
|
def to_s
|
119
|
-
"name: #{@name},
|
120
|
-
"
|
163
|
+
"name: #{@name}, both_start_year: #{@both_start_year.format}, " \
|
164
|
+
"both_start_date: #{@both_start_date.format}, end_date: #{@end_date.format}"
|
121
165
|
end
|
122
166
|
end
|
123
167
|
|
@@ -125,12 +169,16 @@ module Zakuro
|
|
125
169
|
# Set 元号セット
|
126
170
|
#
|
127
171
|
class Set
|
172
|
+
# @return [Integer] 不正値
|
173
|
+
INVALID = -1
|
128
174
|
# @return [Integer] 元号セットID
|
129
175
|
attr_reader :id
|
130
176
|
# @return [String] 元号セット名
|
131
177
|
attr_reader :name
|
132
|
-
# @return [
|
133
|
-
attr_reader :
|
178
|
+
# @return [Both::Date] 元号セットでの終了年
|
179
|
+
attr_reader :both_end_year
|
180
|
+
# @return [Both::Date] 元号セットでの終了日
|
181
|
+
attr_reader :both_end_date
|
134
182
|
# @return [Array<Gengou>] 元号リスト
|
135
183
|
attr_reader :list
|
136
184
|
|
@@ -142,10 +190,12 @@ module Zakuro
|
|
142
190
|
# @param [Western::Calendar] end_date 元号セットでの終了日
|
143
191
|
# @param [Array<Gengou>] list 元号リスト
|
144
192
|
#
|
145
|
-
def initialize(id:
|
193
|
+
def initialize(id: INVALID, name: '', both_end_year: Both::Year.new,
|
194
|
+
both_end_date: Both::Date.new, list: [])
|
146
195
|
@id = id
|
147
196
|
@name = name
|
148
|
-
@
|
197
|
+
@both_end_year = both_end_year
|
198
|
+
@both_end_date = both_end_date
|
149
199
|
@list = list
|
150
200
|
end
|
151
201
|
|
@@ -171,7 +221,64 @@ module Zakuro
|
|
171
221
|
# @return [False] 正しい
|
172
222
|
#
|
173
223
|
def invalid?
|
174
|
-
@id ==
|
224
|
+
@id == INVALID
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
#
|
229
|
+
# 和暦/西暦
|
230
|
+
#
|
231
|
+
module Both
|
232
|
+
#
|
233
|
+
# Year 年
|
234
|
+
#
|
235
|
+
class Year
|
236
|
+
# @return [Integer] 不正値
|
237
|
+
INVALID = -1
|
238
|
+
# @return [Integer] 和暦元号年
|
239
|
+
attr_reader :japan
|
240
|
+
# @return [Integer] 西暦年
|
241
|
+
attr_reader :western
|
242
|
+
|
243
|
+
def initialize(japan: INVALID, western: INVALID)
|
244
|
+
@japan = japan
|
245
|
+
@western = western
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# 不正か
|
250
|
+
#
|
251
|
+
# @return [True] 不正
|
252
|
+
# @return [False] 不正なし
|
253
|
+
#
|
254
|
+
def invalid?
|
255
|
+
@japan == INVALID || @western == INVALID
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
#
|
260
|
+
# Date 日
|
261
|
+
#
|
262
|
+
class Date
|
263
|
+
# @return [Japan::Calendar] 和暦日
|
264
|
+
attr_reader :japan
|
265
|
+
# @return [Western::Calendar] 西暦日
|
266
|
+
attr_reader :western
|
267
|
+
|
268
|
+
def initialize(japan: Japan::Calendar.new, western: Western::Calendar.new)
|
269
|
+
@japan = japan
|
270
|
+
@western = western
|
271
|
+
end
|
272
|
+
|
273
|
+
#
|
274
|
+
# 不正か
|
275
|
+
#
|
276
|
+
# @return [True] 不正
|
277
|
+
# @return [False] 不正なし
|
278
|
+
#
|
279
|
+
def invalid?
|
280
|
+
@japan.invalid? || @western.invalid?
|
281
|
+
end
|
175
282
|
end
|
176
283
|
end
|
177
284
|
end
|