zakuro 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/doc/operation/csv/month.csv +3 -4
  4. data/doc/operation/operation.xlsx +0 -0
  5. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +6 -0
  6. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +4 -2
  7. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +9 -3
  8. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +18 -9
  9. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +6 -2
  10. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +5 -2
  11. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +11 -3
  12. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +10 -4
  13. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +5 -2
  14. data/lib/zakuro/calculation/monthly/month.rb +61 -2
  15. data/lib/zakuro/calculation/monthly/operated_month.rb +2 -0
  16. data/lib/zakuro/calculation/option/dropped_date/location.rb +8 -1
  17. data/lib/zakuro/calculation/range/dated_full_range.rb +6 -3
  18. data/lib/zakuro/calculation/range/dated_operation_range.rb +2 -1
  19. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  20. data/lib/zakuro/calculation/summary/western/range.rb +8 -1
  21. data/lib/zakuro/calculation/summary/western/single.rb +12 -5
  22. data/lib/zakuro/era/japan/gengou/alignment.rb +32 -5
  23. data/lib/zakuro/era/japan/gengou.rb +8 -6
  24. data/lib/zakuro/operation/yaml/month.yaml +3 -35
  25. data/lib/zakuro/tools/gengou_range_comparer.rb +82 -0
  26. data/lib/zakuro/tools/remainder_comparer.rb +3 -0
  27. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79211341aba598e1c98e7b3df3ffe0ce6f3016027fe0b2459bd2c68a18703e89
4
- data.tar.gz: 17d2537acf7d477b6292d1b14e02dbd355499d1c12cf2491e419124108175d9b
3
+ metadata.gz: fffb0d3903b07bc1c5b884bb73bef8a11ff65f5cfdb4c7d2a58df1c2777da633
4
+ data.tar.gz: c4a5ede6b55e073ac1b82b11c4b19a56a7ae7a518391bcde2c86a94461c61928
5
5
  SHA512:
6
- metadata.gz: '0196f4cd32a1b8b2d9d517ead1abf747f3be612d59514f68ef75670169c17da9e5222b8d1b63504520653aca6646a840a46b052246d192d27e22146372b52e14'
7
- data.tar.gz: 8a9f4e91afd4d07868a470e8e372bd0534ddc9f72e55551febc3aba3970b589c896cf0ca8555e1bb71f1606d78078eabd5f70f5125b1680fd1e0b1eaeece9b54
6
+ metadata.gz: d2084bedda00006b2724616daaa6088e9034dd6e878d0ef145801a5da1ffd6e22af953ea812b24efcc996593a3ec0e7c49c368b8105f2a9b5d44efe9a91ff573
7
+ data.tar.gz: b960ab267ecb7667817c780b86b01ec4aac15a0d9f6ebde3a64c01cfd94d0343a9a37550ad9f98ea55a566102bcd426971e0d7ae1864a0a4af807a9414d4a8fd
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
@@ -351,7 +351,7 @@
351
351
  ,211-1-1,-,-,211,1,1037-4-18,長暦 1年 4 小 甲辰 39-5736,"計算は39癸卯であるが, 行親記により甲辰, 4月甲辰朔のユリウス暦日は4月19日。",-,true,朔日相違,-,-,大,小,-,-,-,-,-,-,癸卯,甲辰,1037-4-18,1037-4-19,39,40,1,1,-,-,-
352
352
  ,215-1-a,-,215-1-2,215,-,1050-10-19,永承 5年 10 小 乙卯 51-7981,-,変更なし,false,次月大小,-,-,小,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
353
353
  ,215-1-0,215-1-2,-,215,-,1050-11-17,永承 5年 閏10 小 甲申 20-5089,-,-,true,朔旦冬至,11月,閏10月,大,小,0,-,-,-,1050-12-17,-,-,-,-,-,-,-,-,-,-,-,-
354
- ,215-1-1,215-1-2,-,215,1,1050-12-17,永承 5年 11 大 癸丑 50-1948,-,-,true,朔旦冬至,閏11月,11月,大,大,-,0,-,-,-,1050-12-17,甲寅,癸丑,1050-12-17,1050-12-16,50,49,-1,-1,-,-,-
354
+ ,215-1-1,215-1-2,-,215,1,1050-12-17,永承 5年 11 大 癸丑 50-1948,-,-,true,朔旦冬至,閏11月,11月,大,大,-,0,-,-,-,1050-11-17,甲寅,癸丑,1050-12-17,1050-12-16,50,49,-1,-1,-,-,-
355
355
  ,215-1-2,-,-,215,1,1051-1-16,永承 5年 12 大 癸未 20-6665,"朔旦冬至にするために, 計算では閏11月であるが, 閏10月に変更された。そのためには中気のない月を閏月にするという規則に合わせるため, 11月朔を50甲寅から癸丑にする必要がある。それにつれて12月は甲申を癸未にしないと11月が31日になってしまう。11月癸丑朔のユリウス暦日は12月16日。12月癸丑朔は1月15日となる。(管見記84, 江次第, 扶桑略記などによる)。",-,true,朔旦冬至,-,-,小,大,-,-,-,-,-,-,甲申,癸未,1051-1-16,1051-1-15,20,19,-1,-1,-,-,-
356
356
  ,220-1-a,-,220-1-1,220,-,1063-9-25,康平 6年 9 大 己亥 35-2001,-,-,true,次月大小,-,-,小,大,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
357
357
  ,220-1-1,-,-,220,1,1063-10-24,康平 6年 10 小 己巳 4-6004,"計算は4戊辰, 扶桑略記により己巳とする。10月己巳朔のユリウス暦日は10月25日。",-,true,朔日相違,-,-,大,小,-,-,-,-,-,-,戊辰,己巳,1063-10-24,1063-10-25,4,5,1,1,-,-,-
@@ -431,9 +431,8 @@
431
431
  ,311-3-1,-,-,311,3,1338-9-15,延元 3年 8 大 壬辰 29-103,"計算では29癸巳, 実夏公記ほか(大日本史料第6編の5)により壬辰, 8月壬辰朔のユリウス暦日は9月14日となる。これは章首のあとの閏8月を避けたものである。(大治4, 西暦1129年の注参照)",-,true,閏8月回避,閏8月,8月,小,大,-,18,-,-,-,1338-8-16,癸巳,壬辰,1338-9-15,1338-9-14,29,28,-1,-1,-,-,-
432
432
  ,313-1-a,-,313-1-1,313,-,1343-12-18,興国 4年 12 小 癸巳 29-814,-,-,true,次月大小,-,-,大,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
433
433
  ,313-1-1,-,-,313,1,1344-1-17,興国 5年 1 大 壬戌 59-6335,"計算は59癸亥, 園太暦・師守記など(大日本史料第6編の8)により壬戌, 正月壬戌朔のユリウス暦日は1月16日。小余が進朔限に近く, 進朔すべきをしなかった司暦の誤りか。",-,true,進朔なし,-,-,小,大,-,-,-,-,-,-,癸亥,壬戌,1344-1-17,1344-1-16,59,58,-1,-1,-,-,-
434
- ,318-1-a,-,318-1-1,318,-,1357-7-18,正平 12年 7 小 甲戌 10-1300,-,-,true,次月大小,-,-,大,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
435
- ,318-1-0,318-1-1,-,318,-,1357-8-16,正平 12年 閏7 癸卯 39-5146,-,-,true,閏8月回避,8月,閏7月,小,小,18,-,-,-,1357-9-15,-,-,-,-,-,-,-,-,-,-,-,-
436
- ,318-1-1,-,-,318,1,1357-9-15,正平 12年 8 大 壬申 9-357,"計算では9癸酉であるが, 章首のあとの閏8月を避けるため壬申に変え閏7月にしたもの。(大日本史料第6編の21)8月壬申朔のユリウス暦日は9月14日となる。",-,true,閏8月回避,閏8月,8月,大,大,-,18,-,-,-,1357-8-16,癸酉,壬申,1357-9-15,1357-9-14,9,8,-1,-1,-,-,-
434
+ ,318-1-0,318-1-1,-,318,-,1357-8-16,正平 12年 7 小 癸卯 39-5146,-,-,true,閏8月回避,8月,閏7月,大,小,18,-,-,-,1357-9-15,-,-,-,-,-,-,-,-,-,-,-,-
435
+ ,318-1-1,-,-,318,1,1357-9-15,正平 12年 8 壬申 9-357,"計算では9癸酉であるが, 章首のあとの閏8月を避けるため壬申に変え閏7月にしたもの。(大日本史料第6編の21)8月壬申朔のユリウス暦日は9月14日となる。",-,true,閏8月回避,閏8月,8月,小,大,-,18,-,-,-,1357-8-16,癸酉,壬申,1357-9-15,1357-9-14,9,8,-1,-1,-,-,-
437
436
  ,323-1-a,-,323-1-1,323,-,1373-10-17,文中 2年 10 小 己巳 5-473,-,変更なし,false,次月大小,-,-,小,小,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,-
438
437
  ,323-1-0,323-0-1,-,323,-,1373-11-15,文中 2年 閏10 小 戊戌 34-4924,-,-,true,朔旦冬至,11月,閏10月,大,小,0,-,-,-,1373-12-15,-,-,-,-,-,-,-,-,-,-,-,-
439
438
  ,323-1-1,323-0-1,-,323,1,1373-12-15,文中 2年 11 大 丁卯 4-1834,"計算では4戊辰, 実施暦は丁卯, 11月丁卯朔のユリウス暦日は12月14日である。",-,true,朔旦冬至,閏11月,11月,大,大,-,0,-,-,-,-,戊辰,丁卯,1373-12-15,1373-12-14,4,3,-1,-1,-,-,-
Binary file
@@ -47,6 +47,12 @@ module Zakuro
47
47
  23 => :taisetsu
48
48
  }.freeze
49
49
 
50
+ # @return [Integer] 開始番号
51
+ FIRST_INDEX = 0
52
+
53
+ # @return [Integer] 終了番号
54
+ LAST_INDEX = 23
55
+
50
56
  #
51
57
  # 初期化
52
58
  #
@@ -20,11 +20,13 @@ module Zakuro
20
20
  # @param [Western::Calendar] start_date 西暦開始日(最大範囲)
21
21
  # @param [Western::Calendar] last_date 西暦終了日(最大範囲)
22
22
  # @param [True, False] operated 運用値設定
23
+ # @param [True, False] restored 運用値から計算値に戻すか
23
24
  #
24
25
  def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
25
- operated: false)
26
+ operated: false, restored: false)
26
27
  range = Reserve::DatedRange.new(
27
- start_date: start_date, last_date: last_date, operated: operated
28
+ start_date: start_date, last_date: last_date, operated: operated,
29
+ restored: restored
28
30
  )
29
31
  super(range: range)
30
32
  end
@@ -34,8 +34,11 @@ module Zakuro
34
34
  # @return [Western::Calendar] 終了日
35
35
  attr_reader :last_date
36
36
  # @return [True] 運用値あり
37
- # @return [True] 運用値なし
37
+ # @return [False] 運用値なし
38
38
  attr_reader :operated
39
+ # @return [True] 運用値から計算値に戻す
40
+ # @return [False] 運用値から計算値に戻さない
41
+ attr_reader :restored
39
42
  # @return [Array<Japan::Alignment::LinearGengou>] 予約元号一覧
40
43
  attr_reader :list
41
44
 
@@ -46,13 +49,15 @@ module Zakuro
46
49
  # @param [Western::Calendar] start_date 開始日
47
50
  # @param [Western::Calendar] last_date 終了日
48
51
  # @param [True, False] operated 運用値設定
52
+ # @param [True, False] restored 運用値から計算値に戻すか
49
53
  #
50
54
  def initialize(index:, start_date: Western::Calendar.new,
51
- last_date: Western::Calendar, operated: false)
55
+ last_date: Western::Calendar, operated: false, restored: false)
52
56
  @index = index
53
57
  @start_date = start_date.clone
54
58
  @last_date = last_date.clone
55
59
  @operated = operated
60
+ @restored = restored
56
61
  @list = []
57
62
 
58
63
  update
@@ -216,7 +221,8 @@ module Zakuro
216
221
  #
217
222
  def line(start_date:, last_date:)
218
223
  Japan::Gengou.line(
219
- line: index, start_date: start_date, last_date: last_date, operated: operated
224
+ line: index, start_date: start_date, last_date: last_date, operated: operated,
225
+ restored: restored
220
226
  )
221
227
  end
222
228
 
@@ -27,19 +27,22 @@ module Zakuro
27
27
  # @param [Western::Calendar] start_date 西暦開始日
28
28
  # @param [Western::Calendar] last_date 西暦終了日
29
29
  # @param [True, False] operated 運用値設定
30
+ # @param [True, False] restored 運用値から計算値に戻すか
30
31
  #
31
32
  def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
32
- operated: false)
33
+ operated: false, restored: false)
33
34
  last_date = start_date.clone if last_date.invalid?
34
35
 
35
36
  @first_list = DatedList.new(
36
- first: true, start_date: start_date, last_date: last_date, operated: operated
37
+ first: true, start_date: start_date, last_date: last_date, operated: operated,
38
+ restored: restored
37
39
  )
38
40
  @second_list = DatedList.new(
39
- first: false, start_date: start_date, last_date: last_date, operated: operated
41
+ first: false, start_date: start_date, last_date: last_date, operated: operated,
42
+ restored: restored
40
43
  )
41
44
 
42
- renew(last_date: last_date)
45
+ renew(last_date: last_date, operated: operated, restored: restored)
43
46
  end
44
47
 
45
48
  #
@@ -47,16 +50,22 @@ module Zakuro
47
50
  # 含まれる最初の元号が別の行にまたがっている場合に開始日を前倒しする
48
51
  #
49
52
  # @param [Western::Calendar] last_date 西暦終了日
53
+ # @param [True, False] operated 運用値設定
54
+ # @param [True, False] restored 運用値から計算値に戻すか
50
55
  #
51
- def renew(last_date: Western::Calendar.new)
56
+ def renew(last_date: Western::Calendar.new, operated: false, restored: false)
52
57
  start_date = native_start_date
53
58
 
54
59
  return if start_date.invalid?
55
60
 
56
- @first_list = DatedList.new(first: true, start_date: start_date,
57
- last_date: last_date)
58
- @second_list = DatedList.new(first: false, start_date: start_date,
59
- last_date: last_date)
61
+ @first_list = DatedList.new(
62
+ first: true, start_date: start_date, last_date: last_date,
63
+ operated: operated, restored: restored
64
+ )
65
+ @second_list = DatedList.new(
66
+ first: false, start_date: start_date, last_date: last_date,
67
+ operated: operated, restored: restored
68
+ )
60
69
  end
61
70
 
62
71
  #
@@ -22,13 +22,17 @@ module Zakuro
22
22
  # @param [Western::Calendar] start_date 開始日
23
23
  # @param [Western::Calendar] last_date 終了日
24
24
  # @param [True, False] operated 運用値設定
25
+ # @param [True, False] restored 運用値から計算値に戻すか
25
26
  #
26
27
  def initialize(first: true, start_date: Western::Calendar.new,
27
- last_date: Western::Calendar, operated: false)
28
+ last_date: Western::Calendar, operated: false, restored: false)
28
29
  @index = parse_index(first: first)
29
30
  @start_date = start_date.clone
30
31
  @last_date = last_date.invalid? ? start_date.clone : last_date.clone
31
- super(index: @index, start_date: start_date, last_date: last_date, operated: operated)
32
+ super(
33
+ index: @index, start_date: start_date, last_date: last_date, operated: operated,
34
+ restored: restored
35
+ )
32
36
  end
33
37
 
34
38
  #
@@ -20,10 +20,13 @@ module Zakuro
20
20
  # @param [Western::Calendar] start_date 西暦開始日
21
21
  # @param [Western::Calendar] last_date 西暦終了日
22
22
  # @param [True, False] operated 運用値設定
23
+ # @param [True, False] restored 運用値から計算値に戻すか
23
24
  #
24
25
  def initialize(start_date: Western::Calendar.new, last_date: Western::Calendar.new,
25
- operated: false)
26
- super(start_date: start_date, last_date: last_date, operated: operated)
26
+ operated: false, restored: false)
27
+ super(
28
+ start_date: start_date, last_date: last_date, operated: operated, restored: restored
29
+ )
27
30
  end
28
31
  end
29
32
  end
@@ -24,16 +24,22 @@ module Zakuro
24
24
  # @param [True, False] first true:1行目元号, false:2行目元号
25
25
  # @param [String] start_name 開始元号名
26
26
  # @param [String] last_name 終了元号名
27
+ # @param [True, False] operated 運用値設定
28
+ # @param [True, False] restored 運用値から計算値に戻すか
27
29
  #
28
30
  def initialize(first: true, start_name: INVALID_NAME, last_name: INVALID_NAME,
29
- operated: false)
31
+ operated: false, restored: false)
30
32
  @index = parse_index(first: first)
31
33
  @start_date = Western::Calendar.new
32
34
  @last_date = Western::Calendar.new
33
35
  @operated = operated
36
+ @restored = restored
34
37
 
35
38
  locate(start_name: start_name, last_name: last_name)
36
- super(index: index, start_date: start_date, last_date: last_date, operated: operated)
39
+ super(
40
+ index: index, start_date: start_date, last_date: last_date, operated: operated,
41
+ restored: restored
42
+ )
37
43
  end
38
44
 
39
45
  private
@@ -109,7 +115,9 @@ module Zakuro
109
115
  # @return [Array<Japan::Alignment::LinearGengou>] 元号
110
116
  #
111
117
  def line_by_name(name:)
112
- Japan::Gengou.line_by_name(line: index, name: name, operated: operated)
118
+ Japan::Gengou.line_by_name(
119
+ line: index, name: name, operated: operated, restored: restored
120
+ )
113
121
  end
114
122
 
115
123
  #
@@ -24,19 +24,25 @@ module Zakuro
24
24
  # @param [String] start_name 開始元号名
25
25
  # @param [String] last_name 終了元号名
26
26
  # @param [True, False] operated 運用値設定
27
+ # @param [True, False] restored 運用値から計算値に戻すか
27
28
  #
28
- def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME, operated: false)
29
+ def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME,
30
+ operated: false, restored: false)
29
31
  @first_list = NamedList.new(
30
- first: true, start_name: start_name, last_name: last_name, operated: operated
32
+ first: true, start_name: start_name, last_name: last_name, operated: operated,
33
+ restored: restored
31
34
  )
32
35
  @second_list = NamedList.new(
33
- first: false, start_name: start_name, last_name: last_name, operated: operated
36
+ first: false, start_name: start_name, last_name: last_name, operated: operated,
37
+ restored: restored
34
38
  )
35
39
 
36
40
  start_date = western_start_date
37
41
  last_date = western_last_date
38
42
 
39
- super(start_date: start_date, last_date: last_date, operated: operated)
43
+ super(
44
+ start_date: start_date, last_date: last_date, operated: operated, restored: restored
45
+ )
40
46
  end
41
47
 
42
48
  #
@@ -20,10 +20,13 @@ module Zakuro
20
20
  # @param [String] start_name 開始元号名
21
21
  # @param [String] last_name 終了元号名
22
22
  # @param [True, False] operated 運用値設定
23
+ # @param [True, False] restored 運用値から計算値に戻すか
23
24
  #
24
- def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME, operated: false)
25
+ def initialize(start_name: INVALID_NAME, last_name: INVALID_NAME,
26
+ operated: false, restored: false)
25
27
  range = Reserve::NamedRange.new(
26
- start_name: start_name, last_name: last_name, operated: operated
28
+ start_name: start_name, last_name: last_name, operated: operated,
29
+ restored: restored
27
30
  )
28
31
  super(range: range)
29
32
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../cycle/abstract_solar_term'
4
+
3
5
  require_relative '../base/gengou'
4
6
  require_relative './first_day'
5
7
  require_relative './meta'
@@ -22,7 +24,7 @@ module Zakuro
22
24
  attr_reader :month_label
23
25
  # @return [FirstDay] 月初日(朔日)
24
26
  attr_reader :first_day
25
- # @return [Array<AbstractSolarTerm>] 二十四節気
27
+ # @return [Array<Cyle::AbstractSolarTerm>] 二十四節気
26
28
  attr_reader :solar_terms
27
29
  # @return [Base::Gengou] 元号
28
30
  attr_reader :gengou
@@ -37,7 +39,7 @@ module Zakuro
37
39
  # @param [Context::Context] context 暦コンテキスト
38
40
  # @param [MonthLabel] month_label 月表示名
39
41
  # @param [FirstDay] first_day 月初日(朔日)
40
- # @param [Array<AbstractSolarTerm>] solar_terms 二十四節気
42
+ # @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
41
43
  # @param [Base::Gengou] gengou 元号
42
44
  # @param [Meta] meta 付加情報
43
45
  #
@@ -261,6 +263,38 @@ module Zakuro
261
263
  same_by_japan_date?(date: date)
262
264
  end
263
265
 
266
+ #
267
+ # 二十四節気を正しい順序にソートする
268
+ #
269
+ def sort_solar_terms
270
+ # TODO: refactor
271
+ sorted = (solar_terms.sort do |termx, termy|
272
+ termx.index <=> termy.index
273
+ end)
274
+
275
+ unless reset_term?(solar_terms: sorted)
276
+ @solar_terms = sorted
277
+ return
278
+ end
279
+
280
+ first = []
281
+ second = []
282
+
283
+ sorted.each do |term|
284
+ if term.index >= (23 - 2)
285
+ second.push(term)
286
+ next
287
+ end
288
+
289
+ first.push(term)
290
+ end
291
+
292
+ # 0以前を先頭にする
293
+ second += first
294
+
295
+ @solar_terms = second
296
+ end
297
+
264
298
  #
265
299
  # 大余に対応する二十四節気
266
300
  #
@@ -322,6 +356,31 @@ module Zakuro
322
356
 
323
357
  true
324
358
  end
359
+
360
+ #
361
+ # 二十四節気の折り返し(23 -> 0)があるか
362
+ #
363
+ # @param [Array<Cyle::AbstractSolarTerm>] solar_terms 二十四節気
364
+ #
365
+ # @return [True] 折り返しあり
366
+ # @return [False] 折り返しなし
367
+ #
368
+ def reset_term?(solar_terms: [])
369
+ first = false
370
+ last = false
371
+
372
+ solar_terms.each do |term|
373
+ index = term.index
374
+ case index
375
+ when Cycle::AbstractSolarTerm::FIRST_INDEX
376
+ first = true
377
+ when Cycle::AbstractSolarTerm::LAST_INDEX
378
+ last = true
379
+ end
380
+ end
381
+
382
+ first && last
383
+ end
325
384
  end
326
385
  end
327
386
  end
@@ -54,6 +54,8 @@ module Zakuro
54
54
  rewrite_month
55
55
  rewrite_solar_terms
56
56
  rewrite_first_day
57
+
58
+ sort_solar_terms
57
59
  end
58
60
 
59
61
  #
@@ -62,7 +62,14 @@ module Zakuro
62
62
  # @return [False] 存在なし
63
63
  #
64
64
  def exist?
65
- !solar_term_remainder.invalid?
65
+ remainder = solar_term_remainder
66
+
67
+ return false if remainder.invalid?
68
+
69
+ minute_later = remainder.class.new(
70
+ day: 0, minute: remainder.minute, second: remainder.second
71
+ )
72
+ minute_later >= limit
66
73
  end
67
74
 
68
75
  #
@@ -19,11 +19,14 @@ module Zakuro
19
19
  # @param [Context::Context] context 暦コンテキスト
20
20
  # @param [Western::Calendar] start_date 開始日
21
21
  # @param [Western::Calendar] last_date 終了日
22
+ # @param [True, False] operated 運用値設定
23
+ # @param [True, False] restored 運用値から計算値に戻すか
22
24
  #
23
- def initialize(context:,
24
- start_date: Western::Calendar.new, last_date: Western::Calendar.new)
25
+ def initialize(context:, start_date: Western::Calendar.new,
26
+ last_date: Western::Calendar.new, operated: false, restored: false)
25
27
  scroll = Gengou::DatedScroll.new(
26
- start_date: start_date, last_date: last_date, operated: false
28
+ start_date: start_date, last_date: last_date, operated: operated,
29
+ restored: restored
27
30
  )
28
31
 
29
32
  super(context: context, scroll: scroll, start_date: start_date, last_date: last_date)
@@ -25,7 +25,8 @@ module Zakuro
25
25
  def initialize(context:, start_date: Western::Calendar.new,
26
26
  last_date: Western::Calendar.new, years: [])
27
27
  scroll = Gengou::DatedScroll.new(
28
- start_date: start_date, last_date: last_date, operated: true
28
+ start_date: start_date, last_date: last_date, operated: true,
29
+ restored: false
29
30
  )
30
31
  super(context: context, scroll: scroll, years: years)
31
32
  end
@@ -25,7 +25,7 @@ module Zakuro
25
25
  #
26
26
  def initialize(context:, start_name: INVALID_NAME, last_name: INVALID_NAME)
27
27
  scroll = Gengou::NamedScroll.new(
28
- start_name: start_name, last_name: last_name, operated: false
28
+ start_name: start_name, last_name: last_name, operated: false, restored: false
29
29
  )
30
30
  range = scroll.range
31
31
 
@@ -35,6 +35,7 @@ module Zakuro
35
35
  years = get_full_range_years(
36
36
  context: context, start_date: start_date, last_date: last_date
37
37
  )
38
+
38
39
  operated_years = get_operation_range_years(
39
40
  context: context, years: years, start_date: start_date, last_date: last_date
40
41
  )
@@ -66,8 +67,14 @@ module Zakuro
66
67
  #
67
68
  def get_full_range_years(context:, start_date: Western::Calendar.new,
68
69
  last_date: Western::Calendar.new)
70
+ # 年情報の再計算
71
+ # * 元号開始日に計算値と運用値のズレが見られる場合、年情報の範囲が異なる場合がある
72
+ # * 例:0781-03-01(計算値は前の元号の「宝亀」を含めるが、運用値では含まない)
73
+ #
74
+ # 運用値の範囲で日付検索するが、元号開始日は計算値のままで取る
69
75
  full_range = Calculation::Range::DatedFullRange.new(
70
- context: context, start_date: start_date, last_date: last_date
76
+ context: context, start_date: start_date, last_date: last_date,
77
+ operated: true, restored: true
71
78
  )
72
79
  full_range.get
73
80
  end
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../../../tools/gengou_range_comparer'
4
+
3
5
  require_relative '../../range/dated_operation_range'
4
6
 
5
7
  require_relative '../../range/dated_full_range'
6
8
 
7
- require_relative './specifier/single_day'
8
-
9
9
  require_relative '../internal/operation'
10
10
 
11
+ require_relative './specifier/single_day'
12
+
11
13
  # :nodoc:
12
14
  module Zakuro
13
15
  # :nodoc:
@@ -53,8 +55,13 @@ module Zakuro
53
55
  # @return [Array<Calculation::Base::Year>] 完全範囲
54
56
  #
55
57
  def get_full_range_years(context:, date: Western::Calendar.new)
58
+ # 年情報の再計算
59
+ # * 元号開始日に計算値と運用値のズレが見られる場合、年情報の範囲が異なる場合がある
60
+ # * 例:0781-03-01(計算値は前の元号の「宝亀」を含めるが、運用値では含まない)
61
+ #
62
+ # 運用値の範囲で日付検索するが、元号開始日は計算値のままで取る
56
63
  full_range = Calculation::Range::DatedFullRange.new(
57
- context: context, start_date: date
64
+ context: context, start_date: date, operated: true, restored: true
58
65
  )
59
66
  full_range.get
60
67
  end
@@ -93,12 +100,12 @@ module Zakuro
93
100
  end
94
101
 
95
102
  #
96
- # 完全範囲を取得する
103
+ # 運用情報を取得する
97
104
  #
98
105
  # @param [Array<Calculation::Base::Year>] years 完全範囲
99
106
  # @param [Western::Calendar] date 西暦日
100
107
  #
101
- # @return [Array<Calculation::Base::Year>] 完全範囲
108
+ # @return [Result::Operation] 運用情報
102
109
  #
103
110
  def get_operation(years:, date: Western::Calendar.new)
104
111
  calc_date = Specifier::SingleDay.get(
@@ -34,15 +34,18 @@ module Zakuro
34
34
  # @param [Western::Calendar] start_date 開始日
35
35
  # @param [Western::Calendar] last_date 終了日
36
36
  # @param [True, False] operated 運用値設定
37
+ # @param [True, False] restored 運用値から計算値に戻すか
37
38
  #
38
39
  # @return [Array<LinearGengou>] 元号
39
40
  #
40
41
  def get(line: FIRST_LINE,
41
42
  start_date: Western::Calendar.new, last_date: Western::Calendar.new,
42
- operated: false)
43
-
43
+ operated: false, restored: false)
44
44
  if operated
45
- return OPERATED_SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
45
+ result = OPERATED_SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
46
+ return result unless restored
47
+
48
+ return restore(line: line, list: result)
46
49
  end
47
50
 
48
51
  SUMMARY.get(line: line, start_date: start_date, last_date: last_date)
@@ -54,14 +57,38 @@ module Zakuro
54
57
  # @param [Integer] line 行
55
58
  # @param [String] name 元号名
56
59
  # @param [True, False] operated 運用値設定
60
+ # @param [True, False] restored 運用値から計算値に戻すか
57
61
  #
58
62
  # @return [Array<LinearGengou>] 元号
59
63
  #
60
- def get_by_name(line: FIRST_LINE, name:, operated: false)
61
- return OPERATED_SUMMARY.get_by_name(line: line, name: name) if operated
64
+ def get_by_name(line: FIRST_LINE, name:, operated: false, restored: false)
65
+ if operated
66
+ result = OPERATED_SUMMARY.get_by_name(line: line, name: name)
67
+ return result unless restored
68
+
69
+ return restore(line: line, list: result)
70
+ end
62
71
 
63
72
  SUMMARY.get_by_name(line: line, name: name)
64
73
  end
74
+
75
+ #
76
+ # 運用値から計算値に戻す
77
+ #
78
+ # @param [Integer] line 行
79
+ # @param [Array<LinearGengou>] list 元号
80
+ #
81
+ # @return [Array<LinearGengou>] 元号
82
+ #
83
+ def restore(line: FIRST_LINE, list: [])
84
+ result = []
85
+ list.each do |gengou|
86
+ calc = SUMMARY.get_by_name(line: line, name: gengou.name)
87
+ result |= calc
88
+ end
89
+
90
+ result
91
+ end
65
92
  end
66
93
  end
67
94
  end
@@ -27,14 +27,16 @@ module Zakuro
27
27
  # @param [Western::Calendar] start_date 開始日
28
28
  # @param [Western::Calendar] last_date 終了日
29
29
  # @param [True, False] operated 運用値設定
30
+ # @param [True, False] restored 運用値から計算値に戻すか
30
31
  #
31
32
  # @return [Array<LinearGengou>] 該当行の元号
32
33
  #
33
34
  def line(line: FIRST_LINE,
34
35
  start_date: Western::Calendar.new, last_date: Western::Calendar.new,
35
- operated: false)
36
+ operated: false, restored: false)
36
37
  Alignment.get(
37
- line: line, start_date: start_date, last_date: last_date, operated: operated
38
+ line: line, start_date: start_date, last_date: last_date, operated: operated,
39
+ restored: restored
38
40
  )
39
41
  end
40
42
 
@@ -42,14 +44,14 @@ module Zakuro
42
44
  # 該当行の元号を取得する(元号名)
43
45
  #
44
46
  # @param [Integer] line 行番号
45
- # @param [Western::Calendar] start_date 開始日
46
- # @param [Western::Calendar] last_date 終了日
47
+ # @param [String] name 元号名
47
48
  # @param [True, False] operated 運用値設定
49
+ # @param [True, False] restored 運用値から計算値に戻すか
48
50
  #
49
51
  # @return [Array<LinearGengou>] 該当行の元号
50
52
  #
51
- def line_by_name(line: FIRST_LINE, name:, operated: false)
52
- Alignment.get_by_name(line: line, name: name, operated: operated)
53
+ def line_by_name(line: FIRST_LINE, name:, operated: false, restored: false)
54
+ Alignment.get_by_name(line: line, name: name, operated: operated, restored: restored)
53
55
  end
54
56
  end
55
57
  end
@@ -11294,7 +11294,7 @@
11294
11294
  zodiac_name: "-"
11295
11295
  dest:
11296
11296
  index: '0'
11297
- from: '1050-12-17'
11297
+ from: '1050-11-17'
11298
11298
  zodiac_name: "-"
11299
11299
  days: "-"
11300
11300
  days: "-1"
@@ -13837,38 +13837,6 @@
13837
13837
  zodiac_name: "-"
13838
13838
  days: "-"
13839
13839
  days: "-1"
13840
- - id: 318-1-a
13841
- relation_id: "-"
13842
- parent_id: 318-1-1
13843
- page: '318'
13844
- number: "-"
13845
- japan_date: 正平 12年 7 小 甲戌 10-1300
13846
- western_date: '1357-7-18'
13847
- description: "-"
13848
- note: "-"
13849
- modified: 'true'
13850
- diffs:
13851
- month:
13852
- number:
13853
- src: "-"
13854
- dest: "-"
13855
- leaped:
13856
- src: "-"
13857
- dest: "-"
13858
- days:
13859
- src: 大
13860
- dest: 小
13861
- solar_term:
13862
- src:
13863
- index: "-"
13864
- to: "-"
13865
- zodiac_name: "-"
13866
- dest:
13867
- index: "-"
13868
- from: "-"
13869
- zodiac_name: "-"
13870
- days: "-"
13871
- days: "-"
13872
13840
  - id: 318-1-0
13873
13841
  relation_id: 318-1-1
13874
13842
  parent_id: "-"
@@ -13888,7 +13856,7 @@
13888
13856
  src: 'false'
13889
13857
  dest: 'true'
13890
13858
  days:
13891
- src:
13859
+ src:
13892
13860
  dest: 小
13893
13861
  solar_term:
13894
13862
  src:
@@ -13920,7 +13888,7 @@
13920
13888
  src: 'true'
13921
13889
  dest: 'false'
13922
13890
  days:
13923
- src:
13891
+ src:
13924
13892
  dest: 大
13925
13893
  solar_term:
13926
13894
  src:
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../output/logger'
4
+
5
+ require_relative '../calculation/cycle/abstract_remainder'
6
+
7
+ require_relative '../calculation/era/gengou/dated_scroll'
8
+
9
+ # TODO: Tools -> Tool
10
+
11
+ # :nodoc:
12
+ module Zakuro
13
+ #
14
+ # Tools 汎用メソッド群
15
+ #
16
+ module Tools
17
+ #
18
+ # GengouRangeComparer 元号範囲比較
19
+ #
20
+ module GengouRangeComparer
21
+ # @return [Output::Logger] ロガー
22
+ LOGGER = Output::Logger.new(location: 'GengouRangeComparer')
23
+
24
+ class << self
25
+ #
26
+ # 元号範囲が計算値/運用値で同一か
27
+ #
28
+ # @param [Western::Calendar] start_date 開始西暦日
29
+ # @param [Western::Calendar] last_date 終了西暦日
30
+ #
31
+ # @return [True] 一致
32
+ # @return [False] 不一致
33
+ #
34
+ def same?(start_date: Western::Calendar.new, last_date: Western::Calendar.new)
35
+ calc_range = Calculation::Gengou::DatedScroll.new(
36
+ start_date: start_date, last_date: last_date
37
+ ).range
38
+
39
+ ope_range = Calculation::Gengou::DatedScroll.new(
40
+ start_date: start_date, last_date: last_date, operated: true
41
+ ).range
42
+
43
+ # 1行目元号
44
+ unless same_line?(calc_line: calc_range.first_list.list,
45
+ ope_line: ope_range.first_list.list)
46
+ return false
47
+ end
48
+
49
+ # 2行目元号
50
+ unless same_line?(calc_line: calc_range.second_list.list,
51
+ ope_line: ope_range.second_list.list)
52
+ return false
53
+ end
54
+
55
+ true
56
+ end
57
+
58
+ private
59
+
60
+ #
61
+ # 同じ予約元号一覧か
62
+ #
63
+ # @param [Array<Japan::Alignment::LinearGengou>] calc_line 予約元号一覧(計算値)
64
+ # @param [Array<Japan::Alignment::LinearGengou>] ope_line 予約元号一覧(運用値)
65
+ #
66
+ # @return [True] 一致
67
+ # @return [False] 不一致
68
+ #
69
+ def same_line?(calc_line: [], ope_line: [])
70
+ return false unless calc_line.size == ope_line.size
71
+
72
+ calc_line.each_with_index do |calc_gengou, index|
73
+ ope_gengou = ope_line[index]
74
+ return false unless calc_gengou.name == ope_gengou.name
75
+ end
76
+
77
+ true
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -4,6 +4,8 @@ require_relative '../output/logger'
4
4
 
5
5
  require_relative '../calculation/cycle/abstract_remainder'
6
6
 
7
+ # TODO: Tools -> Tool
8
+
7
9
  # :nodoc:
8
10
  module Zakuro
9
11
  #
@@ -14,6 +16,7 @@ module Zakuro
14
16
  # RemainderComparer 大余小余比較
15
17
  #
16
18
  module RemainderComparer
19
+ # @return [Output::Logger] ロガー
17
20
  LOGGER = Output::Logger.new(location: 'RemainderComparer')
18
21
 
19
22
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zakuro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pldb
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-25 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mainly lunar solar calendar
14
14
  email:
@@ -184,6 +184,7 @@ files:
184
184
  - lib/zakuro/result/operation/month/annotation.rb
185
185
  - lib/zakuro/result/operation/month/history.rb
186
186
  - lib/zakuro/result/result.rb
187
+ - lib/zakuro/tools/gengou_range_comparer.rb
187
188
  - lib/zakuro/tools/remainder_comparer.rb
188
189
  - lib/zakuro/tools/stringifier.rb
189
190
  - lib/zakuro/tools/typeconv.rb
@@ -277,7 +278,7 @@ metadata:
277
278
  homepage_uri: https://github.com/pldb/zakuro
278
279
  source_code_uri: https://github.com/pldb/zakuro
279
280
  changelog_uri: https://github.com/pldb/zakuro
280
- post_install_message:
281
+ post_install_message:
281
282
  rdoc_options: []
282
283
  require_paths:
283
284
  - lib
@@ -292,8 +293,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
293
  - !ruby/object:Gem::Version
293
294
  version: '0'
294
295
  requirements: []
295
- rubygems_version: 3.1.2
296
- signing_key:
296
+ rubygems_version: 3.1.4
297
+ signing_key:
297
298
  specification_version: 4
298
299
  summary: japanese calendar library.
299
300
  test_files: []