zakuro 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -10
  3. data/VERSION +1 -1
  4. data/doc/dropped_date.md +93 -0
  5. data/doc/error.md +45 -0
  6. data/lib/zakuro/calculation/base/day.rb +52 -0
  7. data/lib/zakuro/calculation/base/operated_year.rb +3 -3
  8. data/lib/zakuro/calculation/base/year.rb +4 -4
  9. data/lib/zakuro/calculation/cycle/abstract_remainder.rb +5 -3
  10. data/lib/zakuro/calculation/monthly/initialized_month.rb +1 -1
  11. data/lib/zakuro/calculation/monthly/month.rb +3 -3
  12. data/lib/zakuro/calculation/monthly/operated_month.rb +1 -1
  13. data/lib/zakuro/calculation/option/dropped_date/abstract_parameter.rb +44 -0
  14. data/lib/zakuro/calculation/option/dropped_date/location.rb +135 -0
  15. data/lib/zakuro/calculation/range/abstract_full_range.rb +10 -8
  16. data/lib/zakuro/calculation/range/abstract_operation_range.rb +2 -2
  17. data/lib/zakuro/calculation/range/dated_full_range.rb +1 -1
  18. data/lib/zakuro/calculation/range/dated_operation_range.rb +1 -1
  19. data/lib/zakuro/calculation/range/medieval_annual_range.rb +2 -2
  20. data/lib/zakuro/calculation/range/named_full_range.rb +1 -1
  21. data/lib/zakuro/calculation/range/named_operation_range.rb +1 -1
  22. data/lib/zakuro/calculation/range/operated_solar_terms.rb +9 -9
  23. data/lib/zakuro/calculation/range/transfer/year_boundary.rb +6 -6
  24. data/lib/zakuro/calculation/stella/solar/abstract_location.rb +2 -0
  25. data/lib/zakuro/calculation/summary/internal/day.rb +40 -0
  26. data/lib/zakuro/calculation/summary/internal/month.rb +15 -7
  27. data/lib/zakuro/calculation/summary/internal/option.rb +85 -0
  28. data/lib/zakuro/calculation/summary/japan/range.rb +15 -9
  29. data/lib/zakuro/calculation/summary/japan/single.rb +6 -6
  30. data/lib/zakuro/calculation/summary/japan/specifier/single_day.rb +10 -5
  31. data/lib/zakuro/calculation/summary/western/range.rb +5 -5
  32. data/lib/zakuro/calculation/summary/western/single.rb +9 -9
  33. data/lib/zakuro/calculation/summary/western/specifier/multiple_day.rb +15 -10
  34. data/lib/zakuro/calculation/summary/western/specifier/single_day.rb +12 -7
  35. data/lib/zakuro/calculation/type/optional.rb +46 -0
  36. data/lib/zakuro/condition.rb +60 -20
  37. data/lib/zakuro/context/context.rb +44 -0
  38. data/lib/zakuro/context/option.rb +117 -0
  39. data/lib/zakuro/context/version_class_resolver.rb +110 -0
  40. data/lib/zakuro/era/japan/gengou/alignment/aligner.rb +4 -0
  41. data/lib/zakuro/era/japan/gengou/resource/parser.rb +2 -0
  42. data/lib/zakuro/era/japan/gengou/resource/type.rb +6 -0
  43. data/lib/zakuro/era/western/calendar.rb +4 -0
  44. data/lib/zakuro/exception/case/pattern.rb +39 -3
  45. data/lib/zakuro/exception/exception.rb +3 -3
  46. data/lib/zakuro/exception/zakuro_error.rb +19 -1
  47. data/lib/zakuro/gateway/range.rb +2 -2
  48. data/lib/zakuro/gateway/single.rb +1 -1
  49. data/lib/zakuro/merchant.rb +78 -8
  50. data/lib/zakuro/operation/month/parser.rb +2 -0
  51. data/lib/zakuro/output/response.rb +24 -57
  52. data/lib/zakuro/result/data/option/abstract_option.rb +37 -0
  53. data/lib/zakuro/result/data/option/dropped_date/calculation.rb +47 -0
  54. data/lib/zakuro/result/data/option/dropped_date/option.rb +47 -0
  55. data/lib/zakuro/result/data/option/dropped_date/solar_term.rb +48 -0
  56. data/lib/zakuro/result/data/single_day.rb +9 -1
  57. data/lib/zakuro/result/operation/{operation.rb → bundle.rb} +0 -0
  58. data/lib/zakuro/result/result.rb +1 -1
  59. data/lib/zakuro/tools/stringifier.rb +26 -3
  60. data/lib/zakuro/version/daien/cycle/remainder.rb +2 -2
  61. data/lib/zakuro/version/daien/option/dropped_date/parameter.rb +31 -0
  62. data/lib/zakuro/version/daien/range/annual_range.rb +1 -1
  63. data/lib/zakuro/version/daien/stella/lunar/adjustment.rb +2 -0
  64. data/lib/zakuro/version/daien/stella/lunar/value.rb +2 -0
  65. data/lib/zakuro/version/genka/cycle/remainder.rb +2 -2
  66. data/lib/zakuro/version/genka/option/dropped_date/parameter.rb +31 -0
  67. data/lib/zakuro/version/genka/range/annual_range.rb +1 -1
  68. data/lib/zakuro/version/gihou/cycle/remainder.rb +2 -2
  69. data/lib/zakuro/version/gihou/option/dropped_date/parameter.rb +31 -0
  70. data/lib/zakuro/version/gihou/range/annual_range.rb +1 -1
  71. data/lib/zakuro/version/gihou/stella/lunar/adjustment.rb +2 -0
  72. data/lib/zakuro/version/gihou/stella/lunar/value.rb +2 -0
  73. data/lib/zakuro/version/senmyou/const/remainder.rb +5 -0
  74. data/lib/zakuro/version/senmyou/cycle/remainder.rb +37 -2
  75. data/lib/zakuro/version/senmyou/option/dropped_date/parameter.rb +33 -0
  76. data/lib/zakuro/version/senmyou/range/annual_range.rb +1 -1
  77. data/lib/zakuro/version/senmyou/stella/lunar/adjustment.rb +2 -0
  78. data/lib/zakuro/version/senmyou/stella/lunar/value.rb +2 -0
  79. metadata +26 -9
  80. data/lib/zakuro/version/context.rb +0 -44
  81. data/lib/zakuro/version/version_class_resolver.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 294b07e6f6f82cad6ed7d5332d96a0c147ee1cbcbb842faa745918f1d8fbac2e
4
- data.tar.gz: 41341f57aab606cea9a86c75aa4dbef8a8d247421d7428ddf5f1e442afc1b8db
3
+ metadata.gz: fd91623531440c342355fd005938af7cc10d07ae858dfb83d51704c6c1eab92c
4
+ data.tar.gz: 0a1bfca6ded7403960512c9854c5b22e95b761fb1c8d04fd530cb4806c2eaf66
5
5
  SHA512:
6
- metadata.gz: 9f3aee8d972a13e41ae98cb6b600f2032e833380a845513b2a738bf045e7d36a719a2e31161fd90f23194bdee4e0a690dc931934ad30ab0940742f20ea0f7bc7
7
- data.tar.gz: 8c8ea9c23b11c28910cbfcdad25dec4720f919a1bbb0551737f8cf82cc62cd59621dcdd4770580d81c7a4a1c8d8859765e3ae7cd39592369a25dd89e1da9932d
6
+ metadata.gz: 76d1ad94413f1b0101964e6ac292e8e4074e2441418a1e31ad3f46d01397e5dba54afaf4799f1a45b310cb32bc17dc27bcf0d6a76348486dacb8a45ecf0df7e3
7
+ data.tar.gz: f97b9d72fde20c6bcf991f8136b8c9ee935516c27243f7a46ad60c1c38abe32cecb825a51083f01b605d9f4a00810df7c29be09a6564b2881000dd9ae6713786
data/README.md CHANGED
@@ -63,8 +63,7 @@ western_date = Date.new(862, 2, 3)
63
63
  # 初期化時の設定
64
64
  merchant = Zakuro::Merchant.new(condition: { date: western_date })
65
65
  puts merchant.commit.to_json
66
- # => {"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"
67
- 大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}}}}
66
+ # => {"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}}}}
68
67
 
69
68
  western_date = Date.new(1685, 2, 3)
70
69
 
@@ -72,12 +71,12 @@ western_date = Date.new(1685, 2, 3)
72
71
  # merchant = Zakuro::Merchant.new
73
72
  merchant.offer(condition: { date: western_date })
74
73
  puts merchant.commit.to_json
75
- # => {"data":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"甲子","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"甲子","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"}}}}
74
+ # => {"data":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞享","number":1},"second_gengou":{"name":"","number":-1},"zodiac_name":"","total_days":354},"month":{"number":12,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"壬辰","remainder":"28-4182","western_date":"1685-01-05"},"odd_solar_terms":[{"index":1,"remainder":"30-890"}],"even_solar_terms":[{"index":2,"remainder":"45-2726"}]},"day":{"number":30,"zodiac_name":"辛酉","remainder":"57-4182","western_date":"1685-02-03"},"options":{}}}}
76
75
 
77
76
  # 期間検索
78
77
  merchant = Zakuro::Merchant.new(condition: { range: {start: Date.new(862, 2, 3), last: Date.new(862, 2, 4)}})
79
78
  puts merchant.commit.to_json
80
- {"list":[{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"}}}},{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"}}}}]}
79
+ # => {"list":[{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"options":{}}}},{"data":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"},"options":{}},"operation":{"operated":false,"month":{"current":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]},"parent":{"id":"","western_date":"","page":-1,"number":-1,"annotations":[]}},"original":{"year":{"first_gengou":{"name":"貞観","number":4},"second_gengou":{"name":"","number":-1},"zodiac_name":"壬午","total_days":354},"month":{"number":1,"leaped":false,"days_name":"大","first_day":{"number":1,"zodiac_name":"庚午","remainder":"6-1282","western_date":"0862-02-03"},"odd_solar_terms":[{"index":5,"remainder":"34-5368"}],"even_solar_terms":[{"index":4,"remainder":"19-3532"}]},"day":{"number":2,"zodiac_name":"辛未","remainder":"7-1282","western_date":"0862-02-04"},"options":{}}}}]}
81
80
  ```
82
81
 
83
82
  # 条件
@@ -93,7 +92,7 @@ puts merchant.commit.to_json
93
92
  | 範囲(終了日) | | last | Date | 西暦日 |
94
93
  | | | | String | 和暦日/西暦日 |
95
94
  | 列 | columns | | Array | 取得したい列の列名 |
96
- | オプション | options | | Array | 取得オプション |
95
+ | オプション | options | | Hash<String, Object> | 取得オプション |
97
96
 
98
97
  現時点では `date` と `range` のみ対応中です。
99
98
 
@@ -101,14 +100,22 @@ puts merchant.commit.to_json
101
100
 
102
101
  | 項目名 | キー名 | データ型 | データ | 備考 |
103
102
  |--------|-----------|----------|--------|------------------------|
104
- | 単位 | unit | String | year | 年単位 |
105
- | | | | month | 月単位 |
106
- | | | | day | 日単位(デフォルト) |
107
- | 没日 | lost_days | TRUE | | 没日あり |
108
- | | | FALSE | | 没日なし(デフォルト) |
103
+ | | version | String | Genka | 元嘉暦 |
104
+ | | | | Gihou | 儀鳳暦 |
105
+ | | | | Daien | 大衍暦 |
106
+ | | | | Senmyou | 宣明暦 |
107
+ | | | | Joukyou | 貞享暦 |
108
+ | | | | Kansei | 寛政暦 |
109
+ | | | | Tenpou | 天保暦 |
110
+ | | | | Gregorio | グレゴリオ暦 |
111
+ | | | | | 指定なし(デフォルト) |
112
+ | 没日 | dropped_days | TRUE | | 没日あり |
113
+ | | | FALSE | | 没日なし(デフォルト) |
109
114
  | 四季 | seasons | TRUE | | 四季あり |
110
115
  | | | FALSE | | 四季なし(デフォルト) |
111
116
 
117
+ 現時点では宣明暦の [没日](./doc/dropped_date.md) のみ試験的に対応しております(結果未検証)。
118
+
112
119
  # 期待値
113
120
  暦算値は『日本暦日原典』、元号の切り替えは『日本史年表 第5版』を範とします。
114
121
 
@@ -166,6 +173,7 @@ puts merchant.commit.to_json
166
173
  | 日の干支 | | zodiac_name | | String | 乙卯 | 日の干支 |
167
174
  | 日の大余小余 | | remainder | | String | 51-2479 | 大余小余 |
168
175
  | 西暦日 | | western_date | | String | 0937-02-14 | 西暦日 |
176
+ | オプション | options | | | Hash<String, Zakuro::Result::Data::Option::AbstractOption>| | オプション値 |
169
177
 
170
178
  ### Zakuro::Result::Operation
171
179
 
@@ -195,6 +203,20 @@ puts merchant.commit.to_json
195
203
  | 注釈内容 |   | | description | String | 計算は51乙卯であるが, 日本紀略に甲寅朔とある。<br>正月甲寅朔のユリウス暦日は2月13日となる。(元旦日食 をさけるための変更か) |   |
196
204
  | 注釈補記 |   | | note | String | - | 原文訂正 |
197
205
 
206
+ ### Zakuro::Result::Data::Option::AbstractOption
207
+
208
+ #### Zakuro::Result::Data::Option::DroppedDate::Option
209
+
210
+ キー: dropped_date
211
+
212
+ | 項目名 | キー名 | - | - | データ型 | 参考値 | 備考 |
213
+ | -------------------- | ----------- | ---------- | --------- | ------------------------------------------------------ | -------- | ------------------ |
214
+ | オプション値有無 | matched | | | True/False | true | |
215
+ | 演算値 | calculation | | | Zakuro::Result::Data::Option::DroppedDate::Calculation | | |
216
+ | 没余 | | remainder | | String | 59-34155 | |
217
+ | 二十四節気 | | solar_term | | Zakuro::Result::Data::Option::DroppedDate::SolarTerm | | |
218
+ | 二十四節気番号 | | | index | Integer | 6 | |
219
+ | 二十四節気の大余小余 | | | remainder | String | 49-7203 | |
198
220
 
199
221
  # 元号
200
222
 
@@ -209,6 +231,11 @@ puts merchant.commit.to_json
209
231
 
210
232
  [宣明暦](./lib/zakuro/version/senmyou/README.md) のみ記載しております。
211
233
 
234
+ # 例外
235
+
236
+ 条件不正などで例外が発生します。
237
+ 詳細は [例外処理](./doc/error.md) を参照してください。
238
+
212
239
  ## コントリビュート(Contributing)
213
240
 
214
241
  バグ報告/修正はこちらまで。
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
@@ -0,0 +1,93 @@
1
+ # 没日
2
+ 没日を端的に説明すると、1太陽年(365.24..日)を360日で表わすために、一定の法則で `存在しない日` として配置された日である
3
+
4
+ 太陽の運行に対応するため、基本的には二十四節気をもとに計算を行う
5
+
6
+ # 期待値
7
+ 「日本暦日便覧」に従う
8
+
9
+ ## 計算
10
+ 「長慶宣明暦算法」に従う
11
+
12
+ 下記は該当箇所の引用と、それに対応する計算を示している
13
+
14
+ ```
15
+ ◯没日ヲ求ルノ術
16
+ 没日ト云ハ毎日の気盈ノ數ツモリテ統法ノ八千四百ニ満タル日ヲ云其モトメヤウノ法ナリ
17
+ ```
18
+
19
+ ```
20
+ 常氣ノ小餘六千五百六十四秒三巳上ハ物之ヲ置テ
21
+ 常氣ハ前ノ等法ニテ求メタル二十四氣トナリ其二十四節氣ノ内イツレニモ小余ノ數六千五百六十四秒三ヨリ以上アラハ没日ヲ求メヨトナリ
22
+ タトヘハ小余ノ數六千五百六十四秒アリテモ秒三ヨリ内ナラハモトムヘラカス秒ノ數ハスクナレトモ小余ノ數多クアラハ求ムヘシ
23
+ 小余ノ一ハ秒ノ八ナレハナリ
24
+ 畢竟ハ小余六千五百六十四秒三アルカ尤モソレヨリ以上アラハ求ムヘシ少シモ以下ナラハ求ムヘカラストナリ
25
+ ```
26
+
27
+ 次のパターンのみ求める
28
+ * 常気の小余 >= 6564.3
29
+
30
+ ```
31
+ 三百六十ヲ以テ之乗シ別ニ秒ヲ置テ四十五ヲ以テ之乗シ小餘ノ之上ニ加フ
32
+ 常氣ノ小余ノ數ニカクルナリ今立春ノ小余八千二百三十六秒七アリ
33
+ 故に没日ヲ求メントテマツ其立春ノ小余八千二百三十六ニ三百六十ヲカクレハ二百九十六萬四千九百六十トナル
34
+ 又別ニ秒七ヲ置テ是ニ四十五ヲカクレハ三百一十五トナル
35
+ 此ヲ右ノ二百九十六萬四千九百六十ニ加フレハ合セテ二百九十六萬五千二百七十五トナル
36
+ 又秒七ヲ八ニワリテ小余ノ次ニ置テ八千二百三十六八分七厘五毛トツテ子テ是ニ三百六十ヲカクレハ二百九十六萬五千二百七十五トナルモ同シ等法ナリ
37
+ ```
38
+
39
+ ある立春の小余: 8236.7
40
+ * A
41
+ * 8236 * 360 = 2964960
42
+ * 7 * 45 = 315
43
+ * 2964960 + 315 = 2965275
44
+ * B
45
+ * 8236 + 7/8 = 8236.875 * 360 = 2965275
46
+
47
+ ```
48
+ 而ソ章歳ノ三百零六萬八千零五十五ヲ以テ直減シ
49
+ 以ハ用ナリ置テト云心ナルヘシ此章歳ノ數三百零六萬八千零五十五ヲ置テコノ内ヲ右ノ二百九十六萬五千二百七十五去テ残テ一十萬零二千七百八十トナルナリ
50
+ 細注ニ或ハ少ヲ以テ多ニ減ストアレトモ是ハアヤマリナルヘシ
51
+ タトヘハ常氣ノ小余八千三百九十九秒七アルトキニ右ノ法ノ如クニシテミレハ三百零二萬三千九百五十五トナル
52
+ コレ章歳ノ數ニ四萬四千一百タラサルナリ
53
+ 然レハ必ラス定テ章歳ノ數ノ内ヲ減スルノ明トシ常氣ノ小余八千三百九十九秒七ヨリ多キクハナキケリ
54
+ ```
55
+ 章歳: 3068055
56
+
57
+ * 3068055 - 2965275 = 102780
58
+ * 負数はない。負数であれば正数にする
59
+
60
+ ```
61
+ 残分ヲ置テ通餘ノ四萬四千一零五十五ヲ以テ之ヲ除シ商ヲ以テ日ト為 常氣ノ之大餘ヲ加フ甲子自之ヲ命シ等外ヲ用フ也
62
+ 残分ト云ハ右ノ章歳ヲ減シタル残リ一十萬零二千七百八十トナリ此數ヲ置テ通余ノ四萬四千一零五十五ニテワレハ商ニ不盡一萬四千六百七十アリ
63
+ サテ此商二ニ常氣立春ノ大余五十六ヲ加レハ五十八トナル
64
+ コレヲ没日ノ大余ノ數トス
65
+ サテ右ノ不盡一萬四千六百七十ヲ没日ノ小余トス
66
+ 其大余ノ數モシ六十ニ満ツルトキハハラヒ去リテ其残リヲ用テサテ前ノ二十四氣ニテ攴干ヲ付タル如ク紀法ノ圖ニテ付ヘシ今大余五十八ハ壬戌ニアタルナリ
67
+ 立春一氣ノ内ニ壬戌ノ日アルヲ没日ノ日トス
68
+ サテ是ハ立春ノ一氣ヲ記セリ
69
+ 二十四氣ノ内イツレニテモ有没日ノ数小余六千五百六十四秒巳上アラハ右ノ如クニシテ求ムヘシ
70
+ ```
71
+
72
+ 通余: 44055
73
+
74
+ * 102780 / 44055 = 2.3329... ≒ 2
75
+ * 102780 % 44055 = 14670
76
+ * 56(立春大余) + 2 = 58
77
+
78
+ 没日: 58-14670
79
+
80
+ ```
81
+ 次ヲ求ルノ術
82
+ ```
83
+
84
+ ```
85
+ 大餘ニ九 小餘ニ二萬八千二百六十
86
+ 二十四氣ノ内ヲ考ヘテイツレニテモ有没日ノ小余六千五百六十四秒三以上アル時ハ右ノ法ノ如ニシテ求ムヘシ
87
+ 又一術アリモトメ得タル没日ノ大余ニ九加エ小余ニ二萬八千二百六十加エテ小余通余ノ四萬四千零五十五ニ満レハ一ニツツメテ其一ヲ大余ニ加ヘ大余六十ニ満レハ去此ノ如ク累加スレハ次々ノ没日ヲ求メ得ルナリ
88
+ 其アル日ハ有没日ノ六千五百六十四秒三以上アル處ノ氣ノ内ニアルトシルヘシ
89
+
90
+ ```
91
+ * 大余 + 9
92
+ * 小余 + 28260
93
+ * 小余 > 44055 の場合は繰り上げ
data/doc/error.md ADDED
@@ -0,0 +1,45 @@
1
+ # 例外処理
2
+
3
+ ## Zakuro::Exception::ZakuroError
4
+
5
+ 例外は `ZakuroError` に集約されます。
6
+
7
+ ```
8
+ merchant = Zakuro::Merchant.new(condition: {})
9
+ merchant.commit
10
+ Traceback (most recent call last):
11
+ 4: from ./bin/console:14:in `<main>'
12
+ 3: from (irb):5
13
+ 2: from /Users/ty/ruby/zakuro/lib/zakuro/merchant.rb:81:in `commit'
14
+ 1: from /Users/ty/ruby/zakuro/lib/zakuro/merchant.rb:132:in `make_uncommitable_error'
15
+ Zakuro::Exception::ZakuroError (an error has occurred:[{"code":"ERROR_0203","message":"検索不可能な日付指定です。"}])
16
+ ```
17
+
18
+ 例外に対応したコードとメッセージを取得できます。
19
+ ```
20
+ merchant = Zakuro::Merchant.new(condition: {})
21
+ begin
22
+ merchant.commit
23
+ rescue Zakuro::Exception::ZakuroError => e
24
+ p e.causes[0].code
25
+ p e.causes[0].message
26
+ end
27
+ => "ERROR_0203"
28
+ => "検索不可能な日付指定です。"
29
+ ```
30
+
31
+ ## エラー種別
32
+
33
+ `Zakuro::Exception::Case::Pattern` の通りです。
34
+
35
+ |コード|メッセージ|引数長|
36
+ |:----|:----|:----|
37
+ |ERROR_0001|内部エラーです。|0|
38
+ |ERROR_0101|日付の型は文字列/日付です。指定型:%s|1|
39
+ |ERROR_0102|範囲の型はhashです。指定型:%s|1|
40
+ |ERROR_0103|オプションの型はhashです。指定型:%s|1|
41
+ |ERROR_0104|列の型は配列です。指定型:%s|1|
42
+ |ERROR_0105|条件の型は配列です。指定型:%s|1|
43
+ |ERROR_0201|一日検索の日付指定が誤っています。|0|
44
+ |ERROR_0202|範囲検索の日付指定が誤っています。|0|
45
+ |ERROR_0203|検索不可能な日付指定です。|0|
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../era/western/calendar'
4
+ require_relative '../cycle/abstract_remainder'
5
+
6
+ # :nodoc:
7
+ module Zakuro
8
+ # :nodoc:
9
+ module Calculation
10
+ # :nodoc:
11
+ module Base
12
+ #
13
+ # Day 日
14
+ #
15
+ class Day
16
+ # @return [Integer] 不正日
17
+ INVALID_NUMBER = -1
18
+
19
+ # @return [Integer] 日
20
+ attr_reader :number
21
+ # @return [Western::Calendar] 西暦日
22
+ attr_reader :western_date
23
+ # @return [Cycle::AbstractRemainder] 和暦日
24
+ attr_reader :remainder
25
+
26
+ #
27
+ # 初期化
28
+ #
29
+ # @param [Integer] number 日
30
+ # @param [Western::Calendar] western_date 西暦日
31
+ # @param [Cycle::AbstractRemainder] 和暦日
32
+ #
33
+ def initialize(number: INVALID_NUMBER, western_date: Western::Calendar.new,
34
+ remainder: Cycle::AbstractRemainder.new)
35
+ @number = number
36
+ @western_date = western_date
37
+ @remainder = remainder
38
+ end
39
+
40
+ #
41
+ # 不正か
42
+ #
43
+ # @return [True] 不正
44
+ # @return [False] 不正なし
45
+ #
46
+ def invalid?
47
+ number == INVALID_NUMBER
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative './year'
4
4
 
5
- require_relative '../../version/context'
5
+ require_relative '../../context/context'
6
6
 
7
7
  # :nodoc:
8
8
  module Zakuro
@@ -17,11 +17,11 @@ module Zakuro
17
17
  #
18
18
  # 初期化
19
19
  #
20
- # @param [Context] context 暦コンテキスト
20
+ # @param [Context::Context] context 暦コンテキスト
21
21
  # @param [Array<OperatedMonth>] months 年内の全ての月
22
22
  # @param [Integer] total_days 年の日数
23
23
  #
24
- def initialize(context: Context.new, months: [], total_days: 0)
24
+ def initialize(context: Context::Context.new, months: [], total_days: 0)
25
25
  super(context: context, months: months, total_days: total_days)
26
26
  end
27
27
 
@@ -4,7 +4,7 @@ require_relative '../cycle/zodiac'
4
4
 
5
5
  require_relative '../../era/western/calendar'
6
6
 
7
- require_relative '../../version/context'
7
+ require_relative '../../context/context'
8
8
 
9
9
  # :nodoc:
10
10
  module Zakuro
@@ -16,7 +16,7 @@ module Zakuro
16
16
  # Year 年
17
17
  #
18
18
  class Year
19
- # @return [Context] 暦コンテキスト
19
+ # @return [Context::Context] 暦コンテキスト
20
20
  attr_reader :context
21
21
  # @return [Array<Month>] 年内の全ての月
22
22
  attr_reader :months
@@ -26,11 +26,11 @@ module Zakuro
26
26
  #
27
27
  # 初期化
28
28
  #
29
- # @param [Context] context 暦コンテキスト
29
+ # @param [Context::Context] context 暦コンテキスト
30
30
  # @param [Array<Month>] months 年内の全ての月
31
31
  # @param [Integer] total_days 年の日数
32
32
  #
33
- def initialize(context: Context.new, months: [], total_days: 0)
33
+ def initialize(context: Context::Context.new, months: [], total_days: 0)
34
34
  @context = context
35
35
  @months = months
36
36
  @total_days = total_days
@@ -43,16 +43,16 @@ module Zakuro
43
43
  # 初期化
44
44
  #
45
45
  # @param [Integer] base_day 1大余に必要な小余(暦によって基数が異なる)
46
- # @param [Integer] base_mitune 1小余に必要な秒(暦によって基数が異なる)
46
+ # @param [Integer] base_minute 1小余に必要な秒(暦によって基数が異なる)
47
47
  # @param [Integer] day 大余("日"に相当)
48
48
  # @param [Integer] minute 小余("分"に相当)
49
49
  # @param [Integer] second 秒
50
50
  # @param [Integer] total 繰り上げなしの小余
51
51
  #
52
- def initialize(base_day: -1, base_mitune: -1, day: -1, minute: -1, second: -1, total: -1)
52
+ def initialize(base_day: -1, base_minute: -1, day: -1, minute: -1, second: -1, total: -1)
53
53
  @base_limit = LIMIT
54
54
  @base_day = base_day
55
- @base_minute = base_mitune
55
+ @base_minute = base_minute
56
56
  @limited = true
57
57
 
58
58
  set(day: day, minute: minute, second: second, total: total)
@@ -113,6 +113,8 @@ module Zakuro
113
113
  # @return [True] 無効
114
114
  # @return [False] 有効
115
115
  #
116
+ # @raise [ArgumentError] 引数エラー
117
+ #
116
118
  def invalid?(param: self)
117
119
  raise ArgumentError, 'unmatch parameter type' unless param.is_a?(AbstractRemainder)
118
120
 
@@ -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
@@ -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 月初日(朔日)
@@ -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