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,761 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "active_support"
5
+ require "active_support/time" # レシーバに対する change / months_ago / end_of_month などの拡張
6
+ require_relative "configuration"
7
+
8
+ module Decentworks
9
+ module DateSupport
10
+ # ::Date の日付拡張
11
+ #
12
+ # 各メソッドは ::Date を返す。
13
+ module DateExtension
14
+ # includeしたクラスにクラスメソッドを追加する
15
+ def self.included(base) = base.extend(ClassMethods)
16
+
17
+ module ClassMethods
18
+ # #############################################################################################################
19
+ # 満経過月数
20
+ # #############################################################################################################
21
+
22
+ # 満経過月数
23
+ #
24
+ # fromからtoまでに満了した月数を返す。
25
+ # 民法第140条(初日不算入)に従いfromの翌日を起算日とし、
26
+ # 民法第143条第2項に従い応当日の前日をもって満了とする。
27
+ # 応当日が存在しない月は、同項ただし書に従いその月の末日をもって満了とする。
28
+ #
29
+ # ::Date.whole_months_elapsed(from: ::Date.new(2026, 1, 31), to: ::Date.new(2026, 2, 27)) # => 0
30
+ # ::Date.whole_months_elapsed(from: ::Date.new(2026, 1, 31), to: ::Date.new(2026, 2, 28)) # => 1
31
+ # ::Date.whole_months_elapsed(from: ::Date.new(2026, 2, 28), to: ::Date.new(2026, 3, 30)) # => 0
32
+ # ::Date.whole_months_elapsed(from: ::Date.new(2026, 2, 28), to: ::Date.new(2026, 3, 31)) # => 1
33
+ # ::Date.whole_months_elapsed(from: ::Date.new(2024, 2, 29), to: ::Date.new(2025, 2, 28)) # => 12
34
+ #
35
+ # @raise [ArgumentError] toがfromより前の日付の場合
36
+ def whole_months_elapsed(from:, to:)
37
+ raise ::ArgumentError, "to must be on or after from (from: #{from}, to: #{to})" if to < from
38
+
39
+ months = ((to.year - from.year) * 12) + (to.month - from.month)
40
+
41
+ # 満了日に達していない場合は1ヶ月に満たない
42
+ expiration_date(from:, months:) > to ? months - 1 : months
43
+ end
44
+
45
+ private
46
+
47
+ # 満了日
48
+ #
49
+ # fromから起算してmonthsヶ月が満了する日を返す。
50
+ #
51
+ # from: 2026-01-15, months: 1 # => 2026-02-15(起算日2026-01-16の応当日2026-02-16の前日)
52
+ # from: 2026-01-30, months: 1 # => 2026-02-28(起算日2026-01-31の応当日が存在しないため2月の末日)
53
+ # from: 2026-02-28, months: 1 # => 2026-03-31(起算日2026-03-01の応当日2026-04-01の前日)
54
+ def expiration_date(from:, months:)
55
+ beginning_date = from.next_day # 起算日(初日不算入)
56
+ corresponding_date = beginning_date >> months # 応当日(存在しない場合はその月の末日に繰り下がる)
57
+
58
+ corresponding_date.day == beginning_date.day ? corresponding_date.prev_day : corresponding_date
59
+ end
60
+ end
61
+
62
+ # ###############################################################################################################
63
+ # 週関係
64
+ # ###############################################################################################################
65
+
66
+ #
67
+ # 今週
68
+ #
69
+
70
+ # 現在の日付が属する週の始まりの日付
71
+ def beginning_of_this_week = beginning_of_week(::Date.beginning_of_week)
72
+
73
+ # 現在の日付が属する週の終わりの日付
74
+ def end_of_this_week = beginning_of_this_week.advance(days: 6)
75
+
76
+ # 今週の期間
77
+ def all_this_week = ::Range.new(beginning_of_this_week, end_of_this_week)
78
+
79
+ # ###############################################################################################################
80
+ # 月関係
81
+ # ###############################################################################################################
82
+
83
+ #
84
+ # 今月関係
85
+ #
86
+
87
+ # 現在の日付が属する月の始まりの日付
88
+ def beginning_of_this_month = beginning_of_month
89
+
90
+ # 現在の日付が属する月の終わりの日付
91
+ def end_of_this_month = end_of_month
92
+
93
+ # 現在の日付が属する月の期間
94
+ def all_this_month = ::Range.new(beginning_of_this_month, end_of_this_month)
95
+
96
+ #
97
+ # Nヶ月前関係
98
+ #
99
+
100
+ # 2ヶ月前の日付
101
+ def two_months_ago = months_ago(2)
102
+
103
+ # 3ヶ月前の日付
104
+ def three_months_ago = months_ago(3)
105
+
106
+ # 4ヶ月前の日付
107
+ def four_months_ago = months_ago(4)
108
+
109
+ # 5ヶ月前の日付
110
+ def five_months_ago = months_ago(5)
111
+
112
+ # 6ヶ月前の日付
113
+ def six_months_ago = months_ago(6)
114
+
115
+ # 半年前の日付
116
+ def half_year_ago = six_months_ago
117
+
118
+ # 7ヶ月前の日付
119
+ def seven_months_ago = months_ago(7)
120
+
121
+ # 8ヶ月前の日付
122
+ def eight_months_ago = months_ago(8)
123
+
124
+ # 9ヶ月前の日付
125
+ def nine_months_ago = months_ago(9)
126
+
127
+ # 10ヶ月前の日付
128
+ def ten_months_ago = months_ago(10)
129
+
130
+ # 11ヶ月前の日付
131
+ def eleven_months_ago = months_ago(11)
132
+
133
+ #
134
+ # Nヶ月後関係
135
+ #
136
+
137
+ # 2ヶ月後の日付
138
+ def two_months_since = months_since(2)
139
+
140
+ # 3ヶ月後の日付
141
+ def three_months_since = months_since(3)
142
+
143
+ # 4ヶ月後の日付
144
+ def four_months_since = months_since(4)
145
+
146
+ # 5ヶ月後の日付
147
+ def five_months_since = months_since(5)
148
+
149
+ # 6ヶ月後の日付
150
+ def six_months_since = months_since(6)
151
+
152
+ # 半年後の日付
153
+ def half_year_since = six_months_since
154
+
155
+ # 7ヶ月後の日付
156
+ def seven_months_since = months_since(7)
157
+
158
+ # 8ヶ月後の日付
159
+ def eight_months_since = months_since(8)
160
+
161
+ # 9ヶ月後の日付
162
+ def nine_months_since = months_since(9)
163
+
164
+ # 10ヶ月後の日付
165
+ def ten_months_since = months_since(10)
166
+
167
+ # 11ヶ月後の日付
168
+ def eleven_months_since = months_since(11)
169
+
170
+ #
171
+ # 暦月関係
172
+ #
173
+
174
+ #
175
+ # 1月
176
+ #
177
+
178
+ # 1月の月初
179
+ def beginning_of_january = change(month: 1, day: 1)
180
+
181
+ # 1月の月末
182
+ def end_of_january = beginning_of_january.end_of_month
183
+
184
+ # 1月の期間
185
+ def all_january = ::Range.new(beginning_of_january, end_of_january)
186
+
187
+ # 1月の月初か?
188
+ def beginning_of_january? = self == beginning_of_january
189
+
190
+ # 1月の月末か?
191
+ def end_of_january? = self == end_of_january
192
+
193
+ # 1月か?
194
+ def in_january? = all_january.cover?(self)
195
+
196
+ #
197
+ # 2月
198
+ #
199
+
200
+ # 2月の月初
201
+ def beginning_of_february = change(month: 2, day: 1)
202
+
203
+ # 2月の月末
204
+ def end_of_february = beginning_of_february.end_of_month
205
+
206
+ # 2月の期間
207
+ def all_february = ::Range.new(beginning_of_february, end_of_february)
208
+
209
+ # 2月の月初か?
210
+ def beginning_of_february? = self == beginning_of_february
211
+
212
+ # 2月の月末か?
213
+ def end_of_february? = self == end_of_february
214
+
215
+ # 2月か?
216
+ def in_february? = all_february.cover?(self)
217
+
218
+ #
219
+ # 3月
220
+ #
221
+
222
+ # 3月の月初
223
+ def beginning_of_march = change(month: 3, day: 1)
224
+
225
+ # 3月の月末
226
+ def end_of_march = beginning_of_march.end_of_month
227
+
228
+ # 3月の期間
229
+ def all_march = ::Range.new(beginning_of_march, end_of_march)
230
+
231
+ # 3月の月初か?
232
+ def beginning_of_march? = self == beginning_of_march
233
+
234
+ # 3月の月末か?
235
+ def end_of_march? = self == end_of_march
236
+
237
+ # 3月か?
238
+ def in_march? = all_march.cover?(self)
239
+
240
+ #
241
+ # 4月
242
+ #
243
+
244
+ # 4月の月初
245
+ def beginning_of_april = change(month: 4, day: 1)
246
+
247
+ # 4月の月末
248
+ def end_of_april = beginning_of_april.end_of_month
249
+
250
+ # 4月の期間
251
+ def all_april = ::Range.new(beginning_of_april, end_of_april)
252
+
253
+ # 4月の月初か?
254
+ def beginning_of_april? = self == beginning_of_april
255
+
256
+ # 4月の月末か?
257
+ def end_of_april? = self == end_of_april
258
+
259
+ # 4月か?
260
+ def in_april? = all_april.cover?(self)
261
+
262
+ #
263
+ # 5月
264
+ #
265
+
266
+ # 5月の月初
267
+ def beginning_of_may = change(month: 5, day: 1)
268
+
269
+ # 5月の月末
270
+ def end_of_may = beginning_of_may.end_of_month
271
+
272
+ # 5月の期間
273
+ def all_may = ::Range.new(beginning_of_may, end_of_may)
274
+
275
+ # 5月の月初か?
276
+ def beginning_of_may? = self == beginning_of_may
277
+
278
+ # 5月の月末か?
279
+ def end_of_may? = self == end_of_may
280
+
281
+ # 5月か?
282
+ def in_may? = all_may.cover?(self)
283
+
284
+ #
285
+ # 6月
286
+ #
287
+
288
+ # 6月の月初
289
+ def beginning_of_june = change(month: 6, day: 1)
290
+
291
+ # 6月の月末
292
+ def end_of_june = beginning_of_june.end_of_month
293
+
294
+ # 6月の期間
295
+ def all_june = ::Range.new(beginning_of_june, end_of_june)
296
+
297
+ # 6月の月初か?
298
+ def beginning_of_june? = self == beginning_of_june
299
+
300
+ # 6月の月末か?
301
+ def end_of_june? = self == end_of_june
302
+
303
+ # 6月か?
304
+ def in_june? = all_june.cover?(self)
305
+
306
+ #
307
+ # 7月
308
+ #
309
+
310
+ # 7月の月初
311
+ def beginning_of_july = change(month: 7, day: 1)
312
+
313
+ # 7月の月末
314
+ def end_of_july = beginning_of_july.end_of_month
315
+
316
+ # 7月の期間
317
+ def all_july = ::Range.new(beginning_of_july, end_of_july)
318
+
319
+ # 7月の月初か?
320
+ def beginning_of_july? = self == beginning_of_july
321
+
322
+ # 7月の月末か?
323
+ def end_of_july? = self == end_of_july
324
+
325
+ # 7月か?
326
+ def in_july? = all_july.cover?(self)
327
+
328
+ #
329
+ # 8月
330
+ #
331
+
332
+ # 8月の月初
333
+ def beginning_of_august = change(month: 8, day: 1)
334
+
335
+ # 8月の月末
336
+ def end_of_august = beginning_of_august.end_of_month
337
+
338
+ # 8月の期間
339
+ def all_august = ::Range.new(beginning_of_august, end_of_august)
340
+
341
+ # 8月の月初か?
342
+ def beginning_of_august? = self == beginning_of_august
343
+
344
+ # 8月の月末か?
345
+ def end_of_august? = self == end_of_august
346
+
347
+ # 8月か?
348
+ def in_august? = all_august.cover?(self)
349
+
350
+ #
351
+ # 9月
352
+ #
353
+
354
+ # 9月の月初
355
+ def beginning_of_september = change(month: 9, day: 1)
356
+
357
+ # 9月の月末
358
+ def end_of_september = beginning_of_september.end_of_month
359
+
360
+ # 9月の期間
361
+ def all_september = ::Range.new(beginning_of_september, end_of_september)
362
+
363
+ # 9月の月初か?
364
+ def beginning_of_september? = self == beginning_of_september
365
+
366
+ # 9月の月末か?
367
+ def end_of_september? = self == end_of_september
368
+
369
+ # 9月か?
370
+ def in_september? = all_september.cover?(self)
371
+
372
+ #
373
+ # 10月
374
+ #
375
+
376
+ # 10月の月初
377
+ def beginning_of_october = change(month: 10, day: 1)
378
+
379
+ # 10月の月末
380
+ def end_of_october = beginning_of_october.end_of_month
381
+
382
+ # 10月の期間
383
+ def all_october = ::Range.new(beginning_of_october, end_of_october)
384
+
385
+ # 10月の月初か?
386
+ def beginning_of_october? = self == beginning_of_october
387
+
388
+ # 10月の月末か?
389
+ def end_of_october? = self == end_of_october
390
+
391
+ # 10月か?
392
+ def in_october? = all_october.cover?(self)
393
+
394
+ #
395
+ # 11月
396
+ #
397
+
398
+ # 11月の月初
399
+ def beginning_of_november = change(month: 11, day: 1)
400
+
401
+ # 11月の月末
402
+ def end_of_november = beginning_of_november.end_of_month
403
+
404
+ # 11月の期間
405
+ def all_november = ::Range.new(beginning_of_november, end_of_november)
406
+
407
+ # 11月の月初か?
408
+ def beginning_of_november? = self == beginning_of_november
409
+
410
+ # 11月の月末か?
411
+ def end_of_november? = self == end_of_november
412
+
413
+ # 11月か?
414
+ def in_november? = all_november.cover?(self)
415
+
416
+ #
417
+ # 12月
418
+ #
419
+
420
+ # 12月の月初
421
+ def beginning_of_december = change(month: 12, day: 1)
422
+
423
+ # 12月の月末
424
+ def end_of_december = beginning_of_december.end_of_month
425
+
426
+ # 12月の期間
427
+ def all_december = ::Range.new(beginning_of_december, end_of_december)
428
+
429
+ # 12月の月初か?
430
+ def beginning_of_december? = self == beginning_of_december
431
+
432
+ # 12月の月末か?
433
+ def end_of_december? = self == end_of_december
434
+
435
+ # 12月か?
436
+ def in_december? = all_december.cover?(self)
437
+
438
+ # ###############################################################################################################
439
+ # 四半期関係
440
+ # ###############################################################################################################
441
+
442
+ #
443
+ # 今四半期
444
+ #
445
+
446
+ # 現在の日付が属する四半期の番号(1〜4)
447
+ def this_quarter_number
448
+ (((month - ::Decentworks::DateSupport.first_quarter_month) % 12) / 3) + 1
449
+ end
450
+
451
+ # 現在の日付が属する四半期の期首
452
+ def beginning_of_this_quarter
453
+ beginning_of_first_quarter.months_since((this_quarter_number - 1) * 3)
454
+ end
455
+
456
+ # 現在の日付が属する四半期の期末
457
+ def end_of_this_quarter = beginning_of_this_quarter.two_months_since.end_of_month
458
+
459
+ # 現在の日付が属する四半期の期間
460
+ def all_this_quarter = ::Range.new(beginning_of_this_quarter, end_of_this_quarter)
461
+
462
+ #
463
+ # 次の四半期
464
+ #
465
+
466
+ # 次の四半期の期首
467
+ def beginning_of_next_quarter = beginning_of_this_quarter.three_months_since
468
+
469
+ # 次の四半期の期末
470
+ def end_of_next_quarter = beginning_of_next_quarter.two_months_since.end_of_month
471
+
472
+ # 次の四半期の期間
473
+ def all_next_quarter = ::Range.new(beginning_of_next_quarter, end_of_next_quarter)
474
+
475
+ #
476
+ # 前の四半期
477
+ #
478
+
479
+ # 前の四半期の期首
480
+ def beginning_of_prev_quarter = beginning_of_this_quarter.three_months_ago
481
+
482
+ # 前の四半期の期末
483
+ def end_of_prev_quarter = beginning_of_prev_quarter.two_months_since.end_of_month
484
+
485
+ # 前の四半期の期間
486
+ def all_prev_quarter = ::Range.new(beginning_of_prev_quarter, end_of_prev_quarter)
487
+
488
+ #
489
+ # 第1四半期
490
+ #
491
+
492
+ # 第1四半期の期首
493
+ def beginning_of_first_quarter
494
+ beginning_of_month
495
+ .months_ago(::Decentworks::DateSupport.first_quarter_month_offset) # 1月始まりと見た時の対応した日付に移動
496
+ .change(month: ::Decentworks::DateSupport.first_quarter_month, day: 1)
497
+ end
498
+
499
+ # 第1四半期の期末
500
+ def end_of_first_quarter = beginning_of_first_quarter.two_months_since.end_of_month
501
+
502
+ # 第1四半期の期間
503
+ def all_first_quarter = ::Range.new(beginning_of_first_quarter, end_of_first_quarter)
504
+
505
+ # 第1四半期の期首か?
506
+ def beginning_of_first_quarter? = self == beginning_of_first_quarter
507
+
508
+ # 第1四半期の期末か?
509
+ def end_of_first_quarter? = self == end_of_first_quarter
510
+
511
+ # 第1四半期か?
512
+ def in_first_quarter? = all_first_quarter.cover?(self)
513
+
514
+ #
515
+ # 第2四半期
516
+ #
517
+
518
+ # 第2四半期の期首
519
+ def beginning_of_second_quarter = beginning_of_first_quarter.three_months_since
520
+
521
+ # 第2四半期の期末
522
+ def end_of_second_quarter = beginning_of_second_quarter.two_months_since.end_of_month
523
+
524
+ # 第2四半期の期間
525
+ def all_second_quarter = ::Range.new(beginning_of_second_quarter, end_of_second_quarter)
526
+
527
+ # 第2四半期の期首か?
528
+ def beginning_of_second_quarter? = self == beginning_of_second_quarter
529
+
530
+ # 第2四半期の期末か?
531
+ def end_of_second_quarter? = self == end_of_second_quarter
532
+
533
+ # 第2四半期か?
534
+ def in_second_quarter? = all_second_quarter.cover?(self)
535
+
536
+ #
537
+ # 第3四半期
538
+ #
539
+
540
+ # 第3四半期の期首
541
+ def beginning_of_third_quarter = beginning_of_first_quarter.six_months_since
542
+
543
+ # 第3四半期の期末
544
+ def end_of_third_quarter = beginning_of_third_quarter.two_months_since.end_of_month
545
+
546
+ # 第3四半期の期間
547
+ def all_third_quarter = ::Range.new(beginning_of_third_quarter, end_of_third_quarter)
548
+
549
+ # 第3四半期の期首か?
550
+ def beginning_of_third_quarter? = self == beginning_of_third_quarter
551
+
552
+ # 第3四半期の期末か?
553
+ def end_of_third_quarter? = self == end_of_third_quarter
554
+
555
+ # 第3四半期か?
556
+ def in_third_quarter? = all_third_quarter.cover?(self)
557
+
558
+ #
559
+ # 第4四半期
560
+ #
561
+
562
+ # 第4四半期の期首
563
+ def beginning_of_fourth_quarter = beginning_of_first_quarter.nine_months_since
564
+
565
+ # 第4四半期の期末
566
+ def end_of_fourth_quarter = beginning_of_fourth_quarter.two_months_since.end_of_month
567
+
568
+ # 第4四半期の期間
569
+ def all_fourth_quarter = ::Range.new(beginning_of_fourth_quarter, end_of_fourth_quarter)
570
+
571
+ # 第4四半期の期首か?
572
+ def beginning_of_fourth_quarter? = self == beginning_of_fourth_quarter
573
+
574
+ # 第4四半期の期末か?
575
+ def end_of_fourth_quarter? = self == end_of_fourth_quarter
576
+
577
+ # 第4四半期か?
578
+ def in_fourth_quarter? = all_fourth_quarter.cover?(self)
579
+
580
+ # ###############################################################################################################
581
+ # 上下期関係
582
+ # ###############################################################################################################
583
+
584
+ #
585
+ # 今期
586
+ #
587
+
588
+ # 現在の日付が属する期の番号(1〜2)
589
+ def this_half_number = this_quarter_number <= 2 ? 1 : 2
590
+
591
+ # 現在の日付が属する期の期首
592
+ def beginning_of_this_half = this_half_number == 1 ? beginning_of_first_half : beginning_of_second_half
593
+
594
+ # 現在の日付が属する期の期末
595
+ def end_of_this_half = this_half_number == 1 ? end_of_first_half : end_of_second_half
596
+
597
+ # 現在の日付が属する期の期間
598
+ def all_this_half = ::Range.new(beginning_of_this_half, end_of_this_half)
599
+
600
+ #
601
+ # 次の期
602
+ #
603
+
604
+ # 次の期の期首
605
+ def beginning_of_next_half = beginning_of_this_half.six_months_since
606
+
607
+ # 次の期の期末
608
+ def end_of_next_half = beginning_of_next_half.five_months_since.end_of_month
609
+
610
+ # 次の期の期間
611
+ def all_next_half = ::Range.new(beginning_of_next_half, end_of_next_half)
612
+
613
+ #
614
+ # 前の期
615
+ #
616
+
617
+ # 前の期の期首
618
+ def beginning_of_prev_half = beginning_of_this_half.six_months_ago
619
+
620
+ # 前の期の期末
621
+ def end_of_prev_half = beginning_of_prev_half.five_months_since.end_of_month
622
+
623
+ # 前の期の期間
624
+ def all_prev_half = ::Range.new(beginning_of_prev_half, end_of_prev_half)
625
+
626
+ #
627
+ # 上期
628
+ #
629
+
630
+ # 上期の期首
631
+ def beginning_of_first_half = beginning_of_first_quarter
632
+
633
+ # 上期の期末
634
+ def end_of_first_half = end_of_second_quarter
635
+
636
+ # 上期の期間
637
+ def all_first_half = ::Range.new(beginning_of_first_half, end_of_first_half)
638
+
639
+ # 上期の期首か?
640
+ def beginning_of_first_half? = self == beginning_of_first_half
641
+
642
+ # 上期の期末か?
643
+ def end_of_first_half? = self == end_of_first_half
644
+
645
+ # 上期か?
646
+ def in_first_half? = all_first_half.cover?(self)
647
+
648
+ #
649
+ # 下期
650
+ #
651
+
652
+ # 下期の期首
653
+ def beginning_of_second_half = beginning_of_third_quarter
654
+
655
+ # 下期の期末
656
+ def end_of_second_half = end_of_fourth_quarter
657
+
658
+ # 下期の期間
659
+ def all_second_half = ::Range.new(beginning_of_second_half, end_of_second_half)
660
+
661
+ # 下期の期首か?
662
+ def beginning_of_second_half? = self == beginning_of_second_half
663
+
664
+ # 下期の期末か?
665
+ def end_of_second_half? = self == end_of_second_half
666
+
667
+ # 下期か?
668
+ def in_second_half? = all_second_half.cover?(self)
669
+
670
+ # ###############################################################################################################
671
+ # 年度関係
672
+ # ###############################################################################################################
673
+
674
+ # 現在の日付が属する年度(期首の年)
675
+ def fiscal_year = beginning_of_fiscal_year.year
676
+
677
+ # 年度の期首
678
+ def beginning_of_fiscal_year = beginning_of_first_quarter
679
+
680
+ # 年度の期末
681
+ def end_of_fiscal_year = end_of_fourth_quarter
682
+
683
+ #
684
+ # 次の年度
685
+ #
686
+
687
+ # 次の年度(期首の年)
688
+ def next_fiscal_year = fiscal_year + 1
689
+
690
+ # 次の年度の期首
691
+ def beginning_of_next_fiscal_year = beginning_of_fiscal_year.months_since(12)
692
+
693
+ # 次の年度の期末
694
+ def end_of_next_fiscal_year = beginning_of_next_fiscal_year.eleven_months_since.end_of_month
695
+
696
+ # 次の年度の期間
697
+ def all_next_fiscal_year = ::Range.new(beginning_of_next_fiscal_year, end_of_next_fiscal_year)
698
+
699
+ #
700
+ # 前の年度
701
+ #
702
+
703
+ # 前の年度(期首の年)
704
+ def prev_fiscal_year = fiscal_year - 1
705
+
706
+ # 前の年度の期首
707
+ def beginning_of_prev_fiscal_year = beginning_of_fiscal_year.months_ago(12)
708
+
709
+ # 前の年度の期末
710
+ def end_of_prev_fiscal_year = beginning_of_prev_fiscal_year.eleven_months_since.end_of_month
711
+
712
+ # 前の年度の期間
713
+ def all_prev_fiscal_year = ::Range.new(beginning_of_prev_fiscal_year, end_of_prev_fiscal_year)
714
+
715
+ # 年度の期間
716
+ def all_fiscal_year = ::Range.new(beginning_of_fiscal_year, end_of_fiscal_year)
717
+
718
+ # ###############################################################################################################
719
+ # ActiveSupportのメソッドの上書き
720
+ # ###############################################################################################################
721
+ #
722
+ # ActiveSupportの四半期メソッドは暦年基準(1月・4月・7月・10月始まり固定)であり、
723
+ # first_quarter_month_nameの設定を参照しない。設定を反映した値を返すよう上書きする。
724
+ #
725
+ # ActiveSupportがaliasで定義している別名(at_beginning_of_quarter / at_end_of_quarter /
726
+ # last_quarter)は定義時点の実体を掴むため、本体を上書きしても追従しない。
727
+ # 値が食い違わないよう、別名もメソッド定義で上書きする。
728
+
729
+ # 現在の日付が属する四半期の番号(1〜4)
730
+ def quarter = this_quarter_number
731
+
732
+ # 現在の日付が属する四半期の期首
733
+ def beginning_of_quarter = beginning_of_this_quarter
734
+
735
+ # 現在の日付が属する四半期の期首(beginning_of_quarterの別名)
736
+ def at_beginning_of_quarter = beginning_of_quarter
737
+
738
+ # 現在の日付が属する四半期の期末
739
+ def end_of_quarter = end_of_this_quarter
740
+
741
+ # 現在の日付が属する四半期の期末(end_of_quarterの別名)
742
+ def at_end_of_quarter = end_of_quarter
743
+
744
+ # 現在の日付が属する四半期の期間
745
+ def all_quarter = all_this_quarter
746
+
747
+ # 次の四半期の期首
748
+ #
749
+ # ActiveSupportは3ヶ月後の同日を返すが、期間ベースに揃えて期首を返す。
750
+ def next_quarter = beginning_of_next_quarter
751
+
752
+ # 前の四半期の期首
753
+ #
754
+ # ActiveSupportは3ヶ月前の同日を返すが、期間ベースに揃えて期首を返す。
755
+ def prev_quarter = beginning_of_prev_quarter
756
+
757
+ # 前の四半期の期首(prev_quarterの別名)
758
+ def last_quarter = prev_quarter
759
+ end
760
+ end
761
+ end