zakuro 0.0.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +102 -42
- data/doc/operation.md +25 -0
- data/doc/operation/csv/month.csv +202 -0
- data/doc/operation/operation.xlsx +0 -0
- data/doc/operation/transfer.rb +77 -0
- data/lib/zakuro/calculation/base/multi_gengou.rb +101 -0
- data/lib/zakuro/calculation/base/multi_gengou_roller.rb +218 -0
- data/lib/zakuro/calculation/base/year.rb +107 -0
- data/lib/zakuro/calculation/cycle/abstract_remainder.rb +459 -0
- data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +151 -0
- data/lib/zakuro/calculation/cycle/zodiac.rb +106 -0
- data/lib/zakuro/calculation/monthly/first_day.rb +45 -0
- data/lib/zakuro/calculation/monthly/initialized_month.rb +120 -0
- data/lib/zakuro/calculation/monthly/month.rb +184 -0
- data/lib/zakuro/calculation/monthly/month_label.rb +88 -0
- data/lib/zakuro/calculation/monthly/operated_month.rb +201 -0
- data/lib/zakuro/calculation/range/full_range.rb +210 -0
- data/lib/zakuro/calculation/range/operated_range.rb +134 -0
- data/lib/zakuro/calculation/range/operated_solar_terms.rb +201 -0
- data/lib/zakuro/calculation/range/transfer/western_date_allocation.rb +76 -0
- data/lib/zakuro/calculation/range/transfer/year_boundary.rb +142 -0
- data/lib/zakuro/calculation/specifier/single_day.rb +109 -0
- data/lib/zakuro/calculation/summary/single.rb +129 -0
- data/lib/zakuro/condition.rb +17 -13
- data/lib/zakuro/era/japan/gengou.rb +106 -0
- data/lib/zakuro/era/japan/gengou/parser.rb +167 -0
- data/lib/zakuro/era/japan/gengou/type.rb +178 -0
- data/lib/zakuro/era/japan/gengou/validator.rb +236 -0
- data/lib/zakuro/era/japan/reki.rb +91 -0
- data/lib/zakuro/era/{gengou → japan/yaml}/set-001-until-south.yaml +0 -0
- data/lib/zakuro/era/{gengou → japan/yaml}/set-002-from-north.yaml +0 -0
- data/lib/zakuro/era/{gengou → japan/yaml}/set-003-modern.yaml +1 -1
- data/lib/zakuro/era/western.rb +1 -1
- data/lib/zakuro/merchant.rb +2 -2
- data/lib/zakuro/operation/month/parser.rb +373 -0
- data/lib/zakuro/operation/month/type.rb +453 -0
- data/lib/zakuro/operation/month/validator.rb +802 -0
- data/lib/zakuro/operation/operation.rb +66 -0
- data/lib/zakuro/operation/yaml/month.yaml +6452 -0
- data/lib/zakuro/output/error.rb +7 -4
- data/lib/zakuro/output/logger.rb +50 -47
- data/lib/zakuro/output/response.rb +146 -143
- data/lib/zakuro/result/core.rb +52 -0
- data/lib/zakuro/result/data.rb +187 -0
- data/lib/zakuro/result/operation.rb +114 -0
- data/lib/zakuro/result/result.rb +37 -0
- data/lib/zakuro/{output → tools}/stringifier.rb +16 -9
- data/lib/zakuro/tools/typeof.rb +33 -0
- data/lib/zakuro/version.rb +1 -1
- data/lib/zakuro/version/abstract_version.rb +1 -1
- data/lib/zakuro/version/context.rb +23 -0
- data/lib/zakuro/version/senmyou/cycle/remainder.rb +63 -0
- data/lib/zakuro/version/senmyou/cycle/solar_term.rb +31 -0
- data/lib/zakuro/version/senmyou/monthly/lunar_phase.rb +186 -182
- data/lib/zakuro/version/senmyou/range/annual_range.rb +164 -0
- data/lib/zakuro/version/senmyou/senmyou.rb +10 -4
- data/lib/zakuro/version/senmyou/stella/lunar_orbit.rb +7 -7
- data/lib/zakuro/version/senmyou/stella/solar_average.rb +103 -138
- data/lib/zakuro/version/senmyou/stella/solar_location.rb +213 -0
- data/lib/zakuro/version/senmyou/stella/solar_orbit.rb +6 -191
- data/lib/zakuro/version/senmyou/stella/winter_solstice.rb +4 -4
- data/lib/zakuro/version/version_class_resolver.rb +62 -0
- data/lib/zakuro/version_factory.rb +3 -3
- metadata +49 -20
- data/lib/zakuro/cycle/abstract_remainder.rb +0 -457
- data/lib/zakuro/cycle/zodiac.rb +0 -103
- data/lib/zakuro/era/japan.rb +0 -660
- data/lib/zakuro/output/result.rb +0 -219
- data/lib/zakuro/version/senmyou/base/era.rb +0 -83
- data/lib/zakuro/version/senmyou/base/multi_gengou.rb +0 -98
- data/lib/zakuro/version/senmyou/base/multi_gengou_roller.rb +0 -205
- data/lib/zakuro/version/senmyou/base/remainder.rb +0 -60
- data/lib/zakuro/version/senmyou/base/solar_term.rb +0 -66
- data/lib/zakuro/version/senmyou/base/year.rb +0 -104
- data/lib/zakuro/version/senmyou/monthly/month.rb +0 -122
- data/lib/zakuro/version/senmyou/summary/annual_range.rb +0 -186
- data/lib/zakuro/version/senmyou/summary/full_range.rb +0 -216
- data/lib/zakuro/version/senmyou/summary/specifier.rb +0 -100
data/lib/zakuro/output/result.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
require_relative './stringifier'
|
6
|
-
|
7
|
-
# :nodoc:
|
8
|
-
module Zakuro
|
9
|
-
#
|
10
|
-
# Result 演算結果
|
11
|
-
#
|
12
|
-
module Result
|
13
|
-
#
|
14
|
-
# Gengou 元号
|
15
|
-
#
|
16
|
-
class Gengou
|
17
|
-
# @return [String] 元号名
|
18
|
-
attr_reader :name
|
19
|
-
# @return [Integer] 元号年
|
20
|
-
attr_reader :number
|
21
|
-
|
22
|
-
#
|
23
|
-
# 初期化
|
24
|
-
#
|
25
|
-
# @param [String] name 元号名
|
26
|
-
# @param [Integer] number 元号年
|
27
|
-
#
|
28
|
-
def initialize(name:, number:)
|
29
|
-
@name = name
|
30
|
-
@number = number
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# Year 年
|
36
|
-
#
|
37
|
-
class Year
|
38
|
-
# @return [Gengou] 元号(1行目)
|
39
|
-
attr_reader :first_gengou
|
40
|
-
# @return [Gengou] 元号(2行目)
|
41
|
-
attr_reader :second_gengou
|
42
|
-
# @return [String] 十干十二支
|
43
|
-
attr_reader :zodiac_name
|
44
|
-
# @return [Integer] 日数
|
45
|
-
attr_reader :total_days
|
46
|
-
|
47
|
-
#
|
48
|
-
# 初期化
|
49
|
-
#
|
50
|
-
# @param [Gengou] first_gengou 元号(1行目)
|
51
|
-
# @param [Gengou] second_gengou 元号(2行目)
|
52
|
-
# @param [String] zodiac_name 十干十二支
|
53
|
-
# @param [Integer] total_days 日数
|
54
|
-
#
|
55
|
-
def initialize(first_gengou:, second_gengou:, zodiac_name:, total_days:)
|
56
|
-
@first_gengou = first_gengou
|
57
|
-
@second_gengou = second_gengou
|
58
|
-
@zodiac_name = zodiac_name
|
59
|
-
@total_days = total_days
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
# SolarTerm 二十四節気
|
65
|
-
#
|
66
|
-
class SolarTerm
|
67
|
-
# @return [Integer] 連番
|
68
|
-
attr_reader :index
|
69
|
-
# @return [String] 大余小余
|
70
|
-
attr_reader :remainder
|
71
|
-
|
72
|
-
#
|
73
|
-
# 初期化
|
74
|
-
#
|
75
|
-
# @param [Integer] index 連番
|
76
|
-
# @param [String] remainder 大余小余
|
77
|
-
#
|
78
|
-
def initialize(index:, remainder:)
|
79
|
-
@index = index
|
80
|
-
@remainder = remainder
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# :reek:TooManyInstanceVariables { max_instance_variables: 6 }
|
85
|
-
|
86
|
-
#
|
87
|
-
# Month 月
|
88
|
-
#
|
89
|
-
class Month
|
90
|
-
# TODO: days_name -> zodiac_name
|
91
|
-
|
92
|
-
# @return [Integer] 月順(1-12)
|
93
|
-
attr_reader :number
|
94
|
-
# @return [True] 閏月
|
95
|
-
# @return [False] 平月
|
96
|
-
attr_reader :leaped
|
97
|
-
# @return [String] 十干十二支
|
98
|
-
attr_reader :days_name
|
99
|
-
# @return [Day] 月初日データ
|
100
|
-
attr_reader :first_day
|
101
|
-
# @return [SolarTerm] 二十四節気(節気)
|
102
|
-
attr_reader :odd_solar_terms
|
103
|
-
# @return [SolarTerm] 二十四節気(中気)
|
104
|
-
attr_reader :even_solar_terms
|
105
|
-
|
106
|
-
# rubocop:disable Metrics/ParameterLists
|
107
|
-
# :reek:LongParameterList { max_params: 6 }
|
108
|
-
|
109
|
-
#
|
110
|
-
# 初期化
|
111
|
-
#
|
112
|
-
# @param [Integer] number 月順(1-12)
|
113
|
-
# @param [True, False] leaped 閏月/平月
|
114
|
-
# @param [String] days_name 十干十二支
|
115
|
-
# @param [Day] first_day 月初日データ
|
116
|
-
# @param [SolarTerm] odd_solar_terms 二十四節気(節気)
|
117
|
-
# @param [SolarTerm] even_solar_terms 二十四節気(中気)
|
118
|
-
#
|
119
|
-
def initialize(number:, leaped:, days_name:, first_day:,
|
120
|
-
odd_solar_terms:, even_solar_terms:)
|
121
|
-
@number = number
|
122
|
-
@leaped = leaped
|
123
|
-
@days_name = days_name
|
124
|
-
@first_day = first_day
|
125
|
-
@odd_solar_terms = odd_solar_terms
|
126
|
-
@even_solar_terms = even_solar_terms
|
127
|
-
end
|
128
|
-
# rubocop:enable Metrics/ParameterLists
|
129
|
-
end
|
130
|
-
|
131
|
-
#
|
132
|
-
# Day 日
|
133
|
-
#
|
134
|
-
class Day
|
135
|
-
# @return [Integer] 月初日から数えた日(M月d日のdに相当)
|
136
|
-
attr_reader :number
|
137
|
-
# @return [String] 十干十二支
|
138
|
-
attr_reader :zodiac_name
|
139
|
-
# @return [String] 大余小余
|
140
|
-
attr_reader :remainder
|
141
|
-
# @return [String] 年月日
|
142
|
-
attr_reader :western_date
|
143
|
-
|
144
|
-
#
|
145
|
-
# 初期化
|
146
|
-
#
|
147
|
-
# @param [Integer] number 月初日から数えた日(M月d日のdに相当)
|
148
|
-
# @param [String] zodiac_name 十干十二支
|
149
|
-
# @param [String] remainder 大余小余
|
150
|
-
# @param [String] western_date 年月日
|
151
|
-
#
|
152
|
-
def initialize(number:, zodiac_name:, remainder:, western_date:)
|
153
|
-
@number = number
|
154
|
-
@zodiac_name = zodiac_name
|
155
|
-
@remainder = remainder
|
156
|
-
@western_date = western_date
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
#
|
161
|
-
# Core 共通処理
|
162
|
-
#
|
163
|
-
class Core
|
164
|
-
#
|
165
|
-
# ハッシュ化する
|
166
|
-
#
|
167
|
-
# @return [Hash<String, Object>] ハッシュ
|
168
|
-
#
|
169
|
-
def to_h
|
170
|
-
Stringifier.to_h(obj: self, class_prefix: 'Zakuro::Result')
|
171
|
-
end
|
172
|
-
|
173
|
-
#
|
174
|
-
# JSON化する
|
175
|
-
#
|
176
|
-
# @param [JSON::State] _args 引数( Struct#to_json )
|
177
|
-
#
|
178
|
-
# @return [String] JSON文字列
|
179
|
-
#
|
180
|
-
def to_json(*_args)
|
181
|
-
JSON.generate(to_h)
|
182
|
-
end
|
183
|
-
|
184
|
-
#
|
185
|
-
# JSON(整形)化する
|
186
|
-
#
|
187
|
-
# @return [String] JSON(整形)文字列
|
188
|
-
#
|
189
|
-
def to_pretty_json
|
190
|
-
JSON.pretty_generate(to_h)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
#
|
195
|
-
# SingleDay 1日分情報
|
196
|
-
#
|
197
|
-
class SingleDay < Core
|
198
|
-
# @return [Year] 年
|
199
|
-
attr_reader :year
|
200
|
-
# @return [Month] 月
|
201
|
-
attr_reader :month
|
202
|
-
# @return [Day] 日
|
203
|
-
attr_reader :day
|
204
|
-
|
205
|
-
#
|
206
|
-
# 初期化
|
207
|
-
#
|
208
|
-
# @param [Year] year 年
|
209
|
-
# @param [Month] month 月
|
210
|
-
# @param [Day] day 日
|
211
|
-
#
|
212
|
-
def initialize(year:, month:, day:)
|
213
|
-
@year = year
|
214
|
-
@month = month
|
215
|
-
@day = day
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../../era/japan'
|
4
|
-
require_relative '../../../era/western'
|
5
|
-
require_relative '../../../cycle/zodiac'
|
6
|
-
|
7
|
-
# :nodoc:
|
8
|
-
module Zakuro
|
9
|
-
# :nodoc:
|
10
|
-
module Senmyou
|
11
|
-
#
|
12
|
-
# Era 宣明暦時代
|
13
|
-
#
|
14
|
-
module Era
|
15
|
-
# FIXME: JOUGAN_START_DATE は不要。'貞観' かどうかだけで良い
|
16
|
-
|
17
|
-
# @return [Western::Calendar] 貞観1年1月1日
|
18
|
-
JOUGAN_START_DATE = Western::Calendar.new(year: 859, month: 2, day: 7)
|
19
|
-
# @return [Western::Calendar] 貞観4年1月1日
|
20
|
-
START_DATE = Western::Calendar.new(year: 862, month: 2, day: 3)
|
21
|
-
# @return [Integer] (貞観)4年
|
22
|
-
START_GENGOU_YEAR = 4
|
23
|
-
# @return [Western::Calendar] 貞享2年12月29日
|
24
|
-
END_DATE = Western::Calendar.new(year: 1686, month: 1, day: 23)
|
25
|
-
|
26
|
-
#
|
27
|
-
# 元号(1行目)を取得する
|
28
|
-
#
|
29
|
-
# @param [Western::Calendar] start_date 開始日
|
30
|
-
#
|
31
|
-
# @return [Japan::Gengou] 元号(1行目)
|
32
|
-
#
|
33
|
-
def self.first(start_date:)
|
34
|
-
first_gengou = Japan::GengouResource.first_line(date: start_date)
|
35
|
-
# 宣明暦の初めの元号であれば、起算年を4年とする
|
36
|
-
if JOUGAN_START_DATE == first_gengou.start_date
|
37
|
-
first_gengou = Japan::Gengou.new(
|
38
|
-
name: first_gengou.name,
|
39
|
-
start_date: START_DATE,
|
40
|
-
end_date: first_gengou.end_date,
|
41
|
-
year: START_GENGOU_YEAR
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
first_gengou
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# 元号(2行目)を取得する
|
50
|
-
#
|
51
|
-
# @param [Western::Calendar] start_date 開始日
|
52
|
-
#
|
53
|
-
# @return [Japan::Gengou] 元号(2行目)
|
54
|
-
#
|
55
|
-
def self.second(start_date:)
|
56
|
-
Japan::GengouResource.second_line(date: start_date)
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# 宣明暦に含まれるかを確認する
|
61
|
-
#
|
62
|
-
# @param [Western::Calendar] date 日付
|
63
|
-
#
|
64
|
-
# @return [True] 含まれる
|
65
|
-
# @return [False] 含まれない
|
66
|
-
#
|
67
|
-
def self.include?(date:)
|
68
|
-
(START_DATE <= date && date <= END_DATE)
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# 十干十二支を引き当てる
|
73
|
-
#
|
74
|
-
# @param [String] western_year 西暦年
|
75
|
-
#
|
76
|
-
# @return [String] 十干十二支
|
77
|
-
#
|
78
|
-
def self.zodiac_name(western_year: 0)
|
79
|
-
Cycle::Zodiac.year_name(western_year: western_year)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../../era/japan'
|
4
|
-
require_relative '../../../era/western'
|
5
|
-
|
6
|
-
# :nodoc:
|
7
|
-
module Zakuro
|
8
|
-
# :nodoc:
|
9
|
-
module Senmyou
|
10
|
-
#
|
11
|
-
# MultiGengou 複数元号
|
12
|
-
#
|
13
|
-
class MultiGengou
|
14
|
-
# @return [Japan::Gengou] 元号(1行目)
|
15
|
-
attr_reader :first_line
|
16
|
-
# @return [Japan::Gengou] 元号(2行目)
|
17
|
-
attr_reader :second_line
|
18
|
-
# @return [Western::Calendar] 元旦
|
19
|
-
attr_reader :new_year_date
|
20
|
-
|
21
|
-
def initialize(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new,
|
22
|
-
new_year_date: Western::Calendar.new)
|
23
|
-
@first_line = first_line
|
24
|
-
@second_line = second_line
|
25
|
-
@new_year_date = new_year_date
|
26
|
-
end
|
27
|
-
|
28
|
-
# :reek:TooManyStatements { max_statements: 7 }
|
29
|
-
|
30
|
-
#
|
31
|
-
# 改元する
|
32
|
-
#
|
33
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
34
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
35
|
-
#
|
36
|
-
# @return [MultiGengou] 自身
|
37
|
-
#
|
38
|
-
def transfer(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new)
|
39
|
-
cloned_first_line = first_line.clone
|
40
|
-
cloned_second_line = second_line.clone
|
41
|
-
|
42
|
-
if integrated?(first_line: cloned_first_line, second_line: cloned_second_line)
|
43
|
-
@first_line = @second_line.clone
|
44
|
-
@second_line = cloned_second_line
|
45
|
-
end
|
46
|
-
|
47
|
-
@first_line = cloned_first_line if @first_line.name != first_line.name
|
48
|
-
@second_line = cloned_second_line if @second_line.name != second_line.name
|
49
|
-
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
#
|
54
|
-
# 次年にする
|
55
|
-
#
|
56
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
57
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
58
|
-
#
|
59
|
-
# @return [MultiGengou] 自身
|
60
|
-
#
|
61
|
-
def next_year
|
62
|
-
@first_line.next_year
|
63
|
-
@second_line.next_year
|
64
|
-
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
#
|
69
|
-
# ディープコピー
|
70
|
-
#
|
71
|
-
# @param [MultiGengou] obj 自身
|
72
|
-
#
|
73
|
-
def initialize_copy(obj)
|
74
|
-
@first_line = obj.first_line.clone
|
75
|
-
@second_line = obj.second_line.clone
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
#
|
81
|
-
# 複数元号を統一するかどうか
|
82
|
-
#
|
83
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
84
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
85
|
-
#
|
86
|
-
# @return [True] 統一する
|
87
|
-
# @return [False] 統一しない
|
88
|
-
#
|
89
|
-
def integrated?(first_line: Japan::Gengou.new, second_line: Japan::Gengou.new)
|
90
|
-
return false if @second_line.name != first_line.name
|
91
|
-
|
92
|
-
return false unless second_line.invalid?
|
93
|
-
|
94
|
-
true
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,205 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './era'
|
4
|
-
require_relative './multi_gengou'
|
5
|
-
|
6
|
-
require_relative '../../../era/japan'
|
7
|
-
|
8
|
-
# :nodoc:
|
9
|
-
module Zakuro
|
10
|
-
# :nodoc:
|
11
|
-
module Senmyou
|
12
|
-
# FIXME: 宣明暦に依存しない共通処理にする
|
13
|
-
|
14
|
-
#
|
15
|
-
# MultiGengouRoller 改元処理
|
16
|
-
#
|
17
|
-
class MultiGengouRoller
|
18
|
-
# @return [MultiGengou] 複数元号
|
19
|
-
attr_reader :multi_gengou
|
20
|
-
# @return [Western::Calendar] 元旦(元号が2つある場合は再過去の日付になる)
|
21
|
-
attr_reader :oldest_date
|
22
|
-
# @return [Western::Calendar] 元号内での最未来日(元号が2つある場合は再未来の日付になる)
|
23
|
-
attr_reader :newest_date
|
24
|
-
# @return [Western::Calendar] 現在日
|
25
|
-
attr_reader :current_date
|
26
|
-
|
27
|
-
def initialize(start_date: Era::START_DATE, end_date: Western::Calendar.new)
|
28
|
-
end_date = start_date if end_date.invalid?
|
29
|
-
|
30
|
-
@oldest_date = MultiGengouRoller.choise_oldest_gengou_date(
|
31
|
-
first_line: Era.first(start_date: start_date),
|
32
|
-
second_line: Era.second(start_date: start_date)
|
33
|
-
)
|
34
|
-
@current_date = @oldest_date.clone
|
35
|
-
@newest_date = MultiGengouRoller.choise_newest_gengou_date(
|
36
|
-
first_line: Era.first(start_date: end_date),
|
37
|
-
second_line: Era.second(start_date: end_date)
|
38
|
-
)
|
39
|
-
|
40
|
-
@multi_gengou = MultiGengou.new(
|
41
|
-
first_line: current_first_line,
|
42
|
-
second_line: current_second_line,
|
43
|
-
new_year_date: @oldest_date
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# 現在日付を未来に進める
|
49
|
-
#
|
50
|
-
# @param [<Type>] days <description>
|
51
|
-
#
|
52
|
-
# @return [<Type>] <description>
|
53
|
-
#
|
54
|
-
def next(days: 0)
|
55
|
-
@current_date += days
|
56
|
-
end
|
57
|
-
|
58
|
-
#
|
59
|
-
# 現在日から元号(1行目)を取得する
|
60
|
-
#
|
61
|
-
# @return [Japan::Gengou] 元号(1行目)
|
62
|
-
#
|
63
|
-
def current_first_line
|
64
|
-
MultiGengouRoller.first_line(date: @current_date)
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
# 現在日から元号(2行目)を取得する
|
69
|
-
#
|
70
|
-
# @return [Japan::Gengou] 元号(2行目)
|
71
|
-
#
|
72
|
-
def current_second_line
|
73
|
-
MultiGengouRoller.second_line(date: @current_date)
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# 改元する
|
78
|
-
#
|
79
|
-
# @return [MultiGengou] 複数元号
|
80
|
-
#
|
81
|
-
def transfer
|
82
|
-
MultiGengouRoller.transfer(multi_gengou: @multi_gengou, date: @current_date)
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# 次年にする
|
87
|
-
#
|
88
|
-
# @return [MultiGengou] 複数元号
|
89
|
-
#
|
90
|
-
def next_year
|
91
|
-
@multi_gengou.next_year
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# 元号(1行目)を取得する
|
96
|
-
#
|
97
|
-
# @return [Japan::Gengou] 元号(1行目)
|
98
|
-
#
|
99
|
-
def self.first_line(date: Western::Calender.new)
|
100
|
-
Era.first(start_date: date)
|
101
|
-
end
|
102
|
-
|
103
|
-
#
|
104
|
-
# 元号(2行目)を取得する
|
105
|
-
#
|
106
|
-
# @return [Japan::Gengou] 元号(2行目)
|
107
|
-
#
|
108
|
-
def self.second_line(date: Western::Calender.new)
|
109
|
-
Era.second(start_date: date)
|
110
|
-
end
|
111
|
-
|
112
|
-
#
|
113
|
-
# 改元する
|
114
|
-
#
|
115
|
-
# @param [MultiGengou] multi_gengou 複数元号
|
116
|
-
# @param [Western::Calendar] date 対象日
|
117
|
-
#
|
118
|
-
# @return [MultiGengou] 改元済み複数元号
|
119
|
-
#
|
120
|
-
def self.transfer(multi_gengou:, date:)
|
121
|
-
multi_gengou.transfer(
|
122
|
-
first_line: first_line(date: date),
|
123
|
-
second_line: second_line(date: date)
|
124
|
-
)
|
125
|
-
|
126
|
-
multi_gengou
|
127
|
-
end
|
128
|
-
|
129
|
-
#
|
130
|
-
# 現在日からみて直近の未来に対する元号の切替前日を求める
|
131
|
-
# @note 2つの元号が重複した場合はより過去の日となる
|
132
|
-
#
|
133
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
134
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
135
|
-
#
|
136
|
-
# @return [Western::Calendar] 元号の切替前日
|
137
|
-
#
|
138
|
-
def choise_nearest_end_date
|
139
|
-
condition = lambda do |first_date, second_date|
|
140
|
-
first_date < second_date ? first_date : second_date
|
141
|
-
end
|
142
|
-
|
143
|
-
second_line = current_second_line
|
144
|
-
|
145
|
-
MultiGengouRoller.choise_date(condition: condition, second_line: second_line,
|
146
|
-
first_date: current_first_line.end_date.clone,
|
147
|
-
second_date: second_line.end_date.clone)
|
148
|
-
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# 最過去の元旦を求める
|
152
|
-
# @note 2つの元号が重複した場合はより過去の日となる
|
153
|
-
#
|
154
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
155
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
156
|
-
#
|
157
|
-
# @return [Western::Calendar] 最過去の元旦
|
158
|
-
#
|
159
|
-
def self.choise_oldest_gengou_date(first_line:, second_line:)
|
160
|
-
condition = lambda do |first_date, second_date|
|
161
|
-
first_date < second_date ? first_date : second_date
|
162
|
-
end
|
163
|
-
choise_date(condition: condition, second_line: second_line,
|
164
|
-
first_date: first_line.new_year_date.clone,
|
165
|
-
second_date: second_line.new_year_date.clone)
|
166
|
-
end
|
167
|
-
|
168
|
-
#
|
169
|
-
# 元号内での最未来日を求める
|
170
|
-
# @note 2つの元号が重複した場合はより未来の日となる
|
171
|
-
#
|
172
|
-
# @param [Japan::Gengou] first_line 元号(1行目)
|
173
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
174
|
-
#
|
175
|
-
# @return [Western::Calendar] 最未来日
|
176
|
-
#
|
177
|
-
def self.choise_newest_gengou_date(first_line:, second_line:)
|
178
|
-
condition = lambda do |first_date, second_date|
|
179
|
-
first_date > second_date ? first_date : second_date
|
180
|
-
end
|
181
|
-
choise_date(condition: condition, second_line: second_line,
|
182
|
-
first_date: first_line.end_date.clone, second_date: second_line.end_date.clone)
|
183
|
-
end
|
184
|
-
|
185
|
-
# :reek:LongParameterList {max_params: 4}
|
186
|
-
|
187
|
-
#
|
188
|
-
# 条件を元に日付を求める
|
189
|
-
#
|
190
|
-
# @param [Proc] condition 比較条件
|
191
|
-
# @param [Japan::Gengou] second_line 元号(2行目)
|
192
|
-
# @param [Western::Calendar] first_date 比較対象(1行目)
|
193
|
-
# @param [Western::Calendar] second_date 比較対象(2行目)
|
194
|
-
#
|
195
|
-
# @return [Western::Calendar] 比較結果
|
196
|
-
#
|
197
|
-
def self.choise_date(condition:, second_line:, first_date:, second_date:)
|
198
|
-
# first_lineは常に存在する
|
199
|
-
return first_date if second_line.invalid?
|
200
|
-
|
201
|
-
condition.call(first_date, second_date)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|