zakuro 0.6.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3 -0
  3. data/README.md +58 -16
  4. data/VERSION +1 -1
  5. data/doc/dropped_date.md +93 -0
  6. data/doc/error.md +45 -0
  7. data/doc/operation/transfer.rb +8 -8
  8. data/lib/zakuro/calculation/base/day.rb +52 -0
  9. data/lib/zakuro/calculation/base/gengou.rb +50 -4
  10. data/lib/zakuro/calculation/base/linear_gengou.rb +6 -6
  11. data/lib/zakuro/calculation/base/operated_year.rb +3 -3
  12. data/lib/zakuro/calculation/base/year.rb +4 -4
  13. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
  14. data/lib/zakuro/calculation/era/gengou/abstract_scroll.rb +209 -0
  15. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +30 -0
  16. data/lib/zakuro/calculation/era/gengou/internal/connector.rb +107 -0
  17. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +214 -0
  18. data/lib/zakuro/calculation/era/gengou/internal/publisher.rb +104 -0
  19. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +230 -0
  20. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +193 -0
  21. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +48 -0
  22. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +30 -0
  23. data/lib/zakuro/calculation/era/gengou/internal/reserve/empty_link.rb +158 -0
  24. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +125 -0
  25. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +75 -0
  26. data/lib/zakuro/calculation/{gengou → era/gengou}/internal/reserve.rb +6 -7
  27. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +30 -0
  28. data/lib/zakuro/calculation/{version → era/version}/internal/crawler.rb +7 -7
  29. data/lib/zakuro/calculation/{version → era/version}/internal/range.rb +4 -4
  30. data/lib/zakuro/calculation/{version → era/version}/version.rb +3 -3
  31. data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
  32. data/lib/zakuro/calculation/monthly/month.rb +44 -5
  33. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -2
  34. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  35. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  36. data/lib/zakuro/calculation/range/{full_range.rb → abstract_full_range.rb} +29 -27
  37. data/lib/zakuro/calculation/range/{operated_range.rb → abstract_operation_range.rb} +11 -14
  38. data/lib/zakuro/calculation/range/dated_full_range.rb +32 -0
  39. data/lib/zakuro/calculation/range/dated_operation_range.rb +33 -0
  40. data/lib/zakuro/calculation/range/medieval_annual_range.rb +2 -2
  41. data/lib/zakuro/calculation/range/named_full_range.rb +38 -0
  42. data/lib/zakuro/calculation/range/named_operation_range.rb +36 -0
  43. data/lib/zakuro/calculation/range/operated_solar_terms.rb +9 -11
  44. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
  45. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
  46. data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
  47. data/lib/zakuro/calculation/summary/internal/month.rb +92 -0
  48. data/lib/zakuro/calculation/summary/{single.rb → internal/operation.rb} +6 -40
  49. data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
  50. data/lib/zakuro/calculation/summary/japan/range.rb +158 -0
  51. data/lib/zakuro/calculation/summary/japan/single.rb +118 -0
  52. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +96 -0
  53. data/lib/zakuro/calculation/summary/western/range.rb +124 -0
  54. data/lib/zakuro/calculation/summary/western/single.rb +113 -0
  55. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +174 -0
  56. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +98 -0
  57. data/lib/zakuro/calculation/type/optional.rb +46 -0
  58. data/lib/zakuro/condition.rb +75 -22
  59. data/lib/zakuro/context/context.rb +44 -0
  60. data/lib/zakuro/context/option.rb +117 -0
  61. data/lib/zakuro/context/version_class_resolver.rb +110 -0
  62. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +125 -0
  63. data/lib/zakuro/era/japan/gengou/alignment/division.rb +168 -0
  64. data/lib/zakuro/era/japan/gengou/alignment/line.rb +175 -0
  65. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +187 -0
  66. data/lib/zakuro/era/japan/gengou/alignment.rb +55 -0
  67. data/lib/zakuro/era/japan/gengou/resource/parser.rb +245 -0
  68. data/lib/zakuro/era/japan/gengou/resource/type.rb +299 -0
  69. data/lib/zakuro/era/japan/gengou/resource/validator.rb +347 -0
  70. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-001-until-south.yaml +2 -2
  71. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-002-from-north.yaml +2 -2
  72. data/lib/zakuro/era/japan/gengou/{yaml → resource/yaml}/set-003-modern.yaml +2 -2
  73. data/lib/zakuro/era/japan/gengou/resource.rb +33 -0
  74. data/lib/zakuro/era/japan/gengou.rb +25 -79
  75. data/lib/zakuro/era/japan/version.rb +18 -18
  76. data/lib/zakuro/era/western/calendar.rb +13 -9
  77. data/lib/zakuro/exception/case/pattern.rb +71 -0
  78. data/lib/zakuro/exception/case/preset.rb +51 -0
  79. data/lib/zakuro/exception/case/template.rb +48 -0
  80. data/lib/zakuro/exception/cause.rb +28 -0
  81. data/lib/zakuro/exception/exception.rb +37 -0
  82. data/lib/zakuro/exception/zakuro_error.rb +46 -0
  83. data/lib/zakuro/gateway/locale/date.rb +127 -0
  84. data/lib/zakuro/gateway/locale/range.rb +67 -0
  85. data/lib/zakuro/gateway/range.rb +99 -0
  86. data/lib/zakuro/gateway/single.rb +70 -0
  87. data/lib/zakuro/merchant.rb +84 -12
  88. data/lib/zakuro/operation/month/parser.rb +11 -9
  89. data/lib/zakuro/operation/month/type.rb +31 -31
  90. data/lib/zakuro/operation/month/validator.rb +50 -50
  91. data/lib/zakuro/operation/yaml/month.yaml +3736 -3736
  92. data/lib/zakuro/output/logger.rb +17 -3
  93. data/lib/zakuro/output/response.rb +24 -57
  94. data/lib/zakuro/result/data/day.rb +43 -0
  95. data/lib/zakuro/result/data/gengou.rb +35 -0
  96. data/lib/zakuro/result/data/month.rb +63 -0
  97. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  98. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  99. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  100. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  101. data/lib/zakuro/result/data/single_day.rb +56 -0
  102. data/lib/zakuro/result/data/solar_term.rb +35 -0
  103. data/lib/zakuro/result/data/year.rb +45 -0
  104. data/lib/zakuro/result/operation/bundle.rb +44 -0
  105. data/lib/zakuro/result/operation/month/annotation.rb +40 -0
  106. data/lib/zakuro/result/operation/month/bundle.rb +36 -0
  107. data/lib/zakuro/result/operation/month/history.rb +54 -0
  108. data/lib/zakuro/result/result.rb +21 -2
  109. data/lib/zakuro/tools/stringifier.rb +26 -3
  110. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  111. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  112. data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
  113. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
  114. data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
  115. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  116. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  117. data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
  118. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  119. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  120. data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
  121. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
  122. data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
  123. data/lib/zakuro/version/senmyou/README.md +11 -7
  124. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  125. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  126. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  127. data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
  128. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
  129. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
  130. metadata +85 -24
  131. data/lib/zakuro/calculation/gengou/internal/counter.rb +0 -129
  132. data/lib/zakuro/calculation/gengou/internal/reserve/interval.rb +0 -183
  133. data/lib/zakuro/calculation/gengou/internal/reserve/list.rb +0 -382
  134. data/lib/zakuro/calculation/gengou/scroll.rb +0 -262
  135. data/lib/zakuro/calculation/specifier/single_day.rb +0 -87
  136. data/lib/zakuro/era/japan/gengou/parser.rb +0 -237
  137. data/lib/zakuro/era/japan/gengou/type.rb +0 -285
  138. data/lib/zakuro/era/japan/gengou/validator.rb +0 -341
  139. data/lib/zakuro/result/data.rb +0 -187
  140. data/lib/zakuro/result/operation.rb +0 -114
  141. data/lib/zakuro/version/context.rb +0 -44
  142. data/lib/zakuro/version/version_class_resolver.rb +0 -74
@@ -0,0 +1,125 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract_list'
4
+
5
+ # :nodoc:
6
+ module Zakuro
7
+ # :nodoc:
8
+ module Calculation
9
+ # :nodoc:
10
+ module Gengou
11
+ # :nodoc:
12
+ module Reserve
13
+ # NamedList
14
+ #
15
+ # 予約元号一覧(元号名)
16
+ #
17
+ class NamedList < AbstractList
18
+ # @return [String] 不正元号名
19
+ INVALID_NAME = Japan::Calendar::EMPTY
20
+
21
+ #
22
+ # 初期化
23
+ #
24
+ # @param [True, False] first true:1行目元号, false:2行目元号
25
+ # @param [String] start_name 開始元号名
26
+ # @param [String] last_name 終了元号名
27
+ #
28
+ def initialize(first: true, start_name: INVALID_NAME, last_name: INVALID_NAME)
29
+ @index = parse_index(first: first)
30
+ @start_date = Western::Calendar.new
31
+ @last_date = Western::Calendar.new
32
+
33
+ locate(start_name: start_name, last_name: last_name)
34
+ super(index: @index, start_date: @start_date, last_date: @last_date)
35
+ end
36
+
37
+ private
38
+
39
+ #
40
+ # 開始日・終了日を配置する
41
+ #
42
+ # @param [String] start_name 開始元号名
43
+ # @param [String] last_name 終了元号名
44
+ #
45
+ def locate(start_name:, last_name:)
46
+ start = start_name
47
+ last = last_name
48
+ last = start if last == INVALID_NAME
49
+
50
+ return if start == INVALID_NAME
51
+
52
+ [start, last].each do |name|
53
+ gengou_list = line_by_name(name: name)
54
+
55
+ next if gengou_list.size.zero?
56
+
57
+ choise_start_date(
58
+ date: gengou_list[0].start_date.clone
59
+ )
60
+ choise_last_date(
61
+ date: gengou_list[-1].last_date.clone
62
+ )
63
+ end
64
+ end
65
+
66
+ #
67
+ # 最古の開始日を選択する
68
+ #
69
+ # @param [Western::Calendar] date 西暦日
70
+ #
71
+ def choise_start_date(date:)
72
+ return if date.invalid?
73
+
74
+ if @start_date.invalid?
75
+ @start_date = date
76
+ return
77
+ end
78
+
79
+ return if date > @start_date
80
+
81
+ @start_date = date
82
+ end
83
+
84
+ #
85
+ # 最新の終了日を選択する
86
+ #
87
+ # @param [Western::Calendar] date 西暦日
88
+ #
89
+ def choise_last_date(date:)
90
+ return if date.invalid?
91
+
92
+ if @last_date.invalid?
93
+ @last_date = date
94
+ return
95
+ end
96
+
97
+ return if date < @last_date
98
+
99
+ @last_date = date
100
+ end
101
+
102
+ #
103
+ # 元号を取得する(元号名)
104
+ #
105
+ # @param [String] name 元号名
106
+ #
107
+ # @return [Array<Japan::Alignment::LinearGengou>] 元号
108
+ #
109
+ def line_by_name(name:)
110
+ Japan::Gengou.line_by_name(line: @index, name: name)
111
+ end
112
+
113
+ #
114
+ # 予約元号一覧を更新する
115
+ #
116
+ # すでに解決済みの開始日・終了日をそのまま使用する(前後の元号を引き当てない)
117
+ #
118
+ def update
119
+ @list |= line(start_date: start_date, last_date: last_date)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract_range'
4
+ require_relative './named_list'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Gengou
12
+ # :nodoc:
13
+ module Reserve
14
+ #
15
+ # NamedRange 予約済み計算範囲(元号名)
16
+ #
17
+ class NamedRange < AbstractRange
18
+ # @return [String] 不正元号名
19
+ INVALID_NAME = Japan::Calendar::EMPTY
20
+
21
+ #
22
+ # 初期化
23
+ #
24
+ # @param [String] start_name 開始元号名
25
+ # @param [String] last_name 終了元号名
26
+ #
27
+ def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME)
28
+ @first_list = NamedList.new(first: true, start_name: start_name, last_name: last_name)
29
+ @second_list = NamedList.new(first: false, start_name: start_name, last_name: last_name)
30
+
31
+ start_date = western_start_date
32
+ last_date = western_last_date
33
+
34
+ super(start_date: start_date, last_date: last_date)
35
+ end
36
+
37
+ #
38
+ # 最新の元号から西暦終了日を取得する
39
+ #
40
+ # @return [Western::Calendar] 西暦終了日
41
+ #
42
+ def western_last_date
43
+ list = newest_list
44
+
45
+ return Western::Calendar.new if list.invalid?
46
+
47
+ list.western_last_date
48
+ end
49
+
50
+ #
51
+ # 最新の元号を取得する
52
+ #
53
+ # @return [List] 最新の元号
54
+ #
55
+ def newest_list
56
+ return @first_list if @first_list.invalid?
57
+
58
+ return @first_list if @second_list.invalid?
59
+
60
+ first_western_date = @first_list.western_last_date
61
+ second_western_date = @second_list.western_last_date
62
+
63
+ return @first_list if first_western_date.invalid?
64
+
65
+ return @first_list if second_western_date.invalid?
66
+
67
+ return @first_list if first_western_date > second_western_date
68
+
69
+ @second_list
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../era/western/calendar'
4
- require_relative './reserve/interval'
5
- require_relative './reserve/list'
3
+ require_relative '../../../../era/western/calendar'
4
+ require_relative './reserve/dated_range'
6
5
 
7
6
  # :nodoc:
8
7
  module Zakuro
@@ -29,12 +28,12 @@ module Zakuro
29
28
  # * 終了日が最後の元号の改元前日30日以内の場合、さらに次の元号まで対象にする
30
29
  #
31
30
  # @param [Western::Calendar] start_date 開始日
32
- # @param [Western::Calendar] end_date 終了日
31
+ # @param [Western::Calendar] last_date 終了日
33
32
  #
34
- # @return [Interval] 予約済み計算範囲
33
+ # @return [Range] 予約済み計算範囲
35
34
  #
36
- def self.get(start_date: Western::Calendar.new, end_date: Western::Calendar.new)
37
- Interval.new(start_date: start_date, end_date: end_date)
35
+ def self.get(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
36
+ DatedRange.new(start_date: start_date, last_date: last_date)
38
37
  end
39
38
  end
40
39
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './abstract_scroll'
4
+ require_relative './internal/reserve/named_range'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Gengou
12
+ # NamedScroll
13
+ #
14
+ # 元号スクロール
15
+ #
16
+ class NamedScroll < AbstractScroll
17
+ #
18
+ # 初期化
19
+ #
20
+ # @param [String] start_name 開始元号名
21
+ # @param [String] last_name 終了元号名
22
+ #
23
+ def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME)
24
+ range = Reserve::NamedRange.new(start_name: start_name, last_name: last_name)
25
+ super(range: range)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../era/japan/version'
3
+ require_relative '../../../../era/japan/version'
4
4
  require_relative './range'
5
5
 
6
6
  # :nodoc:
@@ -17,12 +17,12 @@ module Zakuro
17
17
  # 暦の範囲を取得する
18
18
  #
19
19
  # @param [Integer] start_year 開始西暦年
20
- # @param [Integer] end_year 終了西暦年
20
+ # @param [Integer] last_year 終了西暦年
21
21
  #
22
22
  # @return [Array<Range>] 暦の範囲
23
23
  #
24
- def self.get(start_year:, end_year:)
25
- ranges = Japan::Version.ranges_with_year(start_year: start_year, end_year: end_year)
24
+ def self.get(start_year:, last_year:)
25
+ ranges = Japan::Version.ranges_with_year(start_year: start_year, last_year: last_year)
26
26
 
27
27
  result = []
28
28
 
@@ -32,13 +32,13 @@ module Zakuro
32
32
  range_start_year = range.start_year
33
33
  range_start_year = start_year if start_year > range.start_year
34
34
 
35
- range_end_year = range.end_year
36
- range_end_year = end_year if end_year < range.end_year
35
+ range_last_year = range.last_year
36
+ range_last_year = last_year if last_year < range.last_year
37
37
 
38
38
  result.push(
39
39
  Range.new(
40
40
  name: range.name, start_date: range.start_date.clone,
41
- start_year: range_start_year, end_year: range_end_year
41
+ start_year: range_start_year, last_year: range_last_year
42
42
  )
43
43
  )
44
44
  end
@@ -17,7 +17,7 @@ module Zakuro
17
17
  # @return [Integer] 開始西暦年
18
18
  attr_reader :start_year
19
19
  # @return [Integer] 終了西暦年
20
- attr_reader :end_year
20
+ attr_reader :last_year
21
21
 
22
22
  #
23
23
  # 初期化
@@ -25,13 +25,13 @@ module Zakuro
25
25
  # @param [String] name 暦名
26
26
  # @param [Western::Calendar] start_date 暦の開始日
27
27
  # @param [Integer] start_year 開始西暦年
28
- # @param [Integer] end_year 終了西暦年
28
+ # @param [Integer] last_year 終了西暦年
29
29
  #
30
- def initialize(name:, start_date:, start_year:, end_year:)
30
+ def initialize(name:, start_date:, start_year:, last_year:)
31
31
  @name = name
32
32
  @start_date = start_date
33
33
  @start_year = start_year
34
- @end_year = end_year
34
+ @last_year = last_year
35
35
  end
36
36
  end
37
37
  end
@@ -12,12 +12,12 @@ module Zakuro
12
12
  # 暦の範囲を取得する
13
13
  #
14
14
  # @param [Integer] start_year 開始西暦年
15
- # @param [Integer] end_year 終了西暦年
15
+ # @param [Integer] last_year 終了西暦年
16
16
  #
17
17
  # @return [Array<Range>] 暦の範囲
18
18
  #
19
- def self.get(start_year:, end_year:)
20
- Crawler.get(start_year: start_year, end_year: end_year)
19
+ def self.get(start_year:, last_year:)
20
+ Crawler.get(start_year: start_year, last_year: last_year)
21
21
  end
22
22
  end
23
23
  end
@@ -25,7 +25,7 @@ module Zakuro
25
25
  #
26
26
  # 初期化
27
27
  #
28
- # @param [Context] context 暦コンテキスト
28
+ # @param [Context::Context] context 暦コンテキスト
29
29
  # @param [MonthLabel] month_label 月表示名
30
30
  # @param [Array<SolarTerm>] solar_terms 二十四節気
31
31
  # @param [FirstDay] first_day 月初日(朔日)
@@ -14,7 +14,7 @@ module Zakuro
14
14
  # Month 月情報
15
15
  #
16
16
  class Month
17
- # @return [Context] 暦コンテキスト
17
+ # @return [Context::Context] 暦コンテキスト
18
18
  attr_reader :context
19
19
  # @return [MonthLabel] 月表示名
20
20
  attr_reader :month_label
@@ -28,13 +28,13 @@ module Zakuro
28
28
  #
29
29
  # 初期化
30
30
  #
31
- # @param [Context] context 暦コンテキスト
31
+ # @param [Context::Context] context 暦コンテキスト
32
32
  # @param [MonthLabel] month_label 月表示名
33
33
  # @param [FirstDay] first_day 月初日(朔日)
34
34
  # @param [Array<SolarTerm>] solar_terms 二十四節気
35
35
  # @param [Base::Gengou] gengou 元号
36
36
  #
37
- def initialize(context: Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
37
+ def initialize(context: Context::Context.new, month_label: MonthLabel.new, first_day: FirstDay.new,
38
38
  solar_terms: [], gengou: Base::Gengou.new)
39
39
  @context = context
40
40
  @month_label = month_label
@@ -202,7 +202,7 @@ module Zakuro
202
202
  #
203
203
  # @return [Western::Calendar] 月の終了日
204
204
  #
205
- def end_date
205
+ def last_date
206
206
  return Western::Calendar.new if western_date.invalid?
207
207
 
208
208
  western_date.clone + days - 1
@@ -224,7 +224,46 @@ module Zakuro
224
224
 
225
225
  return false if date < start_date
226
226
 
227
- return false if date > end_date
227
+ return false if date > last_date
228
+
229
+ true
230
+ end
231
+
232
+ #
233
+ # 範囲内か
234
+ #
235
+ # @param [Japan::Calendar] date 日付
236
+ #
237
+ # @return [True] 範囲内
238
+ # @return [False] 範囲外
239
+ #
240
+ def include_by_japan_date?(date:)
241
+ return false if invalid?
242
+
243
+ linear_gengou = @gengou.match_by_name(name: date.gengou)
244
+ return false if linear_gengou.invalid?
245
+
246
+ return false unless linear_gengou.name == date.gengou
247
+
248
+ return false unless linear_gengou.year == date.year
249
+
250
+ same_by_japan_date?(date: date)
251
+ end
252
+
253
+ private
254
+
255
+ #
256
+ # 同一の月情報かを検証する
257
+ #
258
+ # @param [Japan::Calendar] date 日付
259
+ #
260
+ # @return [True] 同一の月
261
+ # @return [False] 異なる月
262
+ #
263
+ def same_by_japan_date?(date: Japan::Calendar.new)
264
+ return false unless number == date.month
265
+
266
+ return false unless leaped? == date.leaped
228
267
 
229
268
  true
230
269
  end
@@ -26,7 +26,7 @@ module Zakuro
26
26
  #
27
27
  # 初期化
28
28
  #
29
- # @param [Context] context 暦コンテキスト
29
+ # @param [Context::Context] context 暦コンテキスト
30
30
  # @param [OperatedSolarTerms] operated_solar_terms 運用時二十四節気
31
31
  # @param [MonthLabel] month_label 月表示名
32
32
  # @param [FirstDay] first_day 月初日(朔日)
@@ -80,7 +80,7 @@ module Zakuro
80
80
  default = month_label.send(method_name)
81
81
  return default if diff.invalid?
82
82
 
83
- diff.actual
83
+ diff.dest
84
84
  end
85
85
 
86
86
  #
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Option
9
+ # :nodoc:
10
+ module DroppedDate
11
+ #
12
+ # AbstractParameter 没日引数
13
+ #
14
+ class AbstractParameter
15
+ # @return [True] 有効
16
+ # @return [False] 無効
17
+ attr_reader :valid
18
+ # @return [Integer] 年
19
+ attr_reader :year
20
+ # @return [Cycle::AbstractRemainder] 「有没之気」判定
21
+ attr_reader :limit
22
+ # @return [Class] 没余クラス
23
+ attr_reader :remainder_class
24
+
25
+ #
26
+ # 初期化
27
+ #
28
+ # @param [True, False] valid 有効/無効
29
+ # @param [Integer] year 年
30
+ # @param [Cycle::AbstractRemainder] limit 「有没之気」判定
31
+ # @param [Class] remainder_class 没余クラス
32
+ #
33
+ def initialize(valid: false, year: 0, limit: Cycle::AbstractRemainder.new,
34
+ remainder_class: Object)
35
+ @valid = valid
36
+ @year = year
37
+ @limit = limit
38
+ @remainder_class = remainder_class
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Zakuro
5
+ # :nodoc:
6
+ module Calculation
7
+ # :nodoc:
8
+ module Option
9
+ # :nodoc:
10
+ module DroppedDate
11
+ #
12
+ # Location 没日位置
13
+ #
14
+ class Location
15
+ # @return [Integer] 理想上の年日数
16
+ IDEAL_YEAR = 360
17
+
18
+ # @return [Context::Context] 暦コンテキスト
19
+ attr_reader :context
20
+ # @return [True] 有効
21
+ # @return [False] 無効
22
+ attr_reader :valid
23
+ # @return [Cycle::AbstractRemainder] 「有没之気」判定
24
+ attr_reader :limit
25
+ # @return [Integer] 年
26
+ attr_reader :year
27
+ # @return [Array<Cycle::AbstractSolarTerm>] 二十四節気
28
+ attr_reader :solar_terms
29
+ # @return [Class] 没余クラス
30
+ attr_reader :remainder_class
31
+
32
+ #
33
+ # 初期化
34
+ #
35
+ # @param [Context::Context] context 暦コンテキスト
36
+ # @param [Array<Cycle::AbstractSolarTerm>] solar_terms 二十四節気
37
+ #
38
+ def initialize(context:, solar_terms: [])
39
+ parameter = context.resolver.dropped_date_parameter.new
40
+ @context = context
41
+ @valid = parameter.valid
42
+ @limit = parameter.limit
43
+ @year = parameter.year
44
+ @remainder_class = parameter.remainder_class
45
+ @solar_terms = solar_terms
46
+ end
47
+
48
+ #
49
+ # 不正か
50
+ #
51
+ # @return [True] 不正
52
+ # @return [False] 不正なし
53
+ #
54
+ def invalid?
55
+ !@valid
56
+ end
57
+
58
+ #
59
+ # 没日が存在するか?
60
+ #
61
+ # @return [True] 存在あり
62
+ # @return [False] 存在なし
63
+ #
64
+ def exist?
65
+ !solar_term_remainder.invalid?
66
+ end
67
+
68
+ #
69
+ # 「没余」を返す
70
+ #
71
+ # @return [Cycle::AbstractRemainder] 没余
72
+ #
73
+ def get
74
+ # 1. 二十四節気の大余小余を取り出す
75
+ remainder = solar_term_remainder
76
+ # 2. 小余360、秒45(360/8)で乗算する
77
+ total = multiple_ideal_year(remainder: remainder)
78
+ # 3. 上記2と章歳(3068055)の差を求める
79
+ diff = (year - total).abs
80
+ # 4. 上記3を通余で徐算する
81
+ result = remainder_class.new(total: diff)
82
+ # 5. 上記4の商と上記1の大余が没日大余、余りが小余(没余)
83
+ day = remainder_class.new(day: remainder.day, minute: 0, second: 0)
84
+
85
+ day.add(result)
86
+ end
87
+
88
+ #
89
+ # 該当の二十四節気を取得する
90
+ #
91
+ # @return [Cycle::AbstractSolarTerm] 二十四節気
92
+ #
93
+ def solar_term
94
+ solar_terms.each do |solar_term|
95
+ remainder = solar_term.remainder.clone
96
+ minute_later = remainder.class.new(
97
+ day: 0, minute: remainder.minute, second: remainder.second
98
+ )
99
+
100
+ return solar_term if minute_later >= limit
101
+ end
102
+
103
+ context.resolver.solar_term.new
104
+ end
105
+
106
+ private
107
+
108
+ #
109
+ # 二十四節気の大余小余を取得する
110
+ #
111
+ # @return [Type::Optional<Cycle::AbstractRemainder>] 大余小余
112
+ #
113
+ def solar_term_remainder
114
+ solar_term.remainder
115
+ end
116
+
117
+ #
118
+ # 理想上の年数を乗算する
119
+ #
120
+ # 宣明暦:小余360、秒45(360/8)で積算する
121
+ #
122
+ # @return [Cycle::AbstractRemainder] 大余小余
123
+ #
124
+ # @return [Integer] 乗算結果
125
+ #
126
+ def multiple_ideal_year(remainder:)
127
+ minute = remainder.minute * IDEAL_YEAR
128
+ second = remainder.second * (IDEAL_YEAR / remainder.base_minute)
129
+ minute + second
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end