decentworks-date-support 0.1.1 → 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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -0
  3. data/LICENSE +1 -1
  4. data/README.md +245 -40
  5. data/lib/decentworks/date_support/configuration.rb +19 -18
  6. data/lib/decentworks/date_support/date.rb +4 -541
  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 +1 -1
  13. data/lib/decentworks/date_support.rb +5 -1
  14. data/lib/generators/decentworks/date_support/install/templates/decentworks_date_support.rb.tt +4 -6
  15. data/sig/decentworks/date_support/configuration.rbs +12 -3
  16. data/sig/decentworks/date_support/date.rbs +3 -167
  17. data/sig/decentworks/date_support/date_extension.rbs +244 -0
  18. data/sig/decentworks/date_support/date_time.rbs +4 -0
  19. data/sig/decentworks/date_support/time.rbs +4 -0
  20. data/sig/decentworks/date_support/time_extension.rbs +248 -0
  21. data/sig/decentworks/date_support/time_with_zone.rbs +21 -0
  22. data/sig/decentworks/date_support/version.rbs +5 -0
  23. metadata +14 -13
  24. data/.rspec +0 -3
  25. data/.rubocop.yml +0 -8
  26. data/.ruby-version +0 -1
  27. data/CODE_OF_CONDUCT.md +0 -132
  28. data/LICENSE.txt +0 -21
  29. data/Rakefile +0 -12
  30. data/Steepfile +0 -43
  31. data/lib/decentworks/active_support/time_with_zone_support.rb +0 -541
  32. data/rbs_collection.lock.yaml +0 -288
  33. data/rbs_collection.yaml +0 -41
  34. data/sig/decentworks/active_support/time_with_zone_support.rbs +0 -163
@@ -1,546 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "date"
4
- require "active_support/time"
5
- require_relative "configuration"
3
+ require "date" # ::Date の定義元
6
4
 
7
- module Decentworks
8
- module DateSupport
9
- refine ::Date do
10
- # ###############################################################################################################
11
- # 週関係
12
- # ###############################################################################################################
5
+ require_relative "date_extension"
13
6
 
14
- #
15
- # 今週
16
- #
17
-
18
- # 現在の日付が属する週の始まりの日付
19
- def beginning_of_this_week = beginning_of_week(::Date.beginning_of_week) # steep:ignore NoMethod
20
-
21
- # 現在の日付が属する週の終わりの日付
22
- def end_of_this_week = next_week.beginning_of_this_week.yesterday
23
-
24
- # 今週の期間
25
- def all_this_week = ::Range.new(beginning_of_this_week, end_of_this_week)
26
-
27
- # ###############################################################################################################
28
- # 月関係
29
- # ###############################################################################################################
30
-
31
- #
32
- # 今月関係
33
- #
34
-
35
- # 現在の日付が属する月の期間
36
- def all_this_month
37
- ::Range.new(
38
- beginning_of_month.to_date, # steep:ignore NoMethod
39
- end_of_month.to_date # steep:ignore NoMethod
40
- )
41
- end
42
-
43
- #
44
- # Nヶ月前関係
45
- #
46
-
47
- # 2ヶ月前の日付
48
- def two_months_ago = months_ago(2) # steep:ignore NoMethod
49
-
50
- # 3ヶ月前の日付
51
- def three_months_ago = months_ago(3) # steep:ignore NoMethod
52
-
53
- # 4ヶ月前の日付
54
- def four_months_ago = months_ago(4) # steep:ignore NoMethod
55
-
56
- # 5ヶ月前の日付
57
- def five_months_ago = months_ago(5) # steep:ignore NoMethod
58
-
59
- # 6ヶ月前の日付
60
- def six_months_ago = months_ago(6) # steep:ignore NoMethod
61
-
62
- # 半年前の日
63
- alias_method :half_year_ago, :six_months_ago
64
-
65
- # 7ヶ月前の日付
66
- def seven_months_ago = months_ago(7) # steep:ignore NoMethod
67
-
68
- # 8ヶ月前の日付
69
- def eight_months_ago = months_ago(8) # steep:ignore NoMethod
70
-
71
- # 9ヶ月前の日付
72
- def nine_months_ago = months_ago(9) # steep:ignore NoMethod
73
-
74
- # 10ヶ月前の日付
75
- def ten_months_ago = months_ago(10) # steep:ignore NoMethod
76
-
77
- # 11ヶ月前の日付
78
- def eleven_months_ago = months_ago(11) # steep:ignore NoMethod
79
-
80
- #
81
- # Nヶ月後関係
82
- #
83
-
84
- # 2ヶ月後の日付
85
- def two_months_since = months_since(2) # steep:ignore NoMethod
86
-
87
- # 3ヶ月後の日付
88
- def three_months_since = months_since(3) # steep:ignore NoMethod
89
-
90
- # 4ヶ月後の日付
91
- def four_months_since = months_since(4) # steep:ignore NoMethod
92
-
93
- # 5ヶ月後の日付
94
- def five_months_since = months_since(5) # steep:ignore NoMethod
95
-
96
- # 6ヶ月後の日付
97
- def six_months_since = months_since(6) # steep:ignore NoMethod
98
-
99
- # 半年前の日
100
- alias_method :half_year_since, :six_months_since
101
-
102
- # 7ヶ月後の日付
103
- def seven_months_since = months_since(7) # steep:ignore NoMethod
104
-
105
- # 8ヶ月後の日付
106
- def eight_months_since = months_since(8) # steep:ignore NoMethod
107
-
108
- # 9ヶ月後の日付
109
- def nine_months_since = months_since(9) # steep:ignore NoMethod
110
-
111
- # 10ヶ月後の日付
112
- def ten_months_since = months_since(10) # steep:ignore NoMethod
113
-
114
- # 11ヶ月後の日付
115
- def eleven_months_since = months_since(11) # steep:ignore NoMethod
116
-
117
- #
118
- # 暦月関係
119
- #
120
-
121
- #
122
- # 1月
123
- #
124
-
125
- # 1月の月初
126
- def beginning_of_january = change(month: 1, day: 1) # steep:ignore NoMethod
127
-
128
- # 1月の月末
129
- def end_of_january = beginning_of_january.end_of_month
130
-
131
- # 1月の期間
132
- def all_january = ::Range.new(beginning_of_january, end_of_january)
133
-
134
- # 1月の月初か?
135
- def beginning_of_january? = eql?(beginning_of_january)
136
-
137
- # 1月の月末か?
138
- def end_of_january? = eql?(end_of_january)
139
-
140
- # 1月か?
141
- def in_january? = all_january.cover?(self)
142
-
143
- #
144
- # 2月
145
- #
146
-
147
- # 2月の月初
148
- def beginning_of_february = change(month: 2, day: 1) # steep:ignore NoMethod
149
-
150
- # 2月の月末
151
- def end_of_february = beginning_of_february.end_of_month
152
-
153
- # 2月の期間
154
- def all_february = ::Range.new(beginning_of_february, end_of_february)
155
-
156
- # 2月の月初か?
157
- def beginning_of_february? = eql?(beginning_of_february)
158
-
159
- # 2月の月末か?
160
- def end_of_february? = eql?(end_of_february)
161
-
162
- # 2月か?
163
- def in_february? = all_february.cover?(self)
164
-
165
- #
166
- # 3月
167
- #
168
-
169
- # 3月の月初
170
- def beginning_of_march = change(month: 3, day: 1) # steep:ignore NoMethod
171
-
172
- # 3月の月末
173
- def end_of_march = beginning_of_march.end_of_month
174
-
175
- # 3月の期間
176
- def all_march = ::Range.new(beginning_of_march, end_of_march)
177
-
178
- # 3月の月初か?
179
- def beginning_of_march? = eql?(beginning_of_march)
180
-
181
- # 3月の月末か?
182
- def end_of_march? = eql?(end_of_march)
183
-
184
- # 3月か?
185
- def in_march? = all_march.cover?(self)
186
-
187
- #
188
- # 4月
189
- #
190
-
191
- # 4月の月初
192
- def beginning_of_april = change(month: 4, day: 1) # steep:ignore NoMethod
193
-
194
- # 4月の月末
195
- def end_of_april = beginning_of_april.end_of_month
196
-
197
- # 4月の期間
198
- def all_april = ::Range.new(beginning_of_april, end_of_april)
199
-
200
- # 4月の月初か?
201
- def beginning_of_april? = eql?(beginning_of_april)
202
-
203
- # 4月の月末か?
204
- def end_of_april? = eql?(end_of_april)
205
-
206
- # 4月か?
207
- def in_april? = all_april.cover?(self)
208
-
209
- #
210
- # 5月
211
- #
212
-
213
- # 5月の月初
214
- def beginning_of_may = change(month: 5, day: 1) # steep:ignore NoMethod
215
-
216
- # 5月の月末
217
- def end_of_may = beginning_of_may.end_of_month
218
-
219
- # 5月の期間
220
- def all_may = ::Range.new(beginning_of_may, end_of_may)
221
-
222
- # 5月の月初か?
223
- def beginning_of_may? = eql?(beginning_of_may)
224
-
225
- # 5月の月末か?
226
- def end_of_may? = eql?(end_of_may)
227
-
228
- # 5月か?
229
- def in_may? = all_may.cover?(self)
230
-
231
- #
232
- # 6月
233
- #
234
-
235
- # 6月の月初
236
- def beginning_of_june = change(month: 6, day: 1) # steep:ignore NoMethod
237
-
238
- # 6月の月末
239
- def end_of_june = beginning_of_june.end_of_month
240
-
241
- # 6月の期間
242
- def all_june = ::Range.new(beginning_of_june, end_of_june)
243
-
244
- # 6月の月初か?
245
- def beginning_of_june? = eql?(beginning_of_june)
246
-
247
- # 6月の月末か?
248
- def end_of_june? = eql?(end_of_june)
249
-
250
- # 6月か?
251
- def in_june? = all_june.cover?(self)
252
-
253
- #
254
- # 7月
255
- #
256
-
257
- # 7月の月初
258
- def beginning_of_july = change(month: 7, day: 1) # steep:ignore NoMethod
259
-
260
- # 7月の月末
261
- def end_of_july = beginning_of_july.end_of_month
262
-
263
- # 7月の期間
264
- def all_july = ::Range.new(beginning_of_july, end_of_july)
265
-
266
- # 7月の月初か?
267
- def beginning_of_july? = eql?(beginning_of_july)
268
-
269
- # 7月の月末か?
270
- def end_of_july? = eql?(end_of_july)
271
-
272
- # 7月か?
273
- def in_july? = all_july.cover?(self)
274
-
275
- #
276
- # 8月
277
- #
278
-
279
- # 8月の月初
280
- def beginning_of_august = change(month: 8, day: 1) # steep:ignore NoMethod
281
-
282
- # 8月の月末
283
- def end_of_august = beginning_of_august.end_of_month
284
-
285
- # 8月の期間
286
- def all_august = ::Range.new(beginning_of_august, end_of_august)
287
-
288
- # 8月の月初か?
289
- def beginning_of_august? = eql?(beginning_of_august)
290
-
291
- # 8月の月末か?
292
- def end_of_august? = eql?(end_of_august)
293
-
294
- # 8月か?
295
- def in_august? = all_august.cover?(self)
296
-
297
- #
298
- # 9月
299
- #
300
-
301
- # 9月の月初
302
- def beginning_of_september = change(month: 9, day: 1) # steep:ignore NoMethod
303
-
304
- # 9月の月末
305
- def end_of_september = beginning_of_september.end_of_month
306
-
307
- # 9月の期間
308
- def all_september = ::Range.new(beginning_of_september, end_of_september)
309
-
310
- # 9月の月初か?
311
- def beginning_of_september? = eql?(beginning_of_september)
312
-
313
- # 9月の月末か?
314
- def end_of_september? = eql?(end_of_september)
315
-
316
- # 9月か?
317
- def in_september? = all_september.cover?(self)
318
-
319
- #
320
- # 10月
321
- #
322
-
323
- # 10月の月初
324
- def beginning_of_october = change(month: 10, day: 1) # steep:ignore NoMethod
325
-
326
- # 10月の月末
327
- def end_of_october = beginning_of_october.end_of_month
328
-
329
- # 10月の期間
330
- def all_october = ::Range.new(beginning_of_october, end_of_october)
331
-
332
- # 10月の月初か?
333
- def beginning_of_october? = eql?(beginning_of_october)
334
-
335
- # 10月の月末か?
336
- def end_of_october? = eql?(end_of_october)
337
-
338
- # 10月か?
339
- def in_october? = all_october.cover?(self)
340
-
341
- #
342
- # 11月
343
- #
344
-
345
- # 11月の月初
346
- def beginning_of_november = change(month: 11, day: 1) # steep:ignore NoMethod
347
-
348
- # 11月の月末
349
- def end_of_november = beginning_of_november.end_of_month
350
-
351
- # 11月の期間
352
- def all_november = ::Range.new(beginning_of_november, end_of_november)
353
-
354
- # 11月の月初か?
355
- def beginning_of_november? = eql?(beginning_of_november)
356
-
357
- # 11月の月末か?
358
- def end_of_november? = eql?(end_of_november)
359
-
360
- # 11月か?
361
- def in_november? = all_november.cover?(self)
362
-
363
- #
364
- # 12月
365
- #
366
-
367
- # 12月の月初
368
- def beginning_of_december = change(month: 12, day: 1) # steep:ignore NoMethod
369
-
370
- # 12月の月末
371
- def end_of_december = beginning_of_december.end_of_month
372
-
373
- # 12月の期間
374
- def all_december = ::Range.new(beginning_of_december, end_of_december)
375
-
376
- # 12月の月初か?
377
- def beginning_of_december? = eql?(beginning_of_december)
378
-
379
- # 12月の月末か?
380
- def end_of_december? = eql?(end_of_december)
381
-
382
- # 12月か?
383
- def in_december? = all_december.cover?(self)
384
-
385
- # ###############################################################################################################
386
- # 四半期関係
387
- # ###############################################################################################################
388
-
389
- #
390
- # 第1四半期
391
- #
392
-
393
- # 第1四半期の期首
394
- def beginning_of_first_quarter
395
- beginning_of_month
396
- .months_ago(::Decentworks::DateSupport.first_quarter_month_offset) # 1月始まりと見た時の対応した日付に移動
397
- .change(month: ::Decentworks::DateSupport.beginning_of_first_quarter_month, day: 1)
398
- end
399
-
400
- # 第1四半期の期末
401
- def end_of_first_quarter = beginning_of_first_quarter.two_months_since.end_of_month
402
-
403
- # 第1四半期の期間
404
- def all_first_quarter = ::Range.new(beginning_of_first_quarter, end_of_first_quarter)
405
-
406
- # 第1四半期の期首か?
407
- def beginning_of_first_quarter? = eql?(beginning_of_first_quarter)
408
-
409
- # 第1四半期の期末か?
410
- def end_of_first_quarter? = eql?(end_of_first_quarter)
411
-
412
- # 第1四半期か?
413
- def in_first_quarter? = all_first_quarter.cover?(self)
414
-
415
- #
416
- # 第2四半期
417
- #
418
-
419
- # 第2四半期の期首
420
- def beginning_of_second_quarter = beginning_of_first_quarter.three_months_since
421
-
422
- # 第2四半期の期末
423
- def end_of_second_quarter = beginning_of_second_quarter.two_months_since.end_of_month
424
-
425
- # 第2四半期の期間
426
- def all_second_quarter = ::Range.new(beginning_of_second_quarter, end_of_second_quarter)
427
-
428
- # 第2四半期の期首か?
429
- def beginning_of_second_quarter? = eql?(beginning_of_second_quarter)
430
-
431
- # 第2四半期の期末か?
432
- def end_of_second_quarter? = eql?(end_of_second_quarter)
433
-
434
- # 第2四半期か?
435
- def in_second_quarter? = all_second_quarter.cover?(self)
436
-
437
- #
438
- # 第3四半期
439
- #
440
-
441
- # 第3四半期の期首
442
- def beginning_of_third_quarter = beginning_of_first_quarter.six_months_since
443
-
444
- # 第3四半期の期末
445
- def end_of_third_quarter = beginning_of_third_quarter.two_months_since.end_of_month
446
-
447
- # 第3四半期の期間
448
- def all_third_quarter = ::Range.new(beginning_of_third_quarter, end_of_third_quarter)
449
-
450
- # 第3四半期の期首か?
451
- def beginning_of_third_quarter? = eql?(beginning_of_third_quarter)
452
-
453
- # 第3四半期の期末か?
454
- def end_of_third_quarter? = eql?(end_of_third_quarter)
455
-
456
- # 第3四半期か?
457
- def in_third_quarter? = all_third_quarter.cover?(self)
458
-
459
- #
460
- # 第4四半期
461
- #
462
-
463
- # 第4四半期の期首
464
- def beginning_of_fourth_quarter = beginning_of_first_quarter.nine_months_since
465
-
466
- # 第4四半期の期末
467
- def end_of_fourth_quarter = beginning_of_fourth_quarter.two_months_since.end_of_month
468
-
469
- # 第4四半期の期間
470
- def all_fourth_quarter = ::Range.new(beginning_of_fourth_quarter, end_of_fourth_quarter)
471
-
472
- # 第4四半期の期首か?
473
- def beginning_of_fourth_quarter? = eql?(beginning_of_fourth_quarter)
474
-
475
- # 第4四半期の期末か?
476
- def end_of_fourth_quarter? = eql?(end_of_fourth_quarter)
477
-
478
- # 第4四半期か?
479
- def in_fourth_quarter? = all_fourth_quarter.cover?(self)
480
-
481
- # ###############################################################################################################
482
- # 上下期関係
483
- # ###############################################################################################################
484
-
485
- #
486
- # 上期
487
- #
488
-
489
- # 上期の期首
490
- alias_method :beginning_of_first_half, :beginning_of_first_quarter
491
-
492
- # 上期の期末
493
- alias_method :end_of_first_half, :end_of_second_quarter
494
-
495
- # 上期の期間
496
- def all_first_half = ::Range.new(beginning_of_first_half, end_of_first_half)
497
-
498
- # 上期の期首か?
499
- def beginning_of_first_half? = eql?(beginning_of_first_half)
500
-
501
- # 上期の期末か?
502
- def end_of_first_half? = eql?(end_of_first_half)
503
-
504
- # 上期か?
505
- def in_first_half? = all_first_half.cover?(self)
506
-
507
- #
508
- # 下期
509
- #
510
-
511
- # 下期の期首
512
- alias_method :beginning_of_second_half, :beginning_of_third_quarter
513
-
514
- # 下期の期末
515
- alias_method :end_of_second_half, :end_of_fourth_quarter
516
-
517
- # 下期の期間
518
- def all_second_half = ::Range.new(beginning_of_second_half, end_of_second_half)
519
-
520
- # 下期の期首か?
521
- def beginning_of_second_half? = eql?(beginning_of_second_half)
522
-
523
- # 下期の期末か?
524
- def end_of_second_half? = eql?(end_of_second_half)
525
-
526
- # 下期か?
527
- def in_second_half? = all_second_half.cover?(self)
528
- end
529
-
530
- refine ::Date.singleton_class do
531
- # ###############################################################################################################
532
- # 満経過月数
533
- # ###############################################################################################################
534
-
535
- # 満経過月数
536
- # steep:ignore:start
537
- def whole_months_elapsed(from:, to:)
538
- diff_year = to.year - from.year
539
- diff_month = to.month - from.month
540
-
541
- (diff_year * 12) + diff_month - (to.day >= from.day ? 0 : 1)
542
- end
543
- # steep:ignore:end
544
- end
545
- end
7
+ class ::Date
8
+ include ::Decentworks::DateSupport::DateExtension
546
9
  end