decentworks-date-support 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -3
  3. data/LICENSE +1 -1
  4. data/README.md +268 -24
  5. data/lib/decentworks/date_support/configuration.rb +73 -0
  6. data/lib/decentworks/date_support/date.rb +9 -0
  7. data/lib/decentworks/date_support/date_extension.rb +761 -0
  8. data/lib/decentworks/date_support/date_time.rb +9 -0
  9. data/lib/decentworks/date_support/time.rb +7 -0
  10. data/lib/decentworks/date_support/time_extension.rb +742 -0
  11. data/lib/decentworks/date_support/time_with_zone.rb +12 -0
  12. data/lib/decentworks/date_support/version.rb +7 -0
  13. data/lib/decentworks/date_support.rb +8 -321
  14. data/lib/decentworks-date-support.rb +3 -0
  15. data/lib/generators/decentworks/date_support/install/install_generator.rb +26 -0
  16. data/lib/generators/decentworks/date_support/install/templates/decentworks_date_support.rb.tt +50 -0
  17. data/sig/decentworks/date_support/configuration.rbs +25 -0
  18. data/sig/decentworks/date_support/date.rbs +4 -0
  19. data/sig/decentworks/date_support/date_extension.rbs +244 -0
  20. data/sig/decentworks/date_support/date_time.rbs +4 -0
  21. data/sig/decentworks/date_support/time.rbs +4 -0
  22. data/sig/decentworks/date_support/time_extension.rbs +248 -0
  23. data/sig/decentworks/date_support/time_with_zone.rbs +21 -0
  24. data/sig/decentworks/date_support/version.rbs +5 -0
  25. metadata +27 -143
  26. data/.gem_rbs_collection/actionpack/7.2/.rbs_meta.yaml +0 -9
  27. data/.gem_rbs_collection/actionpack/7.2/actioncontroller-7.2.rbs +0 -14
  28. data/.gem_rbs_collection/actionpack/7.2/actioncontroller.rbs +0 -290
  29. data/.gem_rbs_collection/actionpack/7.2/actiondispatch.rbs +0 -349
  30. data/.gem_rbs_collection/actionpack/7.2/actionpack-generated.rbs +0 -11497
  31. data/.gem_rbs_collection/actionpack/7.2/patch.rbs +0 -77
  32. data/.gem_rbs_collection/actionview/6.0/.rbs_meta.yaml +0 -9
  33. data/.gem_rbs_collection/actionview/6.0/actionview-generated.rbs +0 -8976
  34. data/.gem_rbs_collection/actionview/6.0/actionview.rbs +0 -1940
  35. data/.gem_rbs_collection/actionview/6.0/patch.rbs +0 -57
  36. data/.gem_rbs_collection/activesupport/7.0/.rbs_meta.yaml +0 -9
  37. data/.gem_rbs_collection/activesupport/7.0/activesupport-7.0.rbs +0 -381
  38. data/.gem_rbs_collection/activesupport/7.0/activesupport-generated.rbs +0 -11633
  39. data/.gem_rbs_collection/activesupport/7.0/activesupport.rbs +0 -724
  40. data/.gem_rbs_collection/activesupport/7.0/manifest.yaml +0 -15
  41. data/.gem_rbs_collection/activesupport/7.0/patch.rbs +0 -55
  42. data/.gem_rbs_collection/ast/2.4/.rbs_meta.yaml +0 -9
  43. data/.gem_rbs_collection/ast/2.4/ast.rbs +0 -73
  44. data/.gem_rbs_collection/cgi/0.5/.rbs_meta.yaml +0 -9
  45. data/.gem_rbs_collection/cgi/0.5/core.rbs +0 -925
  46. data/.gem_rbs_collection/cgi/0.5/manifest.yaml +0 -3
  47. data/.gem_rbs_collection/concurrent-ruby/1.1/.rbs_meta.yaml +0 -9
  48. data/.gem_rbs_collection/concurrent-ruby/1.1/array.rbs +0 -4
  49. data/.gem_rbs_collection/concurrent-ruby/1.1/atomic_reference.rbs +0 -16
  50. data/.gem_rbs_collection/concurrent-ruby/1.1/executor.rbs +0 -96
  51. data/.gem_rbs_collection/concurrent-ruby/1.1/hash.rbs +0 -4
  52. data/.gem_rbs_collection/concurrent-ruby/1.1/map.rbs +0 -68
  53. data/.gem_rbs_collection/concurrent-ruby/1.1/promises.rbs +0 -249
  54. data/.gem_rbs_collection/concurrent-ruby/1.1/set.rbs +0 -4
  55. data/.gem_rbs_collection/concurrent-ruby/1.1/timer_task.rbs +0 -47
  56. data/.gem_rbs_collection/concurrent-ruby/1.1/utility/processor_counter.rbs +0 -5
  57. data/.gem_rbs_collection/connection_pool/2.4/.rbs_meta.yaml +0 -9
  58. data/.gem_rbs_collection/connection_pool/2.4/connection_pool.rbs +0 -34
  59. data/.gem_rbs_collection/connection_pool/2.4/manifest.yaml +0 -2
  60. data/.gem_rbs_collection/diff-lcs/1.5/.rbs_meta.yaml +0 -9
  61. data/.gem_rbs_collection/diff-lcs/1.5/diff-lcs.rbs +0 -11
  62. data/.gem_rbs_collection/faker/3.4.2/.rbs_meta.yaml +0 -9
  63. data/.gem_rbs_collection/faker/3.4.2/faker-2.23.rbs +0 -90
  64. data/.gem_rbs_collection/faker/3.4.2/faker.rbs +0 -18
  65. data/.gem_rbs_collection/i18n/1.10/.rbs_meta.yaml +0 -9
  66. data/.gem_rbs_collection/i18n/1.10/backend.rbs +0 -274
  67. data/.gem_rbs_collection/i18n/1.10/i18n.rbs +0 -116
  68. data/.gem_rbs_collection/lint_roller/1.1/.rbs_meta.yaml +0 -9
  69. data/.gem_rbs_collection/lint_roller/1.1/lint_roller.rbs +0 -48
  70. data/.gem_rbs_collection/minitest/5.25/.rbs_meta.yaml +0 -9
  71. data/.gem_rbs_collection/minitest/5.25/minitest/abstract_reporter.rbs +0 -52
  72. data/.gem_rbs_collection/minitest/5.25/minitest/assertion.rbs +0 -17
  73. data/.gem_rbs_collection/minitest/5.25/minitest/assertions.rbs +0 -590
  74. data/.gem_rbs_collection/minitest/5.25/minitest/backtrace_filter.rbs +0 -23
  75. data/.gem_rbs_collection/minitest/5.25/minitest/bench_spec.rbs +0 -102
  76. data/.gem_rbs_collection/minitest/5.25/minitest/benchmark.rbs +0 -259
  77. data/.gem_rbs_collection/minitest/5.25/minitest/composite_reporter.rbs +0 -25
  78. data/.gem_rbs_collection/minitest/5.25/minitest/compress.rbs +0 -13
  79. data/.gem_rbs_collection/minitest/5.25/minitest/error_on_warning.rbs +0 -3
  80. data/.gem_rbs_collection/minitest/5.25/minitest/expectation.rbs +0 -2
  81. data/.gem_rbs_collection/minitest/5.25/minitest/expectations.rbs +0 -21
  82. data/.gem_rbs_collection/minitest/5.25/minitest/guard.rbs +0 -64
  83. data/.gem_rbs_collection/minitest/5.25/minitest/mock.rbs +0 -64
  84. data/.gem_rbs_collection/minitest/5.25/minitest/parallel/executor.rbs +0 -46
  85. data/.gem_rbs_collection/minitest/5.25/minitest/parallel/test/class_methods.rbs +0 -5
  86. data/.gem_rbs_collection/minitest/5.25/minitest/parallel/test.rbs +0 -3
  87. data/.gem_rbs_collection/minitest/5.25/minitest/parallel.rbs +0 -2
  88. data/.gem_rbs_collection/minitest/5.25/minitest/pride_io.rbs +0 -62
  89. data/.gem_rbs_collection/minitest/5.25/minitest/pride_lol.rbs +0 -19
  90. data/.gem_rbs_collection/minitest/5.25/minitest/progress_reporter.rbs +0 -11
  91. data/.gem_rbs_collection/minitest/5.25/minitest/reportable.rbs +0 -53
  92. data/.gem_rbs_collection/minitest/5.25/minitest/reporter.rbs +0 -5
  93. data/.gem_rbs_collection/minitest/5.25/minitest/result.rbs +0 -28
  94. data/.gem_rbs_collection/minitest/5.25/minitest/runnable.rbs +0 -163
  95. data/.gem_rbs_collection/minitest/5.25/minitest/skip.rbs +0 -6
  96. data/.gem_rbs_collection/minitest/5.25/minitest/spec/dsl/instance_methods.rbs +0 -48
  97. data/.gem_rbs_collection/minitest/5.25/minitest/spec/dsl.rbs +0 -129
  98. data/.gem_rbs_collection/minitest/5.25/minitest/spec.rbs +0 -11
  99. data/.gem_rbs_collection/minitest/5.25/minitest/statistics_reporter.rbs +0 -81
  100. data/.gem_rbs_collection/minitest/5.25/minitest/summary_reporter.rbs +0 -18
  101. data/.gem_rbs_collection/minitest/5.25/minitest/test/lifecycle_hooks.rbs +0 -92
  102. data/.gem_rbs_collection/minitest/5.25/minitest/test.rbs +0 -69
  103. data/.gem_rbs_collection/minitest/5.25/minitest/unexpected_error.rbs +0 -12
  104. data/.gem_rbs_collection/minitest/5.25/minitest/unexpected_warning.rbs +0 -6
  105. data/.gem_rbs_collection/minitest/5.25/minitest/unit/test_case.rbs +0 -3
  106. data/.gem_rbs_collection/minitest/5.25/minitest/unit.rbs +0 -4
  107. data/.gem_rbs_collection/minitest/5.25/minitest.rbs +0 -115
  108. data/.gem_rbs_collection/nokogiri/1.11/.rbs_meta.yaml +0 -9
  109. data/.gem_rbs_collection/nokogiri/1.11/nokogiri.rbs +0 -2332
  110. data/.gem_rbs_collection/nokogiri/1.11/patch.rbs +0 -4
  111. data/.gem_rbs_collection/parallel/1.20/.rbs_meta.yaml +0 -9
  112. data/.gem_rbs_collection/parallel/1.20/parallel.rbs +0 -86
  113. data/.gem_rbs_collection/parser/3.2/.rbs_meta.yaml +0 -9
  114. data/.gem_rbs_collection/parser/3.2/manifest.yaml +0 -7
  115. data/.gem_rbs_collection/parser/3.2/parser.rbs +0 -194
  116. data/.gem_rbs_collection/parser/3.2/polyfill.rbs +0 -4
  117. data/.gem_rbs_collection/rack/2.2/.rbs_meta.yaml +0 -9
  118. data/.gem_rbs_collection/rack/2.2/manifest.yaml +0 -3
  119. data/.gem_rbs_collection/rack/2.2/rack.rbs +0 -1480
  120. data/.gem_rbs_collection/rails-dom-testing/2.0/.rbs_meta.yaml +0 -9
  121. data/.gem_rbs_collection/rails-dom-testing/2.0/rails-dom-testing.rbs +0 -51
  122. data/.gem_rbs_collection/rails-html-sanitizer/1.6/.rbs_meta.yaml +0 -9
  123. data/.gem_rbs_collection/rails-html-sanitizer/1.6/rails-html-sanitizer.rbs +0 -53
  124. data/.gem_rbs_collection/railties/6.0/.rbs_meta.yaml +0 -9
  125. data/.gem_rbs_collection/railties/6.0/manifest.yaml +0 -2
  126. data/.gem_rbs_collection/railties/6.0/patch.rbs +0 -17
  127. data/.gem_rbs_collection/railties/6.0/railties-generated.rbs +0 -4822
  128. data/.gem_rbs_collection/railties/6.0/railties.rbs +0 -44
  129. data/.gem_rbs_collection/rainbow/3.0/.rbs_meta.yaml +0 -9
  130. data/.gem_rbs_collection/rainbow/3.0/global.rbs +0 -7
  131. data/.gem_rbs_collection/rainbow/3.0/presenter.rbs +0 -209
  132. data/.gem_rbs_collection/rainbow/3.0/rainbow.rbs +0 -5
  133. data/.gem_rbs_collection/rake/13.0/.rbs_meta.yaml +0 -9
  134. data/.gem_rbs_collection/rake/13.0/manifest.yaml +0 -2
  135. data/.gem_rbs_collection/rake/13.0/rake.rbs +0 -39
  136. data/.gem_rbs_collection/regexp_parser/2.8/.rbs_meta.yaml +0 -9
  137. data/.gem_rbs_collection/regexp_parser/2.8/regexp_parser.rbs +0 -17
  138. data/.gem_rbs_collection/rubocop/1.57/.rbs_meta.yaml +0 -9
  139. data/.gem_rbs_collection/rubocop/1.57/rubocop.rbs +0 -208
  140. data/.gem_rbs_collection/rubocop-ast/1.46/.rbs_meta.yaml +0 -9
  141. data/.gem_rbs_collection/rubocop-ast/1.46/rubocop-ast.rbs +0 -903
  142. data/.gem_rbs_collection/thor/1.2/.rbs_meta.yaml +0 -9
  143. data/.gem_rbs_collection/thor/1.2/thor.rbs +0 -62
  144. data/.gem_rbs_collection/tzinfo/2.0/.rbs_meta.yaml +0 -9
  145. data/.gem_rbs_collection/tzinfo/2.0/manifest.yaml +0 -7
  146. data/.gem_rbs_collection/tzinfo/2.0/tzinfo.rbs +0 -600
  147. data/.rspec +0 -3
  148. data/.rubocop.yml +0 -8
  149. data/.ruby-version +0 -1
  150. data/CODE_OF_CONDUCT.md +0 -132
  151. data/LICENSE.txt +0 -21
  152. data/Rakefile +0 -12
  153. data/Steepfile +0 -43
  154. data/lib/decentworks/active_support/time_with_zone_support.rb +0 -327
  155. data/lib/decentworks/date/support/version.rb +0 -9
  156. data/lib/decentworks_date_support.rb +0 -4
  157. data/rbs_collection.lock.yaml +0 -288
  158. data/rbs_collection.yaml +0 -41
  159. data/sig/decentworks/active_support/time_with_zone_support.rbs +0 -109
  160. data/sig/decentworks/date/support.rbs +0 -8
  161. data/sig/decentworks/date_support.rbs +0 -107
@@ -0,0 +1,742 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date" # ::Date
4
+ require "active_support"
5
+ require "active_support/time" # レシーバに対する change / months_ago / all_day などの拡張
6
+
7
+ require_relative "date" # ::Date.whole_months_elapsed を利用するため
8
+ require_relative "configuration" # ::Decentworks::DateSupport.first_quarter_month_offset を利用するため
9
+
10
+ module Decentworks
11
+ module DateSupport
12
+ # ::Time / ::DateTime / ::ActiveSupport::TimeWithZone に共通の日時拡張
13
+ #
14
+ # 各メソッドはレシーバと同じクラスの値を返す。
15
+ #
16
+ # sigではgeneric module(TimeExtension[T])として宣言し、戻り値を型引数Tで表している。
17
+ # includeする側で TimeExtension[::Time] のように具体的なクラスを渡す。
18
+ module TimeExtension
19
+ # includeしたクラスにクラスメソッドを追加する
20
+ def self.included(base) = base.extend(ClassMethods)
21
+
22
+ module ClassMethods
23
+ # #############################################################################################################
24
+ # 満経過月数
25
+ # #############################################################################################################
26
+
27
+ # 満経過月数
28
+ #
29
+ # fromからtoまでに満了した月数を返す。日付単位で判定し、時刻は考慮しない。
30
+ # 応当日が存在しない月は、民法第143条第2項に準じてその月の末日を応当日とみなす。
31
+ #
32
+ # @raise [ArgumentError] toの日付がfromの日付より前の場合
33
+ def whole_months_elapsed(from:, to:)
34
+ ::Date.whole_months_elapsed(
35
+ from: from.to_date,
36
+ to: to.to_date
37
+ )
38
+ end
39
+ end
40
+
41
+ # ###############################################################################################################
42
+ # 週関係
43
+ # ###############################################################################################################
44
+
45
+ #
46
+ # 今週
47
+ #
48
+
49
+ # 現在の日付が属する週の始まりの日付
50
+ def beginning_of_this_week = beginning_of_week(::Date.beginning_of_week).beginning_of_day
51
+
52
+ # 現在の日付が属する週の終わりの日付
53
+ def end_of_this_week = beginning_of_this_week.advance(days: 6).end_of_day
54
+
55
+ # 今週の期間
56
+ def all_this_week = ::Range.new(beginning_of_this_week, end_of_this_week)
57
+
58
+ # ###############################################################################################################
59
+ # 月関係
60
+ # ###############################################################################################################
61
+
62
+ #
63
+ # 今月関係
64
+ #
65
+
66
+ # 現在の日付が属する月の始まりの日時
67
+ def beginning_of_this_month = beginning_of_month
68
+
69
+ # 現在の日付が属する月の終わりの日時
70
+ def end_of_this_month = end_of_month
71
+
72
+ # 現在の日付が属する月の期間
73
+ def all_this_month = ::Range.new(beginning_of_this_month, end_of_this_month)
74
+
75
+ #
76
+ # Nヶ月前関係
77
+ #
78
+
79
+ # 2ヶ月前の日付
80
+ def two_months_ago = months_ago(2)
81
+
82
+ # 3ヶ月前の日付
83
+ def three_months_ago = months_ago(3)
84
+
85
+ # 4ヶ月前の日付
86
+ def four_months_ago = months_ago(4)
87
+
88
+ # 5ヶ月前の日付
89
+ def five_months_ago = months_ago(5)
90
+
91
+ # 6ヶ月前の日付
92
+ def six_months_ago = months_ago(6)
93
+
94
+ # 半年前の日付
95
+ def half_year_ago = six_months_ago
96
+
97
+ # 7ヶ月前の日付
98
+ def seven_months_ago = months_ago(7)
99
+
100
+ # 8ヶ月前の日付
101
+ def eight_months_ago = months_ago(8)
102
+
103
+ # 9ヶ月前の日付
104
+ def nine_months_ago = months_ago(9)
105
+
106
+ # 10ヶ月前の日付
107
+ def ten_months_ago = months_ago(10)
108
+
109
+ # 11ヶ月前の日付
110
+ def eleven_months_ago = months_ago(11)
111
+
112
+ #
113
+ # Nヶ月後関係
114
+ #
115
+
116
+ # 2ヶ月後の日付
117
+ def two_months_since = months_since(2)
118
+
119
+ # 3ヶ月後の日付
120
+ def three_months_since = months_since(3)
121
+
122
+ # 4ヶ月後の日付
123
+ def four_months_since = months_since(4)
124
+
125
+ # 5ヶ月後の日付
126
+ def five_months_since = months_since(5)
127
+
128
+ # 6ヶ月後の日付
129
+ def six_months_since = months_since(6)
130
+
131
+ # 半年後の日付
132
+ def half_year_since = six_months_since
133
+
134
+ # 7ヶ月後の日付
135
+ def seven_months_since = months_since(7)
136
+
137
+ # 8ヶ月後の日付
138
+ def eight_months_since = months_since(8)
139
+
140
+ # 9ヶ月後の日付
141
+ def nine_months_since = months_since(9)
142
+
143
+ # 10ヶ月後の日付
144
+ def ten_months_since = months_since(10)
145
+
146
+ # 11ヶ月後の日付
147
+ def eleven_months_since = months_since(11)
148
+
149
+ #
150
+ # 暦月関係
151
+ #
152
+
153
+ #
154
+ # 1月
155
+ #
156
+
157
+ # 1月の月初
158
+ def beginning_of_january = change(month: 1, day: 1).beginning_of_day
159
+
160
+ # 1月の月末
161
+ def end_of_january = beginning_of_january.end_of_month.end_of_day
162
+
163
+ # 1月の期間
164
+ def all_january = ::Range.new(beginning_of_january, end_of_january)
165
+
166
+ # 1月の月初か?
167
+ def beginning_of_january? = beginning_of_january.all_day.cover?(self)
168
+
169
+ # 1月の月末か?
170
+ def end_of_january? = end_of_january.all_day.cover?(self)
171
+
172
+ # 1月か?
173
+ def in_january? = all_january.cover?(self)
174
+
175
+ #
176
+ # 2月
177
+ #
178
+
179
+ # 2月の月初
180
+ def beginning_of_february = change(month: 2, day: 1).beginning_of_day
181
+
182
+ # 2月の月末
183
+ def end_of_february = beginning_of_february.end_of_month.end_of_day
184
+
185
+ # 2月の期間
186
+ def all_february = ::Range.new(beginning_of_february, end_of_february)
187
+
188
+ # 2月の月初か?
189
+ def beginning_of_february? = beginning_of_february.all_day.cover?(self)
190
+
191
+ # 2月の月末か?
192
+ def end_of_february? = end_of_february.all_day.cover?(self)
193
+
194
+ # 2月か?
195
+ def in_february? = all_february.cover?(self)
196
+
197
+ #
198
+ # 3月
199
+ #
200
+
201
+ # 3月の月初
202
+ def beginning_of_march = change(month: 3, day: 1).beginning_of_day
203
+
204
+ # 3月の月末
205
+ def end_of_march = beginning_of_march.end_of_month.end_of_day
206
+
207
+ # 3月の期間
208
+ def all_march = ::Range.new(beginning_of_march, end_of_march)
209
+
210
+ # 3月の月初か?
211
+ def beginning_of_march? = beginning_of_march.all_day.cover?(self)
212
+
213
+ # 3月の月末か?
214
+ def end_of_march? = end_of_march.all_day.cover?(self)
215
+
216
+ # 3月か?
217
+ def in_march? = all_march.cover?(self)
218
+
219
+ #
220
+ # 4月
221
+ #
222
+
223
+ # 4月の月初
224
+ def beginning_of_april = change(month: 4, day: 1).beginning_of_day
225
+
226
+ # 4月の月末
227
+ def end_of_april = beginning_of_april.end_of_month.end_of_day
228
+
229
+ # 4月の期間
230
+ def all_april = ::Range.new(beginning_of_april, end_of_april)
231
+
232
+ # 4月の月初か?
233
+ def beginning_of_april? = beginning_of_april.all_day.cover?(self)
234
+
235
+ # 4月の月末か?
236
+ def end_of_april? = end_of_april.all_day.cover?(self)
237
+
238
+ # 4月か?
239
+ def in_april? = all_april.cover?(self)
240
+
241
+ #
242
+ # 5月
243
+ #
244
+
245
+ # 5月の月初
246
+ def beginning_of_may = change(month: 5, day: 1).beginning_of_day
247
+
248
+ # 5月の月末
249
+ def end_of_may = beginning_of_may.end_of_month.end_of_day
250
+
251
+ # 5月の期間
252
+ def all_may = ::Range.new(beginning_of_may, end_of_may)
253
+
254
+ # 5月の月初か?
255
+ def beginning_of_may? = beginning_of_may.all_day.cover?(self)
256
+
257
+ # 5月の月末か?
258
+ def end_of_may? = end_of_may.all_day.cover?(self)
259
+
260
+ # 5月か?
261
+ def in_may? = all_may.cover?(self)
262
+
263
+ #
264
+ # 6月
265
+ #
266
+
267
+ # 6月の月初
268
+ def beginning_of_june = change(month: 6, day: 1).beginning_of_day
269
+
270
+ # 6月の月末
271
+ def end_of_june = beginning_of_june.end_of_month.end_of_day
272
+
273
+ # 6月の期間
274
+ def all_june = ::Range.new(beginning_of_june, end_of_june)
275
+
276
+ # 6月の月初か?
277
+ def beginning_of_june? = beginning_of_june.all_day.cover?(self)
278
+
279
+ # 6月の月末か?
280
+ def end_of_june? = end_of_june.all_day.cover?(self)
281
+
282
+ # 6月か?
283
+ def in_june? = all_june.cover?(self)
284
+
285
+ #
286
+ # 7月
287
+ #
288
+
289
+ # 7月の月初
290
+ def beginning_of_july = change(month: 7, day: 1).beginning_of_day
291
+
292
+ # 7月の月末
293
+ def end_of_july = beginning_of_july.end_of_month.end_of_day
294
+
295
+ # 7月の期間
296
+ def all_july = ::Range.new(beginning_of_july, end_of_july)
297
+
298
+ # 7月の月初か?
299
+ def beginning_of_july? = beginning_of_july.all_day.cover?(self)
300
+
301
+ # 7月の月末か?
302
+ def end_of_july? = end_of_july.all_day.cover?(self)
303
+
304
+ # 7月か?
305
+ def in_july? = all_july.cover?(self)
306
+
307
+ #
308
+ # 8月
309
+ #
310
+
311
+ # 8月の月初
312
+ def beginning_of_august = change(month: 8, day: 1).beginning_of_day
313
+
314
+ # 8月の月末
315
+ def end_of_august = beginning_of_august.end_of_month.end_of_day
316
+
317
+ # 8月の期間
318
+ def all_august = ::Range.new(beginning_of_august, end_of_august)
319
+
320
+ # 8月の月初か?
321
+ def beginning_of_august? = beginning_of_august.all_day.cover?(self)
322
+
323
+ # 8月の月末か?
324
+ def end_of_august? = end_of_august.all_day.cover?(self)
325
+
326
+ # 8月か?
327
+ def in_august? = all_august.cover?(self)
328
+
329
+ #
330
+ # 9月
331
+ #
332
+
333
+ # 9月の月初
334
+ def beginning_of_september = change(month: 9, day: 1).beginning_of_day
335
+
336
+ # 9月の月末
337
+ def end_of_september = beginning_of_september.end_of_month.end_of_day
338
+
339
+ # 9月の期間
340
+ def all_september = ::Range.new(beginning_of_september, end_of_september)
341
+
342
+ # 9月の月初か?
343
+ def beginning_of_september? = beginning_of_september.all_day.cover?(self)
344
+
345
+ # 9月の月末か?
346
+ def end_of_september? = end_of_september.all_day.cover?(self)
347
+
348
+ # 9月か?
349
+ def in_september? = all_september.cover?(self)
350
+
351
+ #
352
+ # 10月
353
+ #
354
+
355
+ # 10月の月初
356
+ def beginning_of_october = change(month: 10, day: 1).beginning_of_day
357
+
358
+ # 10月の月末
359
+ def end_of_october = beginning_of_october.end_of_month.end_of_day
360
+
361
+ # 10月の期間
362
+ def all_october = ::Range.new(beginning_of_october, end_of_october)
363
+
364
+ # 10月の月初か?
365
+ def beginning_of_october? = beginning_of_october.all_day.cover?(self)
366
+
367
+ # 10月の月末か?
368
+ def end_of_october? = end_of_october.all_day.cover?(self)
369
+
370
+ # 10月か?
371
+ def in_october? = all_october.cover?(self)
372
+
373
+ #
374
+ # 11月
375
+ #
376
+
377
+ # 11月の月初
378
+ def beginning_of_november = change(month: 11, day: 1).beginning_of_day
379
+
380
+ # 11月の月末
381
+ def end_of_november = beginning_of_november.end_of_month.end_of_day
382
+
383
+ # 11月の期間
384
+ def all_november = ::Range.new(beginning_of_november, end_of_november)
385
+
386
+ # 11月の月初か?
387
+ def beginning_of_november? = beginning_of_november.all_day.cover?(self)
388
+
389
+ # 11月の月末か?
390
+ def end_of_november? = end_of_november.all_day.cover?(self)
391
+
392
+ # 11月か?
393
+ def in_november? = all_november.cover?(self)
394
+
395
+ #
396
+ # 12月
397
+ #
398
+
399
+ # 12月の月初
400
+ def beginning_of_december = change(month: 12, day: 1).beginning_of_day
401
+
402
+ # 12月の月末
403
+ def end_of_december = beginning_of_december.end_of_month.end_of_day
404
+
405
+ # 12月の期間
406
+ def all_december = ::Range.new(beginning_of_december, end_of_december)
407
+
408
+ # 12月の月初か?
409
+ def beginning_of_december? = beginning_of_december.all_day.cover?(self)
410
+
411
+ # 12月の月末か?
412
+ def end_of_december? = end_of_december.all_day.cover?(self)
413
+
414
+ # 12月か?
415
+ def in_december? = all_december.cover?(self)
416
+
417
+ # ###############################################################################################################
418
+ # 四半期関係
419
+ # ###############################################################################################################
420
+
421
+ #
422
+ # 今四半期
423
+ #
424
+
425
+ # 現在の日付が属する四半期の番号(1〜4)
426
+ def this_quarter_number
427
+ (((month - ::Decentworks::DateSupport.first_quarter_month) % 12) / 3) + 1
428
+ end
429
+
430
+ # 現在の日付が属する四半期の期首
431
+ def beginning_of_this_quarter
432
+ beginning_of_first_quarter.months_since((this_quarter_number - 1) * 3).beginning_of_day
433
+ end
434
+
435
+ # 現在の日付が属する四半期の期末
436
+ def end_of_this_quarter = beginning_of_this_quarter.two_months_since.end_of_month.end_of_day
437
+
438
+ # 現在の日付が属する四半期の期間
439
+ def all_this_quarter = ::Range.new(beginning_of_this_quarter, end_of_this_quarter)
440
+
441
+ #
442
+ # 次の四半期
443
+ #
444
+
445
+ # 次の四半期の期首
446
+ def beginning_of_next_quarter = beginning_of_this_quarter.three_months_since.beginning_of_day
447
+
448
+ # 次の四半期の期末
449
+ def end_of_next_quarter = beginning_of_next_quarter.two_months_since.end_of_month.end_of_day
450
+
451
+ # 次の四半期の期間
452
+ def all_next_quarter = ::Range.new(beginning_of_next_quarter, end_of_next_quarter)
453
+
454
+ #
455
+ # 前の四半期
456
+ #
457
+
458
+ # 前の四半期の期首
459
+ def beginning_of_prev_quarter = beginning_of_this_quarter.three_months_ago.beginning_of_day
460
+
461
+ # 前の四半期の期末
462
+ def end_of_prev_quarter = beginning_of_prev_quarter.two_months_since.end_of_month.end_of_day
463
+
464
+ # 前の四半期の期間
465
+ def all_prev_quarter = ::Range.new(beginning_of_prev_quarter, end_of_prev_quarter)
466
+
467
+ #
468
+ # 第1四半期
469
+ #
470
+
471
+ # 第1四半期の期首
472
+ def beginning_of_first_quarter
473
+ # 1月始まりと見た時の対応した日付に移動してから開始月に合わせる
474
+ beginning_of_month
475
+ .months_ago(::Decentworks::DateSupport.first_quarter_month_offset)
476
+ .change(month: ::Decentworks::DateSupport.first_quarter_month, day: 1)
477
+ .beginning_of_day
478
+ end
479
+
480
+ # 第1四半期の期末
481
+ def end_of_first_quarter = beginning_of_first_quarter.two_months_since.end_of_month.end_of_day
482
+
483
+ # 第1四半期の期間
484
+ def all_first_quarter = ::Range.new(beginning_of_first_quarter, end_of_first_quarter)
485
+
486
+ # 第1四半期の期首か?
487
+ def beginning_of_first_quarter? = beginning_of_first_quarter.all_day.cover?(self)
488
+
489
+ # 第1四半期の期末か?
490
+ def end_of_first_quarter? = end_of_first_quarter.all_day.cover?(self)
491
+
492
+ # 第1四半期か?
493
+ def in_first_quarter? = all_first_quarter.cover?(self)
494
+
495
+ #
496
+ # 第2四半期
497
+ #
498
+
499
+ # 第2四半期の期首
500
+ def beginning_of_second_quarter = beginning_of_first_quarter.three_months_since.beginning_of_day
501
+
502
+ # 第2四半期の期末
503
+ def end_of_second_quarter = beginning_of_second_quarter.two_months_since.end_of_month.end_of_day
504
+
505
+ # 第2四半期の期間
506
+ def all_second_quarter = ::Range.new(beginning_of_second_quarter, end_of_second_quarter)
507
+
508
+ # 第2四半期の期首か?
509
+ def beginning_of_second_quarter? = beginning_of_second_quarter.all_day.cover?(self)
510
+
511
+ # 第2四半期の期末か?
512
+ def end_of_second_quarter? = end_of_second_quarter.all_day.cover?(self)
513
+
514
+ # 第2四半期か?
515
+ def in_second_quarter? = all_second_quarter.cover?(self)
516
+
517
+ #
518
+ # 第3四半期
519
+ #
520
+
521
+ # 第3四半期の期首
522
+ def beginning_of_third_quarter = beginning_of_first_quarter.six_months_since.beginning_of_day
523
+
524
+ # 第3四半期の期末
525
+ def end_of_third_quarter = beginning_of_third_quarter.two_months_since.end_of_month.end_of_day
526
+
527
+ # 第3四半期の期間
528
+ def all_third_quarter = ::Range.new(beginning_of_third_quarter, end_of_third_quarter)
529
+
530
+ # 第3四半期の期首か?
531
+ def beginning_of_third_quarter? = beginning_of_third_quarter.all_day.cover?(self)
532
+
533
+ # 第3四半期の期末か?
534
+ def end_of_third_quarter? = end_of_third_quarter.all_day.cover?(self)
535
+
536
+ # 第3四半期か?
537
+ def in_third_quarter? = all_third_quarter.cover?(self)
538
+
539
+ #
540
+ # 第4四半期
541
+ #
542
+
543
+ # 第4四半期の期首
544
+ def beginning_of_fourth_quarter = beginning_of_first_quarter.nine_months_since.beginning_of_day
545
+
546
+ # 第4四半期の期末
547
+ def end_of_fourth_quarter = beginning_of_fourth_quarter.two_months_since.end_of_month.end_of_day
548
+
549
+ # 第4四半期の期間
550
+ def all_fourth_quarter = ::Range.new(beginning_of_fourth_quarter, end_of_fourth_quarter)
551
+
552
+ # 第4四半期の期首か?
553
+ def beginning_of_fourth_quarter? = beginning_of_fourth_quarter.all_day.cover?(self)
554
+
555
+ # 第4四半期の期末か?
556
+ def end_of_fourth_quarter? = end_of_fourth_quarter.all_day.cover?(self)
557
+
558
+ # 第4四半期か?
559
+ def in_fourth_quarter? = all_fourth_quarter.cover?(self)
560
+
561
+ # ###############################################################################################################
562
+ # 上下期関係
563
+ # ###############################################################################################################
564
+
565
+ #
566
+ # 今期
567
+ #
568
+
569
+ # 現在の日付が属する期の番号(1〜2)
570
+ def this_half_number = this_quarter_number <= 2 ? 1 : 2
571
+
572
+ # 現在の日付が属する期の期首
573
+ def beginning_of_this_half = this_half_number == 1 ? beginning_of_first_half : beginning_of_second_half
574
+
575
+ # 現在の日付が属する期の期末
576
+ def end_of_this_half = this_half_number == 1 ? end_of_first_half : end_of_second_half
577
+
578
+ # 現在の日付が属する期の期間
579
+ def all_this_half = ::Range.new(beginning_of_this_half, end_of_this_half)
580
+
581
+ #
582
+ # 次の期
583
+ #
584
+
585
+ # 次の期の期首
586
+ def beginning_of_next_half = beginning_of_this_half.six_months_since.beginning_of_day
587
+
588
+ # 次の期の期末
589
+ def end_of_next_half = beginning_of_next_half.five_months_since.end_of_month.end_of_day
590
+
591
+ # 次の期の期間
592
+ def all_next_half = ::Range.new(beginning_of_next_half, end_of_next_half)
593
+
594
+ #
595
+ # 前の期
596
+ #
597
+
598
+ # 前の期の期首
599
+ def beginning_of_prev_half = beginning_of_this_half.six_months_ago.beginning_of_day
600
+
601
+ # 前の期の期末
602
+ def end_of_prev_half = beginning_of_prev_half.five_months_since.end_of_month.end_of_day
603
+
604
+ # 前の期の期間
605
+ def all_prev_half = ::Range.new(beginning_of_prev_half, end_of_prev_half)
606
+
607
+ #
608
+ # 上期
609
+ #
610
+
611
+ # 上期の期首
612
+ def beginning_of_first_half = beginning_of_first_quarter
613
+
614
+ # 上期の期末
615
+ def end_of_first_half = end_of_second_quarter
616
+
617
+ # 上期の期間
618
+ def all_first_half = ::Range.new(beginning_of_first_half, end_of_first_half)
619
+
620
+ # 上期の期首か?
621
+ def beginning_of_first_half? = beginning_of_first_half.all_day.cover?(self)
622
+
623
+ # 上期の期末か?
624
+ def end_of_first_half? = end_of_first_half.all_day.cover?(self)
625
+
626
+ # 上期か?
627
+ def in_first_half? = all_first_half.cover?(self)
628
+
629
+ #
630
+ # 下期
631
+ #
632
+
633
+ # 下期の期首
634
+ def beginning_of_second_half = beginning_of_third_quarter
635
+
636
+ # 下期の期末
637
+ def end_of_second_half = end_of_fourth_quarter
638
+
639
+ # 下期の期間
640
+ def all_second_half = ::Range.new(beginning_of_second_half, end_of_second_half)
641
+
642
+ # 下期の期首か?
643
+ def beginning_of_second_half? = beginning_of_second_half.all_day.cover?(self)
644
+
645
+ # 下期の期末か?
646
+ def end_of_second_half? = end_of_second_half.all_day.cover?(self)
647
+
648
+ # 下期か?
649
+ def in_second_half? = all_second_half.cover?(self)
650
+
651
+ # ###############################################################################################################
652
+ # 年度関係
653
+ # ###############################################################################################################
654
+
655
+ # 現在の日付が属する年度(期首の年)
656
+ def fiscal_year = beginning_of_fiscal_year.year
657
+
658
+ # 年度の期首
659
+ def beginning_of_fiscal_year = beginning_of_first_quarter
660
+
661
+ # 年度の期末
662
+ def end_of_fiscal_year = end_of_fourth_quarter
663
+
664
+ #
665
+ # 次の年度
666
+ #
667
+
668
+ # 次の年度(期首の年)
669
+ def next_fiscal_year = fiscal_year + 1
670
+
671
+ # 次の年度の期首
672
+ def beginning_of_next_fiscal_year = beginning_of_fiscal_year.months_since(12).beginning_of_day
673
+
674
+ # 次の年度の期末
675
+ def end_of_next_fiscal_year = beginning_of_next_fiscal_year.eleven_months_since.end_of_month.end_of_day
676
+
677
+ # 次の年度の期間
678
+ def all_next_fiscal_year = ::Range.new(beginning_of_next_fiscal_year, end_of_next_fiscal_year)
679
+
680
+ #
681
+ # 前の年度
682
+ #
683
+
684
+ # 前の年度(期首の年)
685
+ def prev_fiscal_year = fiscal_year - 1
686
+
687
+ # 前の年度の期首
688
+ def beginning_of_prev_fiscal_year = beginning_of_fiscal_year.months_ago(12).beginning_of_day
689
+
690
+ # 前の年度の期末
691
+ def end_of_prev_fiscal_year = beginning_of_prev_fiscal_year.eleven_months_since.end_of_month.end_of_day
692
+
693
+ # 前の年度の期間
694
+ def all_prev_fiscal_year = ::Range.new(beginning_of_prev_fiscal_year, end_of_prev_fiscal_year)
695
+
696
+ # 年度の期間
697
+ def all_fiscal_year = ::Range.new(beginning_of_fiscal_year, end_of_fiscal_year)
698
+
699
+ # ###############################################################################################################
700
+ # ActiveSupportのメソッドの上書き
701
+ # ###############################################################################################################
702
+ #
703
+ # ActiveSupportの四半期メソッドは暦年基準(1月・4月・7月・10月始まり固定)であり、
704
+ # first_quarter_month_nameの設定を参照しない。設定を反映した値を返すよう上書きする。
705
+ #
706
+ # ActiveSupportがaliasで定義している別名(at_beginning_of_quarter / at_end_of_quarter /
707
+ # last_quarter)は定義時点の実体を掴むため、本体を上書きしても追従しない。
708
+ # 値が食い違わないよう、別名もメソッド定義で上書きする。
709
+
710
+ # 現在の日付が属する四半期の番号(1〜4)
711
+ def quarter = this_quarter_number
712
+
713
+ # 現在の日付が属する四半期の期首
714
+ def beginning_of_quarter = beginning_of_this_quarter
715
+
716
+ # 現在の日付が属する四半期の期首(beginning_of_quarterの別名)
717
+ def at_beginning_of_quarter = beginning_of_quarter
718
+
719
+ # 現在の日付が属する四半期の期末
720
+ def end_of_quarter = end_of_this_quarter
721
+
722
+ # 現在の日付が属する四半期の期末(end_of_quarterの別名)
723
+ def at_end_of_quarter = end_of_quarter
724
+
725
+ # 現在の日付が属する四半期の期間
726
+ def all_quarter = all_this_quarter
727
+
728
+ # 次の四半期の期首
729
+ #
730
+ # ActiveSupportは3ヶ月後の同日を返すが、期間ベースに揃えて期首を返す。
731
+ def next_quarter = beginning_of_next_quarter
732
+
733
+ # 前の四半期の期首
734
+ #
735
+ # ActiveSupportは3ヶ月前の同日を返すが、期間ベースに揃えて期首を返す。
736
+ def prev_quarter = beginning_of_prev_quarter
737
+
738
+ # 前の四半期の期首(prev_quarterの別名)
739
+ def last_quarter = prev_quarter
740
+ end
741
+ end
742
+ end