zakuro 0.6.1 → 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/Makefile +3 -0
- data/README.md +46 -17
- data/VERSION +1 -1
- data/doc/dropped_date.md +93 -0
- data/doc/error.md +45 -0
- data/doc/operation/transfer.rb +8 -8
- data/lib/zakuro/calculation/base/day.rb +52 -0
- data/lib/zakuro/calculation/base/gengou.rb +49 -3
- 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/{scroll.rb → abstract_scroll.rb} +44 -37
- data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
- 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/{list.rb → abstract_list.rb} +50 -64
- data/lib/zakuro/calculation/era/gengou/internal/reserve/{range.rb → abstract_range.rb} +73 -50
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +156 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +73 -0
- data/lib/zakuro/calculation/era/gengou/internal/reserve.rb +23 -22
- data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
- 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 +55 -16
- 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/{full_range.rb → abstract_full_range.rb} +45 -29
- data/lib/zakuro/calculation/range/abstract_operation_range.rb +193 -0
- data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
- data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
- data/lib/zakuro/calculation/range/medieval_annual_range.rb +64 -63
- data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
- data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
- 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/{specifier → summary}/internal/month.rb +33 -12
- 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 +179 -0
- data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
- data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +98 -0
- data/lib/zakuro/calculation/summary/japan/specifier/specified_range.rb +34 -0
- data/lib/zakuro/calculation/summary/western/range.rb +127 -0
- data/lib/zakuro/calculation/summary/western/single.rb +115 -0
- data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +173 -0
- data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +100 -0
- data/lib/zakuro/calculation/type/old_float.rb +2 -2
- data/lib/zakuro/calculation/type/optional.rb +46 -0
- data/lib/zakuro/condition.rb +143 -94
- 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 +93 -74
- data/lib/zakuro/era/japan/gengou/alignment/division.rb +135 -133
- data/lib/zakuro/era/japan/gengou/alignment/line.rb +143 -122
- data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +177 -168
- data/lib/zakuro/era/japan/gengou/alignment.rb +40 -25
- data/lib/zakuro/era/japan/gengou/resource/parser.rb +199 -181
- data/lib/zakuro/era/japan/gengou/resource/type.rb +243 -234
- data/lib/zakuro/era/japan/gengou/resource/validator.rb +257 -254
- data/lib/zakuro/era/japan/gengou/resource.rb +23 -22
- data/lib/zakuro/era/japan/gengou.rb +28 -41
- 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 +71 -0
- data/lib/zakuro/exception/case/preset.rb +51 -0
- data/lib/zakuro/exception/case/template.rb +48 -0
- data/lib/zakuro/exception/cause.rb +28 -0
- data/lib/zakuro/exception/exception.rb +39 -0
- data/lib/zakuro/exception/zakuro_error.rb +46 -0
- data/lib/zakuro/gateway/locale/date.rb +127 -0
- data/lib/zakuro/gateway/locale/range.rb +67 -0
- data/lib/zakuro/gateway/range.rb +99 -0
- data/lib/zakuro/gateway/single.rb +81 -0
- data/lib/zakuro/merchant.rb +67 -33
- data/lib/zakuro/operation/month/parser.rb +252 -249
- data/lib/zakuro/operation/month/type.rb +44 -35
- data/lib/zakuro/operation/month/validator.rb +182 -178
- data/lib/zakuro/operation/operation.rb +38 -36
- data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
- data/lib/zakuro/output/logger.rb +17 -3
- data/lib/zakuro/output/response.rb +107 -141
- data/lib/zakuro/result/data/day.rb +43 -0
- data/lib/zakuro/result/data/gengou.rb +35 -0
- data/lib/zakuro/result/data/month.rb +63 -0
- 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 +56 -0
- data/lib/zakuro/result/data/solar_term.rb +35 -0
- data/lib/zakuro/result/data/year.rb +45 -0
- data/lib/zakuro/result/operation/month/annotation.rb +40 -0
- data/lib/zakuro/result/operation/month/history.rb +54 -0
- data/lib/zakuro/result/operation/month.rb +31 -0
- data/lib/zakuro/result/operation.rb +22 -97
- data/lib/zakuro/result/result.rb +6 -4
- 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 +5 -0
- 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 +68 -16
- data/lib/zakuro/calculation/range/operated_range.rb +0 -193
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +0 -220
- data/lib/zakuro/calculation/specifier/multiple_day.rb +0 -162
- data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
- data/lib/zakuro/calculation/summary/range.rb +0 -120
- data/lib/zakuro/calculation/summary/single.rb +0 -110
- data/lib/zakuro/result/data.rb +0 -187
- data/lib/zakuro/version/context.rb +0 -44
- data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -9,146 +9,167 @@ module Zakuro
|
|
9
9
|
# :nodoc:
|
10
10
|
module Japan
|
11
11
|
# :nodoc:
|
12
|
-
module
|
13
|
-
#
|
14
|
-
|
15
|
-
#
|
16
|
-
class Line
|
17
|
-
# @return [Array<LinearGengou>] 元号
|
18
|
-
attr_reader :list
|
19
|
-
|
12
|
+
module Gengou
|
13
|
+
# :nodoc:
|
14
|
+
module Alignment
|
20
15
|
#
|
21
|
-
#
|
16
|
+
# Line 行
|
22
17
|
#
|
23
|
-
|
24
|
-
@
|
25
|
-
|
18
|
+
class Line
|
19
|
+
# @return [Array<LinearGengou>] 元号
|
20
|
+
attr_reader :list
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# 1. 完全に範囲外(開始日より前)
|
33
|
-
# [@list]: |-------|-------|
|
34
|
-
# [list]: |---|
|
35
|
-
# 2. 前半のみ範囲外
|
36
|
-
# [@list]: |-------|-------|
|
37
|
-
# [list]: |------|
|
38
|
-
# 3. 範囲内
|
39
|
-
# [@list]: |-------|-------|
|
40
|
-
# [list]: |------|
|
41
|
-
# 4. 後半のみ範囲外
|
42
|
-
# [@list]: |-------|-------|
|
43
|
-
# [list]: |------|
|
44
|
-
# 5. 完全に範囲外(開始日より後)
|
45
|
-
# [@list]: |-------|-------|
|
46
|
-
# [list]: |----|
|
47
|
-
# 6. 両端が範囲外
|
48
|
-
# [@list]: |-------|-------|
|
49
|
-
# [list]: |--------------------|
|
50
|
-
#
|
51
|
-
# @param [Array<LinearGengou>] list 元号
|
52
|
-
#
|
53
|
-
# @return [Array<LinearGengou>] 未登録元号
|
54
|
-
#
|
55
|
-
def push(list: [])
|
56
|
-
rest = rest(list: list)
|
57
|
-
|
58
|
-
insert(list: list)
|
59
|
-
|
60
|
-
rest
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
# 範囲内の元号を取得する
|
65
|
-
#
|
66
|
-
# @param [Western::Calendar] start_date 開始日
|
67
|
-
# @param [Western::Calendar] last_date 終了日
|
68
|
-
#
|
69
|
-
# @return [Array<LinearGengou>] 元号
|
70
|
-
#
|
71
|
-
def get(start_date:, last_date:)
|
72
|
-
result = []
|
73
|
-
@list.each do |gengou|
|
74
|
-
next if gengou.out?(start_date: start_date, last_date: last_date)
|
75
|
-
|
76
|
-
# 1日でも範囲内であれば対象とみなす
|
77
|
-
result.push(gengou)
|
22
|
+
#
|
23
|
+
# 初期化
|
24
|
+
#
|
25
|
+
def initialize
|
26
|
+
@list = []
|
78
27
|
end
|
79
28
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
29
|
+
#
|
30
|
+
# 追加する
|
31
|
+
#
|
32
|
+
# 下記のパターンが存在し、戻り値は重複分となる
|
33
|
+
#
|
34
|
+
# 1. 完全に範囲外(開始日より前)
|
35
|
+
# [@list]: |-------|-------|
|
36
|
+
# [list]: |---|
|
37
|
+
# 2. 前半のみ範囲外
|
38
|
+
# [@list]: |-------|-------|
|
39
|
+
# [list]: |------|
|
40
|
+
# 3. 範囲内
|
41
|
+
# [@list]: |-------|-------|
|
42
|
+
# [list]: |------|
|
43
|
+
# 4. 後半のみ範囲外
|
44
|
+
# [@list]: |-------|-------|
|
45
|
+
# [list]: |------|
|
46
|
+
# 5. 完全に範囲外(開始日より後)
|
47
|
+
# [@list]: |-------|-------|
|
48
|
+
# [list]: |----|
|
49
|
+
# 6. 両端が範囲外
|
50
|
+
# [@list]: |-------|-------|
|
51
|
+
# [list]: |--------------------|
|
52
|
+
#
|
53
|
+
# @param [Array<LinearGengou>] list 元号
|
54
|
+
#
|
55
|
+
# @return [Array<LinearGengou>] 未登録元号
|
56
|
+
#
|
57
|
+
def push(list: [])
|
58
|
+
rest = rest(list: list)
|
59
|
+
|
60
|
+
insert(list: list)
|
61
|
+
|
62
|
+
rest
|
63
|
+
end
|
84
64
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
65
|
+
#
|
66
|
+
# 範囲内の元号を取得する
|
67
|
+
#
|
68
|
+
# @param [Western::Calendar] start_date 開始日
|
69
|
+
# @param [Western::Calendar] last_date 終了日
|
70
|
+
#
|
71
|
+
# @return [Array<LinearGengou>] 元号
|
72
|
+
#
|
73
|
+
def get(start_date:, last_date:)
|
74
|
+
result = []
|
75
|
+
list.each do |gengou|
|
76
|
+
next if gengou.out?(start_date: start_date, last_date: last_date)
|
77
|
+
|
78
|
+
# 1日でも範囲内であれば対象とみなす
|
79
|
+
result.push(gengou)
|
80
|
+
end
|
81
|
+
|
82
|
+
result
|
83
|
+
end
|
94
84
|
|
95
|
-
|
96
|
-
|
85
|
+
#
|
86
|
+
# 範囲内の元号を取得する(元号名)
|
87
|
+
#
|
88
|
+
# @param [String] name 元号名
|
89
|
+
#
|
90
|
+
# @return [Array<LinearGengou>] 元号
|
91
|
+
#
|
92
|
+
def get_by_name(name:)
|
93
|
+
result = []
|
94
|
+
list.each do |gengou|
|
95
|
+
result.push(gengou) if gengou.name == name
|
96
|
+
end
|
97
|
+
|
98
|
+
result
|
97
99
|
end
|
98
100
|
|
99
|
-
|
100
|
-
end
|
101
|
+
private
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
103
|
+
#
|
104
|
+
# 重複分(空きがないため追加できない範囲の元号)を返す
|
105
|
+
#
|
106
|
+
# @param [Array<LinearGengou>] list 元号
|
107
|
+
#
|
108
|
+
# @return [Array<LinearGengou>] 重複分元号
|
109
|
+
#
|
110
|
+
def rest(list: [])
|
111
|
+
result = []
|
112
112
|
|
113
|
-
|
113
|
+
inner_list = @list
|
114
|
+
inner_list.each do |gengou|
|
115
|
+
result |= and!(rest: list, other: gengou)
|
116
|
+
end
|
114
117
|
|
115
|
-
|
116
|
-
@list.push(gengou)
|
118
|
+
Division.connect(list: result)
|
117
119
|
end
|
118
|
-
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
121
|
+
#
|
122
|
+
# 空き範囲に元号を登録する
|
123
|
+
#
|
124
|
+
# @param [Array<LinearGengou>] list 元号
|
125
|
+
#
|
126
|
+
def insert(list: [])
|
127
|
+
inner_list = @list
|
128
|
+
surplus_result = list.clone
|
129
|
+
inner_list.each do |gengou|
|
130
|
+
surplus_result = not!(surplus: surplus_result, other: gengou)
|
131
|
+
end
|
132
|
+
|
133
|
+
surplus_result = Division.connect(list: surplus_result)
|
134
|
+
|
135
|
+
surplus_result.each do |gengou|
|
136
|
+
inner_list.push(gengou)
|
137
|
+
end
|
132
138
|
end
|
133
139
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
result
|
140
|
+
#
|
141
|
+
# 重複した範囲を返す
|
142
|
+
#
|
143
|
+
# @param [Array<LinearGengou>] rest 残り元号
|
144
|
+
# @param [LinearGengou] other 比較元号
|
145
|
+
#
|
146
|
+
# @return [Array<LinearGengou>] 重複分
|
147
|
+
#
|
148
|
+
def and!(rest:, other:)
|
149
|
+
result = []
|
150
|
+
rest.each do |gengou|
|
151
|
+
result |= Division.match(this: gengou, other: other)
|
152
|
+
end
|
153
|
+
|
154
|
+
result
|
149
155
|
end
|
150
156
|
|
151
|
-
|
157
|
+
#
|
158
|
+
# 範囲が重複しない差分を返す
|
159
|
+
#
|
160
|
+
# @param [Array<LinearGengou>] surplus 積元号
|
161
|
+
# @param [LinearGengou] other 比較元号
|
162
|
+
#
|
163
|
+
# @return [Array<LinearGengou>] 差分
|
164
|
+
#
|
165
|
+
def not!(surplus:, other:)
|
166
|
+
result = []
|
167
|
+
surplus.each do |gengou|
|
168
|
+
result |= Division.mismatch(this: gengou, other: other)
|
169
|
+
end
|
170
|
+
|
171
|
+
result
|
172
|
+
end
|
152
173
|
end
|
153
174
|
end
|
154
175
|
end
|
@@ -9,174 +9,183 @@ module Zakuro
|
|
9
9
|
# :nodoc:
|
10
10
|
module Japan
|
11
11
|
# :nodoc:
|
12
|
-
module
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
12
|
+
module Gengou
|
13
|
+
# :nodoc:
|
14
|
+
module Alignment
|
15
|
+
#
|
16
|
+
# LinearGengou 直列元号
|
17
|
+
#
|
18
|
+
class LinearGengou
|
19
|
+
INVALID_YEAR = -1
|
20
|
+
|
21
|
+
# @return [Western::Calendar] 開始日
|
22
|
+
attr_reader :start_date
|
23
|
+
# @return [Western::Calendar] 終了日
|
24
|
+
attr_reader :last_date
|
25
|
+
# @return [Gengou] 元号
|
26
|
+
attr_reader :gengou
|
27
|
+
|
28
|
+
#
|
29
|
+
# 初期化
|
30
|
+
#
|
31
|
+
# @param [Western::Calendar] start_date 開始日
|
32
|
+
# @param [Western::Calendar] last_date 終了日
|
33
|
+
# @param [Resource::Gengou] gengou 元号
|
34
|
+
#
|
35
|
+
def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
|
36
|
+
gengou: Resource::Gengou.new)
|
37
|
+
@gengou = gengou
|
38
|
+
@start_date = start_date.invalid? ? native_start_date : start_date
|
39
|
+
@last_date = last_date.invalid? ? native_last_date : last_date
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# 元号名を取得する
|
44
|
+
#
|
45
|
+
# @return [String] 元号名
|
46
|
+
#
|
47
|
+
def name
|
48
|
+
gengou.name
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# 不正か
|
53
|
+
#
|
54
|
+
# @return [True] 不正
|
55
|
+
# @return [False] 不正なし
|
56
|
+
#
|
57
|
+
def invalid?
|
58
|
+
gengou.invalid?
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# 範囲内か
|
63
|
+
#
|
64
|
+
# @param [Western::Calendar] date 西暦日
|
65
|
+
#
|
66
|
+
# @return [True] 範囲内
|
67
|
+
# @return [False] 範囲外
|
68
|
+
#
|
69
|
+
def include?(date: Western::Calendar.new)
|
70
|
+
return false if invalid?
|
71
|
+
|
72
|
+
return false if start_date.invalid?
|
73
|
+
|
74
|
+
return false if last_date.invalid?
|
75
|
+
|
76
|
+
return false if date < start_date
|
77
|
+
|
78
|
+
return false if date > last_date
|
79
|
+
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# 完全に範囲内か
|
85
|
+
#
|
86
|
+
# @param [Western::Calendar] start_date 開始日
|
87
|
+
# @param [Western::Calendar] last_date 終了日
|
88
|
+
#
|
89
|
+
# @return [True] 範囲内
|
90
|
+
# @return [False] 範囲外あり
|
91
|
+
#
|
92
|
+
def in?(start_date:, last_date:)
|
93
|
+
inner_start_date = @start_date
|
94
|
+
inner_last_date = @last_date
|
95
|
+
inner_start_date <= start_date && last_date <= inner_last_date
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# 完全に範囲外か
|
100
|
+
#
|
101
|
+
# @param [Western::Calendar] start_date 開始日
|
102
|
+
# @param [Western::Calendar] last_date 終了日
|
103
|
+
#
|
104
|
+
# @return [True] 範囲外
|
105
|
+
# @return [False] 範囲内あり
|
106
|
+
#
|
107
|
+
def out?(start_date:, last_date:)
|
108
|
+
inner_start_date = @start_date
|
109
|
+
inner_last_date = @last_date
|
110
|
+
# 範囲より前
|
111
|
+
return true if start_date < inner_start_date && last_date < inner_start_date
|
112
|
+
|
113
|
+
# 範囲より後
|
114
|
+
return true if inner_last_date < start_date && inner_last_date < last_date
|
115
|
+
|
116
|
+
false
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# 完全に範囲を超えているか
|
121
|
+
#
|
122
|
+
# @param [Western::Calendar] start_date 開始日
|
123
|
+
# @param [Western::Calendar] last_date 終了日
|
124
|
+
#
|
125
|
+
# @return [True] 完全超過
|
126
|
+
# @return [True] 完全超過せず
|
127
|
+
#
|
128
|
+
def covered?(start_date:, last_date:)
|
129
|
+
inner_start_date = @start_date
|
130
|
+
inner_last_date = @last_date
|
131
|
+
start_date < inner_start_date && inner_last_date < last_date
|
132
|
+
end
|
133
|
+
|
134
|
+
#
|
135
|
+
# 元は1繋ぎであった元号が別の行に存在するか(設定値から変更されているか)?
|
136
|
+
#
|
137
|
+
# @return [True] 存在する
|
138
|
+
# @return [False] 存在しない
|
139
|
+
#
|
140
|
+
def changed?
|
141
|
+
return true if change_start_date?
|
142
|
+
|
143
|
+
return true if change_last_date?
|
144
|
+
|
145
|
+
false
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# 開始日が設定された開始日と異なるか(行が変更されているか)
|
150
|
+
#
|
151
|
+
# @return [True] 異なる
|
152
|
+
# @return [False] 同一
|
153
|
+
#
|
154
|
+
def change_start_date?
|
155
|
+
return false if invalid?
|
156
|
+
|
157
|
+
start_date != native_start_date
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# 終了日が設定された終了日と異なるか(行が変更されているか)
|
162
|
+
#
|
163
|
+
# @return [True] 異なる
|
164
|
+
# @return [False] 同一
|
165
|
+
#
|
166
|
+
def change_last_date?
|
167
|
+
return false if invalid?
|
168
|
+
|
169
|
+
last_date != native_last_date
|
170
|
+
end
|
171
|
+
|
172
|
+
#
|
173
|
+
# 設定された元号の開始日を取得する
|
174
|
+
#
|
175
|
+
# @return [Western::Calendar]設定された元号の開始日
|
176
|
+
#
|
177
|
+
def native_start_date
|
178
|
+
gengou.both_start_date.western
|
179
|
+
end
|
180
|
+
|
181
|
+
#
|
182
|
+
# 設定された元号の終了日を取得する
|
183
|
+
#
|
184
|
+
# @return [Western::Calendar] 設定された元号の終了日
|
185
|
+
#
|
186
|
+
def native_last_date
|
187
|
+
gengou.last_date
|
188
|
+
end
|
180
189
|
end
|
181
190
|
end
|
182
191
|
end
|