zakuro 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +25 -0
  5. data/doc/operation/csv/month.csv +4 -5
  6. data/doc/operation/operation.xlsx +0 -0
  7. data/doc/vanished_date.md +26 -0
  8. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +26 -0
  9. data/lib/zakuro/calculation/cycle/abstract_solar_term.rb +7 -1
  10. data/lib/zakuro/calculation/era/gengou/dated_scroll.rb +8 -2
  11. data/lib/zakuro/calculation/era/gengou/internal/counter.rb +5 -5
  12. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_list.rb +18 -5
  13. data/lib/zakuro/calculation/era/gengou/internal/reserve/abstract_range.rb +24 -9
  14. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_list.rb +7 -2
  15. data/lib/zakuro/calculation/era/gengou/internal/reserve/dated_range.rb +7 -2
  16. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_list.rb +13 -3
  17. data/lib/zakuro/calculation/era/gengou/internal/reserve/named_range.rb +15 -4
  18. data/lib/zakuro/calculation/era/gengou/named_scroll.rb +8 -2
  19. data/lib/zakuro/calculation/monthly/initialized_month.rb +4 -2
  20. data/lib/zakuro/calculation/monthly/meta/all_solar_term.rb +64 -0
  21. data/lib/zakuro/calculation/monthly/meta/meta_collector.rb +80 -0
  22. data/lib/zakuro/calculation/monthly/meta.rb +60 -0
  23. data/lib/zakuro/calculation/monthly/month.rb +119 -5
  24. data/lib/zakuro/calculation/monthly/operated_month.rb +7 -19
  25. data/lib/zakuro/calculation/option/dropped_date/location.rb +20 -24
  26. data/lib/zakuro/calculation/option/vanished_date/location.rb +9 -2
  27. data/lib/zakuro/calculation/range/abstract_full_range.rb +19 -2
  28. data/lib/zakuro/calculation/range/abstract_operation_range.rb +20 -2
  29. data/lib/zakuro/calculation/range/dated_full_range.rb +8 -3
  30. data/lib/zakuro/calculation/range/dated_operation_range.rb +4 -1
  31. data/lib/zakuro/calculation/range/medieval_annual_range.rb +1 -1
  32. data/lib/zakuro/calculation/range/named_full_range.rb +3 -1
  33. data/lib/zakuro/calculation/range/named_operation_range.rb +3 -1
  34. data/lib/zakuro/calculation/range/transfer/gengou_scroller.rb +2 -1
  35. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +10 -8
  36. data/lib/zakuro/calculation/stella/solar/abstract_average.rb +8 -34
  37. data/lib/zakuro/calculation/summary/internal/option.rb +24 -5
  38. data/lib/zakuro/calculation/summary/western/range.rb +8 -1
  39. data/lib/zakuro/calculation/summary/western/single.rb +12 -5
  40. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +1 -1
  41. data/lib/zakuro/era/japan/gengou/alignment/linear_gengou.rb +1 -1
  42. data/lib/zakuro/era/japan/gengou/alignment.rb +41 -2
  43. data/lib/zakuro/era/japan/gengou/resource/parser.rb +83 -25
  44. data/lib/zakuro/era/japan/gengou/resource/type.rb +81 -26
  45. data/lib/zakuro/era/japan/gengou/resource/validator.rb +100 -21
  46. data/lib/zakuro/era/japan/gengou/resource/yaml/set-001-until-south.yaml +1123 -375
  47. data/lib/zakuro/era/japan/gengou/resource/yaml/set-002-from-north.yaml +487 -163
  48. data/lib/zakuro/era/japan/gengou/resource/yaml/set-003-modern.yaml +30 -10
  49. data/lib/zakuro/era/japan/gengou/resource.rb +16 -0
  50. data/lib/zakuro/era/japan/gengou.rb +11 -6
  51. data/lib/zakuro/operation/yaml/month.yaml +4 -36
  52. data/lib/zakuro/output/logger.rb +21 -3
  53. data/lib/zakuro/tools/gengou_range_comparer.rb +82 -0
  54. data/lib/zakuro/tools/remainder_comparer.rb +100 -0
  55. metadata +11 -6
@@ -5,16 +5,24 @@ last_year:
5
5
  japan: 7981
6
6
  western: 9999
7
7
  last_date:
8
- japan: 令和7981年12月31日
9
- western: '9999-12-31'
8
+ calculation:
9
+ japan: ''
10
+ western: ''
11
+ operation:
12
+ japan: 令和7981年12月31日
13
+ western: '9999-12-31'
10
14
  list:
11
15
  - name: 明治
12
16
  start_year:
13
17
  japan: 1
14
18
  western: 1868
15
19
  start_date:
16
- japan: 明治01年09月08日
17
- western: '1868-10-23'
20
+ calculation:
21
+ japan: ''
22
+ western: ''
23
+ operation:
24
+ japan: 明治01年09月08日
25
+ western: '1868-10-23'
18
26
  disuse:
19
27
  new_year_date: '1868-1-25'
20
28
  note: ''
@@ -23,8 +31,12 @@ list:
23
31
  japan: 1
24
32
  western: 1912
25
33
  start_date:
26
- japan: 大正01年07月30日
27
- western: '1912-7-30'
34
+ calculation:
35
+ japan: ''
36
+ western: ''
37
+ operation:
38
+ japan: 大正01年07月30日
39
+ western: '1912-7-30'
28
40
  disuse:
29
41
  new_year_date: '1912-1-1'
30
42
  note: ''
@@ -33,8 +45,12 @@ list:
33
45
  japan: 1
34
46
  western: 1926
35
47
  start_date:
36
- japan: 昭和01年12月25日
37
- western: '1926-12-25'
48
+ calculation:
49
+ japan: ''
50
+ western: ''
51
+ operation:
52
+ japan: 昭和01年12月25日
53
+ western: '1926-12-25'
38
54
  disuse:
39
55
  new_year_date: '1926-1-1'
40
56
  note: ''
@@ -43,8 +59,12 @@ list:
43
59
  japan: 1
44
60
  western: 2019
45
61
  start_date:
46
- japan: 令和01年05月01日
47
- western: '2019-5-1'
62
+ calculation:
63
+ japan: ''
64
+ western: ''
65
+ operation:
66
+ japan: 令和01年05月01日
67
+ western: '2019-5-1'
48
68
  disuse:
49
69
  new_year_date: '2019-1-1'
50
70
  note: ''
@@ -27,6 +27,22 @@ module Zakuro
27
27
  __dir__
28
28
  ))
29
29
  ].freeze
30
+
31
+ # @return [Array<Set>] 元号セット情報リスト(運用値)
32
+ OPERATED_LIST = [
33
+ Parser.run(filepath: File.expand_path(
34
+ './resource/yaml/set-001-until-south.yaml',
35
+ __dir__
36
+ ), operated: true),
37
+ Parser.run(filepath: File.expand_path(
38
+ './resource/yaml/set-002-from-north.yaml',
39
+ __dir__
40
+ ), operated: true),
41
+ Parser.run(filepath: File.expand_path(
42
+ './resource/yaml/set-003-modern.yaml',
43
+ __dir__
44
+ ), operated: true)
45
+ ].freeze
30
46
  end
31
47
  end
32
48
  end
@@ -26,13 +26,17 @@ module Zakuro
26
26
  # @param [Integer] line 行番号
27
27
  # @param [Western::Calendar] start_date 開始日
28
28
  # @param [Western::Calendar] last_date 終了日
29
+ # @param [True, False] operated 運用値設定
30
+ # @param [True, False] restored 運用値から計算値に戻すか
29
31
  #
30
32
  # @return [Array<LinearGengou>] 該当行の元号
31
33
  #
32
34
  def line(line: FIRST_LINE,
33
- start_date: Western::Calendar.new, last_date: Western::Calendar.new)
35
+ start_date: Western::Calendar.new, last_date: Western::Calendar.new,
36
+ operated: false, restored: false)
34
37
  Alignment.get(
35
- line: line, start_date: start_date, last_date: last_date
38
+ line: line, start_date: start_date, last_date: last_date, operated: operated,
39
+ restored: restored
36
40
  )
37
41
  end
38
42
 
@@ -40,13 +44,14 @@ module Zakuro
40
44
  # 該当行の元号を取得する(元号名)
41
45
  #
42
46
  # @param [Integer] line 行番号
43
- # @param [Western::Calendar] start_date 開始日
44
- # @param [Western::Calendar] last_date 終了日
47
+ # @param [String] name 元号名
48
+ # @param [True, False] operated 運用値設定
49
+ # @param [True, False] restored 運用値から計算値に戻すか
45
50
  #
46
51
  # @return [Array<LinearGengou>] 該当行の元号
47
52
  #
48
- def line_by_name(line: FIRST_LINE, name:)
49
- Alignment.get_by_name(line: line, name: name)
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)
50
55
  end
51
56
  end
52
57
  end
@@ -3091,7 +3091,7 @@
3091
3091
  dest: "-"
3092
3092
  days:
3093
3093
  src: 大
3094
- dest:
3094
+ dest:
3095
3095
  solar_term:
3096
3096
  src:
3097
3097
  index: "-"
@@ -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:
@@ -9,6 +9,7 @@ module Zakuro
9
9
  # @note 本番では使用しない
10
10
  #
11
11
  class Logger
12
+ # @return [Hash<Symbol, Integer>] ログレベル
12
13
  LEVELS = {
13
14
  none: -1,
14
15
  debug: 0,
@@ -17,6 +18,7 @@ module Zakuro
17
18
  error: 3
18
19
  }.freeze
19
20
 
21
+ # @return [Integer] 現在ログレベル
20
22
  LEVEL = LEVELS[:none]
21
23
 
22
24
  # @return [String] 呼び出し位置
@@ -32,7 +34,9 @@ module Zakuro
32
34
  # @param [String] messages メッセージ
33
35
  #
34
36
  def debug(*messages)
35
- return if LEVEL < LEVELS[:debug]
37
+ return if none?
38
+
39
+ return if LEVEL >= LEVELS[:debug]
36
40
 
37
41
  output('DEBUG', *messages)
38
42
  end
@@ -43,7 +47,9 @@ module Zakuro
43
47
  # @param [String] messages メッセージ
44
48
  #
45
49
  def info(*messages)
46
- return if LEVEL < LEVELS[:info]
50
+ return if none?
51
+
52
+ return if LEVEL >= LEVELS[:info]
47
53
 
48
54
  output('INFO', *messages)
49
55
  end
@@ -55,7 +61,9 @@ module Zakuro
55
61
  # @param [String] messages メッセージ
56
62
  #
57
63
  def error(error, *messages)
58
- return if LEVEL < LEVELS[:error]
64
+ return if none?
65
+
66
+ return if LEVEL >= LEVELS[:error]
59
67
 
60
68
  output('ERROR', *messages)
61
69
  output('ERROR', error.message)
@@ -64,6 +72,16 @@ module Zakuro
64
72
 
65
73
  private
66
74
 
75
+ #
76
+ # 出力なしか
77
+ #
78
+ # @return [True] 出力なし
79
+ # @return [False] 出力あり
80
+ #
81
+ def none?
82
+ LEVEL < LEVELS[:debug]
83
+ end
84
+
67
85
  #
68
86
  # 標準出力を行う
69
87
  #
@@ -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
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../output/logger'
4
+
5
+ require_relative '../calculation/cycle/abstract_remainder'
6
+
7
+ # TODO: Tools -> Tool
8
+
9
+ # :nodoc:
10
+ module Zakuro
11
+ #
12
+ # Tools 汎用メソッド群
13
+ #
14
+ module Tools
15
+ #
16
+ # RemainderComparer 大余小余比較
17
+ #
18
+ module RemainderComparer
19
+ # @return [Output::Logger] ロガー
20
+ LOGGER = Output::Logger.new(location: 'RemainderComparer')
21
+
22
+ class << self
23
+ #
24
+ # 大余を基準に範囲チェックをする
25
+ #
26
+ # 次のパターンで用いる
27
+ # 1. 月内(当月朔日から当月末日(来月朔日の前日)の間)に二十四節気があるか
28
+ # * target: 二十四節気
29
+ # * start: 当月朔日
30
+ # * last: 次月朔日
31
+ # 2. ある二十四節気に対象の日があるか
32
+ # * target: 対象の日
33
+ # * start: 二十四節気
34
+ # * last: 次の二十四節気
35
+ #
36
+ # @param [Calcuration::Cycle::AbstractRemainder] target 対象日
37
+ # @param [Calcuration::Cycle::AbstractRemainder] start 範囲開始
38
+ # @param [Calcuration::Cycle::AbstractRemainder] last 範囲終了
39
+ #
40
+ # @return [True] 対象日がある
41
+ # @return [False] 対象日がない
42
+ #
43
+ def in_range?(target:, start:, last:)
44
+ # 『日本暦日便覧』では下記5日を没日ありとしている
45
+ # これは二十四節気の小余と秒が0の場合に限って、範囲を翌日にずらすことを指している
46
+ #
47
+ # * 貞観12年7月18日
48
+ # * 天喜5年3月11日
49
+ # * 寛元1年11月4日
50
+ # * 永享2年7月26日
51
+ # * 元和3年3月19日
52
+ #
53
+ last_day = last.only_day? ? last.day + 1 : last.day
54
+ in_range_day?(target: target.day, start: start.day, last: last_day)
55
+ end
56
+
57
+ #
58
+ # 大余を基準に範囲チェックをする
59
+ #
60
+ # @param [Calcuration::Cycle::AbstractRemainder] target 対象日
61
+ # @param [Calcuration::Cycle::AbstractRemainder] start 範囲開始
62
+ # @param [Integer] limit 大余上限
63
+ #
64
+ # @return [True] 対象日がある
65
+ # @return [False] 対象日がない
66
+ #
67
+ def in_limit?(target:, start:, limit:)
68
+ last_day = start.add_day(limit).day
69
+
70
+ in_range_day?(target: target.day, start: start.day, last: last_day)
71
+ end
72
+
73
+ private
74
+
75
+ #
76
+ # 大余を基準に範囲チェックをする
77
+ #
78
+ # @note 大余60で一巡するため 以下2パターンがある
79
+ # * start <= last : (二十四節気) >= start && (二十四節気) < last
80
+ # * start > last : (二十四節気) >= start || (二十四節気) < last
81
+ #
82
+ # @param [Integer] target 対象日
83
+ # @param [Integer] start 範囲開始
84
+ # @param [Integer] last 範囲終了
85
+ #
86
+ # @return [True] 対象日がある
87
+ # @return [False] 対象日がない
88
+ #
89
+ def in_range_day?(target:, start:, last:)
90
+ start_over = (target >= start)
91
+ last_under = (target < last)
92
+
93
+ return start_over && last_under if start <= last
94
+
95
+ start_over || last_under
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
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.2
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: 2022-12-29 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:
@@ -86,6 +86,9 @@ files:
86
86
  - lib/zakuro/calculation/monthly/const.rb
87
87
  - lib/zakuro/calculation/monthly/first_day.rb
88
88
  - lib/zakuro/calculation/monthly/initialized_month.rb
89
+ - lib/zakuro/calculation/monthly/meta.rb
90
+ - lib/zakuro/calculation/monthly/meta/all_solar_term.rb
91
+ - lib/zakuro/calculation/monthly/meta/meta_collector.rb
89
92
  - lib/zakuro/calculation/monthly/month.rb
90
93
  - lib/zakuro/calculation/monthly/month_label.rb
91
94
  - lib/zakuro/calculation/monthly/operated_month.rb
@@ -181,6 +184,8 @@ files:
181
184
  - lib/zakuro/result/operation/month/annotation.rb
182
185
  - lib/zakuro/result/operation/month/history.rb
183
186
  - lib/zakuro/result/result.rb
187
+ - lib/zakuro/tools/gengou_range_comparer.rb
188
+ - lib/zakuro/tools/remainder_comparer.rb
184
189
  - lib/zakuro/tools/stringifier.rb
185
190
  - lib/zakuro/tools/typeconv.rb
186
191
  - lib/zakuro/tools/typeof.rb
@@ -273,7 +278,7 @@ metadata:
273
278
  homepage_uri: https://github.com/pldb/zakuro
274
279
  source_code_uri: https://github.com/pldb/zakuro
275
280
  changelog_uri: https://github.com/pldb/zakuro
276
- post_install_message:
281
+ post_install_message:
277
282
  rdoc_options: []
278
283
  require_paths:
279
284
  - lib
@@ -288,8 +293,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
293
  - !ruby/object:Gem::Version
289
294
  version: '0'
290
295
  requirements: []
291
- rubygems_version: 3.1.2
292
- signing_key:
296
+ rubygems_version: 3.1.4
297
+ signing_key:
293
298
  specification_version: 4
294
299
  summary: japanese calendar library.
295
300
  test_files: []