decentworks-date-support 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -3
- data/README.md +43 -4
- data/lib/decentworks/active_support/time_with_zone_support.rb +259 -45
- data/lib/decentworks/date_support/configuration.rb +72 -0
- data/lib/decentworks/date_support/date.rb +546 -0
- data/lib/decentworks/date_support/version.rb +7 -0
- data/lib/decentworks/date_support.rb +4 -321
- data/lib/decentworks-date-support.rb +3 -0
- data/lib/generators/decentworks/date_support/install/install_generator.rb +26 -0
- data/lib/generators/decentworks/date_support/install/templates/decentworks_date_support.rb.tt +52 -0
- data/sig/decentworks/active_support/time_with_zone_support.rbs +57 -3
- data/sig/decentworks/date_support/configuration.rbs +16 -0
- data/sig/decentworks/{date_support.rbs → date_support/date.rbs} +64 -3
- metadata +14 -131
- data/.gem_rbs_collection/actionpack/7.2/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/actionpack/7.2/actioncontroller-7.2.rbs +0 -14
- data/.gem_rbs_collection/actionpack/7.2/actioncontroller.rbs +0 -290
- data/.gem_rbs_collection/actionpack/7.2/actiondispatch.rbs +0 -349
- data/.gem_rbs_collection/actionpack/7.2/actionpack-generated.rbs +0 -11497
- data/.gem_rbs_collection/actionpack/7.2/patch.rbs +0 -77
- data/.gem_rbs_collection/actionview/6.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/actionview/6.0/actionview-generated.rbs +0 -8976
- data/.gem_rbs_collection/actionview/6.0/actionview.rbs +0 -1940
- data/.gem_rbs_collection/actionview/6.0/patch.rbs +0 -57
- data/.gem_rbs_collection/activesupport/7.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/activesupport/7.0/activesupport-7.0.rbs +0 -381
- data/.gem_rbs_collection/activesupport/7.0/activesupport-generated.rbs +0 -11633
- data/.gem_rbs_collection/activesupport/7.0/activesupport.rbs +0 -724
- data/.gem_rbs_collection/activesupport/7.0/manifest.yaml +0 -15
- data/.gem_rbs_collection/activesupport/7.0/patch.rbs +0 -55
- data/.gem_rbs_collection/ast/2.4/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/ast/2.4/ast.rbs +0 -73
- data/.gem_rbs_collection/cgi/0.5/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/cgi/0.5/core.rbs +0 -925
- data/.gem_rbs_collection/cgi/0.5/manifest.yaml +0 -3
- data/.gem_rbs_collection/concurrent-ruby/1.1/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/concurrent-ruby/1.1/array.rbs +0 -4
- data/.gem_rbs_collection/concurrent-ruby/1.1/atomic_reference.rbs +0 -16
- data/.gem_rbs_collection/concurrent-ruby/1.1/executor.rbs +0 -96
- data/.gem_rbs_collection/concurrent-ruby/1.1/hash.rbs +0 -4
- data/.gem_rbs_collection/concurrent-ruby/1.1/map.rbs +0 -68
- data/.gem_rbs_collection/concurrent-ruby/1.1/promises.rbs +0 -249
- data/.gem_rbs_collection/concurrent-ruby/1.1/set.rbs +0 -4
- data/.gem_rbs_collection/concurrent-ruby/1.1/timer_task.rbs +0 -47
- data/.gem_rbs_collection/concurrent-ruby/1.1/utility/processor_counter.rbs +0 -5
- data/.gem_rbs_collection/connection_pool/2.4/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/connection_pool/2.4/connection_pool.rbs +0 -34
- data/.gem_rbs_collection/connection_pool/2.4/manifest.yaml +0 -2
- data/.gem_rbs_collection/diff-lcs/1.5/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/diff-lcs/1.5/diff-lcs.rbs +0 -11
- data/.gem_rbs_collection/faker/3.4.2/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/faker/3.4.2/faker-2.23.rbs +0 -90
- data/.gem_rbs_collection/faker/3.4.2/faker.rbs +0 -18
- data/.gem_rbs_collection/i18n/1.10/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/i18n/1.10/backend.rbs +0 -274
- data/.gem_rbs_collection/i18n/1.10/i18n.rbs +0 -116
- data/.gem_rbs_collection/lint_roller/1.1/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/lint_roller/1.1/lint_roller.rbs +0 -48
- data/.gem_rbs_collection/minitest/5.25/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/minitest/5.25/minitest/abstract_reporter.rbs +0 -52
- data/.gem_rbs_collection/minitest/5.25/minitest/assertion.rbs +0 -17
- data/.gem_rbs_collection/minitest/5.25/minitest/assertions.rbs +0 -590
- data/.gem_rbs_collection/minitest/5.25/minitest/backtrace_filter.rbs +0 -23
- data/.gem_rbs_collection/minitest/5.25/minitest/bench_spec.rbs +0 -102
- data/.gem_rbs_collection/minitest/5.25/minitest/benchmark.rbs +0 -259
- data/.gem_rbs_collection/minitest/5.25/minitest/composite_reporter.rbs +0 -25
- data/.gem_rbs_collection/minitest/5.25/minitest/compress.rbs +0 -13
- data/.gem_rbs_collection/minitest/5.25/minitest/error_on_warning.rbs +0 -3
- data/.gem_rbs_collection/minitest/5.25/minitest/expectation.rbs +0 -2
- data/.gem_rbs_collection/minitest/5.25/minitest/expectations.rbs +0 -21
- data/.gem_rbs_collection/minitest/5.25/minitest/guard.rbs +0 -64
- data/.gem_rbs_collection/minitest/5.25/minitest/mock.rbs +0 -64
- data/.gem_rbs_collection/minitest/5.25/minitest/parallel/executor.rbs +0 -46
- data/.gem_rbs_collection/minitest/5.25/minitest/parallel/test/class_methods.rbs +0 -5
- data/.gem_rbs_collection/minitest/5.25/minitest/parallel/test.rbs +0 -3
- data/.gem_rbs_collection/minitest/5.25/minitest/parallel.rbs +0 -2
- data/.gem_rbs_collection/minitest/5.25/minitest/pride_io.rbs +0 -62
- data/.gem_rbs_collection/minitest/5.25/minitest/pride_lol.rbs +0 -19
- data/.gem_rbs_collection/minitest/5.25/minitest/progress_reporter.rbs +0 -11
- data/.gem_rbs_collection/minitest/5.25/minitest/reportable.rbs +0 -53
- data/.gem_rbs_collection/minitest/5.25/minitest/reporter.rbs +0 -5
- data/.gem_rbs_collection/minitest/5.25/minitest/result.rbs +0 -28
- data/.gem_rbs_collection/minitest/5.25/minitest/runnable.rbs +0 -163
- data/.gem_rbs_collection/minitest/5.25/minitest/skip.rbs +0 -6
- data/.gem_rbs_collection/minitest/5.25/minitest/spec/dsl/instance_methods.rbs +0 -48
- data/.gem_rbs_collection/minitest/5.25/minitest/spec/dsl.rbs +0 -129
- data/.gem_rbs_collection/minitest/5.25/minitest/spec.rbs +0 -11
- data/.gem_rbs_collection/minitest/5.25/minitest/statistics_reporter.rbs +0 -81
- data/.gem_rbs_collection/minitest/5.25/minitest/summary_reporter.rbs +0 -18
- data/.gem_rbs_collection/minitest/5.25/minitest/test/lifecycle_hooks.rbs +0 -92
- data/.gem_rbs_collection/minitest/5.25/minitest/test.rbs +0 -69
- data/.gem_rbs_collection/minitest/5.25/minitest/unexpected_error.rbs +0 -12
- data/.gem_rbs_collection/minitest/5.25/minitest/unexpected_warning.rbs +0 -6
- data/.gem_rbs_collection/minitest/5.25/minitest/unit/test_case.rbs +0 -3
- data/.gem_rbs_collection/minitest/5.25/minitest/unit.rbs +0 -4
- data/.gem_rbs_collection/minitest/5.25/minitest.rbs +0 -115
- data/.gem_rbs_collection/nokogiri/1.11/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/nokogiri/1.11/nokogiri.rbs +0 -2332
- data/.gem_rbs_collection/nokogiri/1.11/patch.rbs +0 -4
- data/.gem_rbs_collection/parallel/1.20/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/parallel/1.20/parallel.rbs +0 -86
- data/.gem_rbs_collection/parser/3.2/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/parser/3.2/manifest.yaml +0 -7
- data/.gem_rbs_collection/parser/3.2/parser.rbs +0 -194
- data/.gem_rbs_collection/parser/3.2/polyfill.rbs +0 -4
- data/.gem_rbs_collection/rack/2.2/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rack/2.2/manifest.yaml +0 -3
- data/.gem_rbs_collection/rack/2.2/rack.rbs +0 -1480
- data/.gem_rbs_collection/rails-dom-testing/2.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rails-dom-testing/2.0/rails-dom-testing.rbs +0 -51
- data/.gem_rbs_collection/rails-html-sanitizer/1.6/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rails-html-sanitizer/1.6/rails-html-sanitizer.rbs +0 -53
- data/.gem_rbs_collection/railties/6.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/railties/6.0/manifest.yaml +0 -2
- data/.gem_rbs_collection/railties/6.0/patch.rbs +0 -17
- data/.gem_rbs_collection/railties/6.0/railties-generated.rbs +0 -4822
- data/.gem_rbs_collection/railties/6.0/railties.rbs +0 -44
- data/.gem_rbs_collection/rainbow/3.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rainbow/3.0/global.rbs +0 -7
- data/.gem_rbs_collection/rainbow/3.0/presenter.rbs +0 -209
- data/.gem_rbs_collection/rainbow/3.0/rainbow.rbs +0 -5
- data/.gem_rbs_collection/rake/13.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rake/13.0/manifest.yaml +0 -2
- data/.gem_rbs_collection/rake/13.0/rake.rbs +0 -39
- data/.gem_rbs_collection/regexp_parser/2.8/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/regexp_parser/2.8/regexp_parser.rbs +0 -17
- data/.gem_rbs_collection/rubocop/1.57/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rubocop/1.57/rubocop.rbs +0 -208
- data/.gem_rbs_collection/rubocop-ast/1.46/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/rubocop-ast/1.46/rubocop-ast.rbs +0 -903
- data/.gem_rbs_collection/thor/1.2/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/thor/1.2/thor.rbs +0 -62
- data/.gem_rbs_collection/tzinfo/2.0/.rbs_meta.yaml +0 -9
- data/.gem_rbs_collection/tzinfo/2.0/manifest.yaml +0 -7
- data/.gem_rbs_collection/tzinfo/2.0/tzinfo.rbs +0 -600
- data/lib/decentworks/date/support/version.rb +0 -9
- data/lib/decentworks_date_support.rb +0 -4
- data/sig/decentworks/date/support.rbs +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecd2667a864d2b7d807244bea27aa807fcb2f23f425766efef2544be928650ae
|
|
4
|
+
data.tar.gz: 8f256c1fefaf7f66e8dd79b761f160d32c29dcee7b9bada4f4f02cb91e256657
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a1b3b1e9af91fb7cb31cc3e1ff97352a411d8bf9bc086e60cebd318a2fcefb0763951c19248123392d69284399f207f8b7a3c9bcb3d3c0dc1d4031bd7c709ecf
|
|
7
|
+
data.tar.gz: 873b03a25a370618596c948f8e061d6cfaf93d0cca9ff150b3bd07609c4121aff7e5edfdcc210604a346127d4c1dd27134feeb1af6ac074e11d82e69bf551d5b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# [0.1.1]
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- [四半期、上下期の開始日を設定できるようにする #1](https://github.com/SrDecentWorks/decentworks-date-support/issues/1)
|
|
4
|
+
- [週の始まりの曜日の指定を引数から削除 #3](https://github.com/SrDecentWorks/decentworks-date-support/issues/3)
|
|
5
|
+
- Gem内のファイル構成をリファクタリング
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
# [0.1.0]
|
|
8
|
+
|
|
9
|
+
- 初期リリース
|
|
10
|
+
- gem開発実験中
|
data/README.md
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
# Decentworks::Date::Support - 日付機能拡張ライブラリ
|
|
2
2
|
|
|
3
|
+
## はじめに
|
|
4
|
+
|
|
5
|
+
このgemは、個人開発用です。
|
|
6
|
+
そのため、予告なく仕様の追加・変更・削除が行われます。
|
|
7
|
+
もちろん、このgemを使用したことによるバグなどの責任は負えません。
|
|
8
|
+
|
|
3
9
|
## 概要
|
|
4
10
|
|
|
5
11
|
Railsの`Date`、`ActiveSupport::TimeWithZone`に対する機能拡張を行います。
|
|
6
12
|
|
|
13
|
+
## refinements
|
|
14
|
+
|
|
15
|
+
gemによる影響範囲を限定するため、refinementsを採用しています。
|
|
16
|
+
利用する場合は、適切なスコープで`using`を利用してください。
|
|
17
|
+
|
|
7
18
|
## 機能
|
|
8
19
|
|
|
20
|
+
### Dateクラス拡張
|
|
21
|
+
|
|
22
|
+
#### using
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
using ::Decentworks::DateSupport
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### ActiveSupport::TimeWithZoneクラス拡張
|
|
29
|
+
|
|
30
|
+
#### using
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
using ::Decentworks::ActiveSupport::TimeWithZoneSupport
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
9
37
|
### 週関係
|
|
10
38
|
|
|
11
39
|
- 週の始まりの曜日を指定しての日付・期間の取得
|
|
@@ -33,22 +61,33 @@ Railsの`Date`、`ActiveSupport::TimeWithZone`に対する機能拡張を行い
|
|
|
33
61
|
gem 'decentworks-date-support'
|
|
34
62
|
```
|
|
35
63
|
|
|
64
|
+
### 初期化ファイルの生成(Rails)
|
|
65
|
+
|
|
66
|
+
Railsから利用する場合は、以下のジェネレータで`config/initializers/decentworks_date_support.rb`を生成できます。
|
|
67
|
+
|
|
68
|
+
```shell
|
|
69
|
+
bin/rails generate decentworks:date_support:install
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- 初期値は1月始まりです。
|
|
73
|
+
- その他の月に変更したい場合は、ファイルの内容を修正してください。
|
|
74
|
+
|
|
36
75
|
## 使い方の例
|
|
37
76
|
|
|
38
77
|
```ruby
|
|
39
|
-
require '
|
|
78
|
+
require 'decentworks/date_support'
|
|
40
79
|
|
|
41
80
|
using ::Decentworks::DateSupport
|
|
42
81
|
|
|
43
82
|
d = ::Date.new(2026, 8, 5)
|
|
44
|
-
d.all_this_week
|
|
83
|
+
d.all_this_week # => Mon, 03 Aug 2026..Sun, 09 Aug 2026
|
|
45
84
|
```
|
|
46
85
|
|
|
47
86
|
```ruby
|
|
48
|
-
require '
|
|
87
|
+
require 'decentworks/date_support'
|
|
49
88
|
|
|
50
89
|
using ::Decentworks::ActiveSupport::TimeWithZoneSupport
|
|
51
90
|
|
|
52
91
|
d = ::Time.zone.local(2026, 8, 5)
|
|
53
|
-
d.all_this_week
|
|
92
|
+
d.all_this_week # => 2026-08-03 00:00:00.000000000 JST +09:00..2026-08-09 23:59:59.999999999 JST +09:00
|
|
54
93
|
```
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "date"
|
|
4
|
-
require "
|
|
4
|
+
require "active_support/time"
|
|
5
|
+
require_relative "../date_support/date" # using ::Decentworks::DateSupport に必要
|
|
5
6
|
|
|
6
7
|
module Decentworks
|
|
7
8
|
module ActiveSupport
|
|
@@ -18,34 +19,13 @@ module Decentworks
|
|
|
18
19
|
#
|
|
19
20
|
|
|
20
21
|
# 現在の日付が属する週の始まりの日付
|
|
21
|
-
|
|
22
|
-
# @param beginning_of_week 週の始まりの曜日。省略した場合は、config.beginning_of_weekの設定に従います。
|
|
23
|
-
def beginning_of_this_week(beginning_of_week = nil)
|
|
24
|
-
to_date # steep:ignore NoMethod
|
|
25
|
-
.beginning_of_this_week(beginning_of_week)
|
|
26
|
-
.beginning_of_day
|
|
27
|
-
end
|
|
22
|
+
def beginning_of_this_week = to_date.beginning_of_this_week.beginning_of_day
|
|
28
23
|
|
|
29
24
|
# 現在の日付が属する週の終わりの日付
|
|
30
|
-
|
|
31
|
-
# @param beginning_of_week 週の始まりの曜日。省略した場合は、config.beginning_of_weekの設定に従います。
|
|
32
|
-
def end_of_this_week(beginning_of_week = nil)
|
|
33
|
-
to_date # steep:ignore NoMethod
|
|
34
|
-
.next_week
|
|
35
|
-
.beginning_of_this_week(beginning_of_week)
|
|
36
|
-
.yesterday
|
|
37
|
-
.end_of_day
|
|
38
|
-
end
|
|
25
|
+
def end_of_this_week = to_date.next_week.beginning_of_this_week.yesterday.end_of_day
|
|
39
26
|
|
|
40
27
|
# 今週の期間
|
|
41
|
-
|
|
42
|
-
# @param beginning_of_week 週の始まりの曜日。省略した場合は、config.beginning_of_weekの設定に従います。
|
|
43
|
-
def all_this_week(beginning_of_week = nil)
|
|
44
|
-
::Range.new(
|
|
45
|
-
beginning_of_this_week(beginning_of_week),
|
|
46
|
-
end_of_this_week(beginning_of_week)
|
|
47
|
-
)
|
|
48
|
-
end
|
|
28
|
+
def all_this_week = ::Range.new(beginning_of_this_week, end_of_this_week)
|
|
49
29
|
|
|
50
30
|
# #############################################################################################################
|
|
51
31
|
# 月関係
|
|
@@ -136,6 +116,10 @@ module Decentworks
|
|
|
136
116
|
# 暦月関係
|
|
137
117
|
#
|
|
138
118
|
|
|
119
|
+
#
|
|
120
|
+
# 1月
|
|
121
|
+
#
|
|
122
|
+
|
|
139
123
|
# 1月の月初
|
|
140
124
|
def beginning_of_january = to_date.beginning_of_january.beginning_of_day # steep:ignore NoMethod
|
|
141
125
|
|
|
@@ -145,6 +129,19 @@ module Decentworks
|
|
|
145
129
|
# 1月の期間
|
|
146
130
|
def all_january = ::Range.new(beginning_of_january, end_of_january)
|
|
147
131
|
|
|
132
|
+
# 1月の月初か?
|
|
133
|
+
def beginning_of_january? = beginning_of_january.all_day.cover?(self)
|
|
134
|
+
|
|
135
|
+
# 1月の月末か?
|
|
136
|
+
def end_of_january? = end_of_january.all_day.cover?(self)
|
|
137
|
+
|
|
138
|
+
# 1月か?
|
|
139
|
+
def in_january? = all_january.cover?(self)
|
|
140
|
+
|
|
141
|
+
#
|
|
142
|
+
# 2月
|
|
143
|
+
#
|
|
144
|
+
|
|
148
145
|
# 2月の月初
|
|
149
146
|
def beginning_of_february = to_date.beginning_of_february.beginning_of_day # steep:ignore NoMethod
|
|
150
147
|
|
|
@@ -154,6 +151,19 @@ module Decentworks
|
|
|
154
151
|
# 2月の期間
|
|
155
152
|
def all_february = ::Range.new(beginning_of_february, end_of_february)
|
|
156
153
|
|
|
154
|
+
# 2月の月初か?
|
|
155
|
+
def beginning_of_february? = beginning_of_february.all_day.cover?(self)
|
|
156
|
+
|
|
157
|
+
# 2月の月末か?
|
|
158
|
+
def end_of_february? = end_of_february.all_day.cover?(self)
|
|
159
|
+
|
|
160
|
+
# 2月か?
|
|
161
|
+
def in_february? = all_february.cover?(self)
|
|
162
|
+
|
|
163
|
+
#
|
|
164
|
+
# 3月
|
|
165
|
+
#
|
|
166
|
+
|
|
157
167
|
# 3月の月初
|
|
158
168
|
def beginning_of_march = to_date.beginning_of_march.beginning_of_day # steep:ignore NoMethod
|
|
159
169
|
|
|
@@ -163,6 +173,19 @@ module Decentworks
|
|
|
163
173
|
# 3月の期間
|
|
164
174
|
def all_march = ::Range.new(beginning_of_march, end_of_march)
|
|
165
175
|
|
|
176
|
+
# 3月の月初か?
|
|
177
|
+
def beginning_of_march? = beginning_of_march.all_day.cover?(self)
|
|
178
|
+
|
|
179
|
+
# 3月の月末か?
|
|
180
|
+
def end_of_march? = end_of_march.all_day.cover?(self)
|
|
181
|
+
|
|
182
|
+
# 3月か?
|
|
183
|
+
def in_march? = all_march.cover?(self)
|
|
184
|
+
|
|
185
|
+
#
|
|
186
|
+
# 4月
|
|
187
|
+
#
|
|
188
|
+
|
|
166
189
|
# 4月の月初
|
|
167
190
|
def beginning_of_april = to_date.beginning_of_april.beginning_of_day # steep:ignore NoMethod
|
|
168
191
|
|
|
@@ -172,6 +195,19 @@ module Decentworks
|
|
|
172
195
|
# 4月の期間
|
|
173
196
|
def all_april = ::Range.new(beginning_of_april, end_of_april)
|
|
174
197
|
|
|
198
|
+
# 4月の月初か?
|
|
199
|
+
def beginning_of_april? = beginning_of_april.all_day.cover?(self)
|
|
200
|
+
|
|
201
|
+
# 4月の月末か?
|
|
202
|
+
def end_of_april? = end_of_april.all_day.cover?(self)
|
|
203
|
+
|
|
204
|
+
# 4月か?
|
|
205
|
+
def in_april? = all_april.cover?(self)
|
|
206
|
+
|
|
207
|
+
#
|
|
208
|
+
# 5月
|
|
209
|
+
#
|
|
210
|
+
|
|
175
211
|
# 5月の月初
|
|
176
212
|
def beginning_of_may = to_date.beginning_of_may.beginning_of_day # steep:ignore NoMethod
|
|
177
213
|
|
|
@@ -181,6 +217,19 @@ module Decentworks
|
|
|
181
217
|
# 5月の期間
|
|
182
218
|
def all_may = ::Range.new(beginning_of_may, end_of_may)
|
|
183
219
|
|
|
220
|
+
# 5月の月初か?
|
|
221
|
+
def beginning_of_may? = beginning_of_may.all_day.cover?(self)
|
|
222
|
+
|
|
223
|
+
# 5月の月末か?
|
|
224
|
+
def end_of_may? = end_of_may.all_day.cover?(self)
|
|
225
|
+
|
|
226
|
+
# 5月か?
|
|
227
|
+
def in_may? = all_may.cover?(self)
|
|
228
|
+
|
|
229
|
+
#
|
|
230
|
+
# 6月
|
|
231
|
+
#
|
|
232
|
+
|
|
184
233
|
# 6月の月初
|
|
185
234
|
def beginning_of_june = to_date.beginning_of_june.beginning_of_day # steep:ignore NoMethod
|
|
186
235
|
|
|
@@ -190,6 +239,19 @@ module Decentworks
|
|
|
190
239
|
# 6月の期間
|
|
191
240
|
def all_june = ::Range.new(beginning_of_june, end_of_june)
|
|
192
241
|
|
|
242
|
+
# 6月の月初か?
|
|
243
|
+
def beginning_of_june? = beginning_of_june.all_day.cover?(self)
|
|
244
|
+
|
|
245
|
+
# 6月の月末か?
|
|
246
|
+
def end_of_june? = end_of_june.all_day.cover?(self)
|
|
247
|
+
|
|
248
|
+
# 6月か?
|
|
249
|
+
def in_june? = all_june.cover?(self)
|
|
250
|
+
|
|
251
|
+
#
|
|
252
|
+
# 7月
|
|
253
|
+
#
|
|
254
|
+
|
|
193
255
|
# 7月の月初
|
|
194
256
|
def beginning_of_july = to_date.beginning_of_july.beginning_of_day # steep:ignore NoMethod
|
|
195
257
|
|
|
@@ -199,6 +261,19 @@ module Decentworks
|
|
|
199
261
|
# 7月の期間
|
|
200
262
|
def all_july = ::Range.new(beginning_of_july, end_of_july)
|
|
201
263
|
|
|
264
|
+
# 7月の月初か?
|
|
265
|
+
def beginning_of_july? = beginning_of_july.all_day.cover?(self)
|
|
266
|
+
|
|
267
|
+
# 7月の月末か?
|
|
268
|
+
def end_of_july? = end_of_july.all_day.cover?(self)
|
|
269
|
+
|
|
270
|
+
# 7月か?
|
|
271
|
+
def in_july? = all_july.cover?(self)
|
|
272
|
+
|
|
273
|
+
#
|
|
274
|
+
# 8月
|
|
275
|
+
#
|
|
276
|
+
|
|
202
277
|
# 8月の月初
|
|
203
278
|
def beginning_of_august = to_date.beginning_of_august.beginning_of_day # steep:ignore NoMethod
|
|
204
279
|
|
|
@@ -208,6 +283,19 @@ module Decentworks
|
|
|
208
283
|
# 8月の期間
|
|
209
284
|
def all_august = ::Range.new(beginning_of_august, end_of_august)
|
|
210
285
|
|
|
286
|
+
# 8月の月初か?
|
|
287
|
+
def beginning_of_august? = beginning_of_august.all_day.cover?(self)
|
|
288
|
+
|
|
289
|
+
# 8月の月末か?
|
|
290
|
+
def end_of_august? = end_of_august.all_day.cover?(self)
|
|
291
|
+
|
|
292
|
+
# 8月か?
|
|
293
|
+
def in_august? = all_august.cover?(self)
|
|
294
|
+
|
|
295
|
+
#
|
|
296
|
+
# 9月
|
|
297
|
+
#
|
|
298
|
+
|
|
211
299
|
# 9月の月初
|
|
212
300
|
def beginning_of_september = to_date.beginning_of_september.beginning_of_day # steep:ignore NoMethod
|
|
213
301
|
|
|
@@ -217,6 +305,19 @@ module Decentworks
|
|
|
217
305
|
# 9月の期間
|
|
218
306
|
def all_september = ::Range.new(beginning_of_september, end_of_september)
|
|
219
307
|
|
|
308
|
+
# 9月の月初か?
|
|
309
|
+
def beginning_of_september? = beginning_of_september.all_day.cover?(self)
|
|
310
|
+
|
|
311
|
+
# 9月の月末か?
|
|
312
|
+
def end_of_september? = end_of_september.all_day.cover?(self)
|
|
313
|
+
|
|
314
|
+
# 9月か?
|
|
315
|
+
def in_september? = all_september.cover?(self)
|
|
316
|
+
|
|
317
|
+
#
|
|
318
|
+
# 10月
|
|
319
|
+
#
|
|
320
|
+
|
|
220
321
|
# 10月の月初
|
|
221
322
|
def beginning_of_october = to_date.beginning_of_october.beginning_of_day # steep:ignore NoMethod
|
|
222
323
|
|
|
@@ -226,6 +327,19 @@ module Decentworks
|
|
|
226
327
|
# 10月の期間
|
|
227
328
|
def all_october = ::Range.new(beginning_of_october, end_of_october)
|
|
228
329
|
|
|
330
|
+
# 10月の月初か?
|
|
331
|
+
def beginning_of_october? = beginning_of_october.all_day.cover?(self)
|
|
332
|
+
|
|
333
|
+
# 10月の月末か?
|
|
334
|
+
def end_of_october? = end_of_october.all_day.cover?(self)
|
|
335
|
+
|
|
336
|
+
# 10月か?
|
|
337
|
+
def in_october? = all_october.cover?(self)
|
|
338
|
+
|
|
339
|
+
#
|
|
340
|
+
# 11月
|
|
341
|
+
#
|
|
342
|
+
|
|
229
343
|
# 11月の月初
|
|
230
344
|
def beginning_of_november = to_date.beginning_of_november.beginning_of_day # steep:ignore NoMethod
|
|
231
345
|
|
|
@@ -235,6 +349,19 @@ module Decentworks
|
|
|
235
349
|
# 11月の期間
|
|
236
350
|
def all_november = ::Range.new(beginning_of_november, end_of_november)
|
|
237
351
|
|
|
352
|
+
# 11月の月初か?
|
|
353
|
+
def beginning_of_november? = beginning_of_november.all_day.cover?(self)
|
|
354
|
+
|
|
355
|
+
# 11月の月末か?
|
|
356
|
+
def end_of_november? = end_of_november.all_day.cover?(self)
|
|
357
|
+
|
|
358
|
+
# 11月か?
|
|
359
|
+
def in_november? = all_november.cover?(self)
|
|
360
|
+
|
|
361
|
+
#
|
|
362
|
+
# 12月
|
|
363
|
+
#
|
|
364
|
+
|
|
238
365
|
# 12月の月初
|
|
239
366
|
def beginning_of_december = to_date.beginning_of_december.beginning_of_day # steep:ignore NoMethod
|
|
240
367
|
|
|
@@ -244,67 +371,154 @@ module Decentworks
|
|
|
244
371
|
# 12月の期間
|
|
245
372
|
def all_december = ::Range.new(beginning_of_december, end_of_december)
|
|
246
373
|
|
|
374
|
+
# 12月の月初か?
|
|
375
|
+
def beginning_of_december? = beginning_of_december.all_day.cover?(self)
|
|
376
|
+
|
|
377
|
+
# 12月の月末か?
|
|
378
|
+
def end_of_december? = end_of_december.all_day.cover?(self)
|
|
379
|
+
|
|
380
|
+
# 12月か?
|
|
381
|
+
def in_december? = all_december.cover?(self)
|
|
382
|
+
|
|
247
383
|
# #############################################################################################################
|
|
248
384
|
# 四半期関係
|
|
249
385
|
# #############################################################################################################
|
|
250
386
|
|
|
251
|
-
#
|
|
252
|
-
|
|
387
|
+
#
|
|
388
|
+
# 第1四半期
|
|
389
|
+
#
|
|
390
|
+
|
|
391
|
+
# 第1四半期の期首
|
|
392
|
+
def beginning_of_first_quarter = to_date.beginning_of_first_quarter.beginning_of_day
|
|
253
393
|
|
|
254
|
-
# 第1
|
|
255
|
-
|
|
394
|
+
# 第1四半期の期末
|
|
395
|
+
def end_of_first_quarter = to_date.end_of_first_quarter.end_of_day
|
|
256
396
|
|
|
257
397
|
# 第1四半期の期間
|
|
258
398
|
def all_first_quarter = ::Range.new(beginning_of_first_quarter, end_of_first_quarter)
|
|
259
399
|
|
|
260
|
-
# 第
|
|
261
|
-
|
|
400
|
+
# 第1四半期の期首か?
|
|
401
|
+
def beginning_of_first_quarter? = beginning_of_first_quarter.all_day.cover?(self)
|
|
402
|
+
|
|
403
|
+
# 第1四半期の期末か?
|
|
404
|
+
def end_of_first_quarter? = end_of_first_quarter.all_day.cover?(self)
|
|
405
|
+
|
|
406
|
+
# 第1四半期か?
|
|
407
|
+
def in_first_quarter? = all_first_quarter.cover?(self)
|
|
408
|
+
|
|
409
|
+
#
|
|
410
|
+
# 第2四半期
|
|
411
|
+
#
|
|
262
412
|
|
|
263
|
-
# 第2
|
|
264
|
-
|
|
413
|
+
# 第2四半期の期首
|
|
414
|
+
def beginning_of_second_quarter = to_date.beginning_of_second_quarter.beginning_of_day
|
|
415
|
+
|
|
416
|
+
# 第2四半期の期末
|
|
417
|
+
def end_of_second_quarter = to_date.end_of_second_quarter.end_of_day
|
|
265
418
|
|
|
266
419
|
# 第2四半期の期間
|
|
267
420
|
def all_second_quarter = ::Range.new(beginning_of_second_quarter, end_of_second_quarter)
|
|
268
421
|
|
|
269
|
-
# 第
|
|
270
|
-
|
|
422
|
+
# 第2四半期の期首か?
|
|
423
|
+
def beginning_of_second_quarter? = beginning_of_second_quarter.all_day.cover?(self)
|
|
424
|
+
|
|
425
|
+
# 第2四半期の期末か?
|
|
426
|
+
def end_of_second_quarter? = end_of_second_quarter.all_day.cover?(self)
|
|
427
|
+
|
|
428
|
+
# 第2四半期か?
|
|
429
|
+
def in_second_quarter? = all_second_quarter.cover?(self)
|
|
430
|
+
|
|
431
|
+
#
|
|
432
|
+
# 第3四半期
|
|
433
|
+
#
|
|
434
|
+
|
|
435
|
+
# 第3四半期の期首
|
|
436
|
+
def beginning_of_third_quarter = to_date.beginning_of_third_quarter.beginning_of_day
|
|
271
437
|
|
|
272
|
-
# 第3
|
|
273
|
-
|
|
438
|
+
# 第3四半期の期末
|
|
439
|
+
def end_of_third_quarter = to_date.end_of_third_quarter.end_of_day
|
|
274
440
|
|
|
275
441
|
# 第3四半期の期間
|
|
276
442
|
def all_third_quarter = ::Range.new(beginning_of_third_quarter, end_of_third_quarter)
|
|
277
443
|
|
|
278
|
-
# 第
|
|
279
|
-
|
|
444
|
+
# 第3四半期の期首か?
|
|
445
|
+
def beginning_of_third_quarter? = beginning_of_third_quarter.all_day.cover?(self)
|
|
280
446
|
|
|
281
|
-
# 第
|
|
282
|
-
|
|
447
|
+
# 第3四半期の期末か?
|
|
448
|
+
def end_of_third_quarter? = end_of_third_quarter.all_day.cover?(self)
|
|
449
|
+
|
|
450
|
+
# 第3四半期か?
|
|
451
|
+
def in_third_quarter? = all_third_quarter.cover?(self)
|
|
452
|
+
|
|
453
|
+
#
|
|
454
|
+
# 第4四半期
|
|
455
|
+
#
|
|
456
|
+
|
|
457
|
+
# 第4四半期の期首
|
|
458
|
+
def beginning_of_fourth_quarter = to_date.beginning_of_fourth_quarter.beginning_of_day
|
|
459
|
+
|
|
460
|
+
# 第4四半期の期末
|
|
461
|
+
def end_of_fourth_quarter = to_date.end_of_fourth_quarter.end_of_day
|
|
283
462
|
|
|
284
463
|
# 第4四半期の期間
|
|
285
464
|
def all_fourth_quarter = ::Range.new(beginning_of_fourth_quarter, end_of_fourth_quarter)
|
|
286
465
|
|
|
466
|
+
# 第4四半期の期首か?
|
|
467
|
+
def beginning_of_fourth_quarter? = beginning_of_fourth_quarter.all_day.cover?(self)
|
|
468
|
+
|
|
469
|
+
# 第4四半期の期末か?
|
|
470
|
+
def end_of_fourth_quarter? = end_of_fourth_quarter.all_day.cover?(self)
|
|
471
|
+
|
|
472
|
+
# 第4四半期か?
|
|
473
|
+
def in_fourth_quarter? = all_fourth_quarter.cover?(self)
|
|
474
|
+
|
|
287
475
|
# #############################################################################################################
|
|
288
476
|
# 上下期関係
|
|
289
477
|
# #############################################################################################################
|
|
290
478
|
|
|
291
|
-
#
|
|
479
|
+
#
|
|
480
|
+
# 上期
|
|
481
|
+
#
|
|
482
|
+
|
|
483
|
+
# 上期の期首
|
|
292
484
|
alias_method :beginning_of_first_half, :beginning_of_first_quarter
|
|
293
485
|
|
|
294
|
-
#
|
|
486
|
+
# 上期の期末
|
|
295
487
|
alias_method :end_of_first_half, :end_of_second_quarter
|
|
296
488
|
|
|
297
489
|
# 上期の期間
|
|
298
490
|
def all_first_half = ::Range.new(beginning_of_first_half, end_of_first_half)
|
|
299
491
|
|
|
300
|
-
#
|
|
492
|
+
# 上期の期首か?
|
|
493
|
+
def beginning_of_first_half? = beginning_of_first_half.all_day.cover?(self)
|
|
494
|
+
|
|
495
|
+
# 上期の期末か?
|
|
496
|
+
def end_of_first_half? = end_of_first_half.all_day.cover?(self)
|
|
497
|
+
|
|
498
|
+
# 上期か?
|
|
499
|
+
def in_first_half? = all_first_half.cover?(self)
|
|
500
|
+
|
|
501
|
+
#
|
|
502
|
+
# 下期
|
|
503
|
+
#
|
|
504
|
+
|
|
505
|
+
# 下期の期首
|
|
301
506
|
alias_method :beginning_of_second_half, :beginning_of_third_quarter
|
|
302
507
|
|
|
303
|
-
#
|
|
508
|
+
# 下期の期末
|
|
304
509
|
alias_method :end_of_second_half, :end_of_fourth_quarter
|
|
305
510
|
|
|
306
511
|
# 下期の期間
|
|
307
512
|
def all_second_half = ::Range.new(beginning_of_second_half, end_of_second_half)
|
|
513
|
+
|
|
514
|
+
# 下期の期首か?
|
|
515
|
+
def beginning_of_second_half? = beginning_of_second_half.all_day.cover?(self)
|
|
516
|
+
|
|
517
|
+
# 下期の期末か?
|
|
518
|
+
def end_of_second_half? = end_of_second_half.all_day.cover?(self)
|
|
519
|
+
|
|
520
|
+
# 下期か?
|
|
521
|
+
def in_second_half? = all_second_half.cover?(self)
|
|
308
522
|
end
|
|
309
523
|
|
|
310
524
|
refine ::ActiveSupport::TimeWithZone.singleton_class do
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
require "active_support/core_ext/module/delegation"
|
|
5
|
+
|
|
6
|
+
module Decentworks
|
|
7
|
+
module DateSupport
|
|
8
|
+
class << self
|
|
9
|
+
def configure
|
|
10
|
+
@configuration ||= Configuration.new
|
|
11
|
+
|
|
12
|
+
yield(@configuration) if block_given?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def configuration
|
|
16
|
+
raise "Initialization has not been performed." if @configuration.nil?
|
|
17
|
+
|
|
18
|
+
@configuration
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# 開始月名
|
|
22
|
+
delegate :beginning_of_first_quarter, to: :configuration
|
|
23
|
+
|
|
24
|
+
# 開始月数
|
|
25
|
+
delegate :beginning_of_first_quarter_month, to: :configuration
|
|
26
|
+
|
|
27
|
+
# 開始月の初期
|
|
28
|
+
def reset_configuration!
|
|
29
|
+
@configuration = nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# 1月始まりとの開始月のずれ
|
|
33
|
+
delegate :first_quarter_month_offset, to: :configuration
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class Configuration
|
|
37
|
+
# { january: 1, february: 2, ... december: 12 }
|
|
38
|
+
MONTHS = ::Date::MONTHNAMES
|
|
39
|
+
.each_with_index
|
|
40
|
+
.filter_map { |name, index| [name.downcase.to_sym, index] if name }
|
|
41
|
+
.to_h
|
|
42
|
+
.freeze
|
|
43
|
+
|
|
44
|
+
# 開始月の初期値(1月)
|
|
45
|
+
DEFAULT = :january
|
|
46
|
+
|
|
47
|
+
# 開始月
|
|
48
|
+
attr_reader :beginning_of_first_quarter
|
|
49
|
+
|
|
50
|
+
def initialize
|
|
51
|
+
@beginning_of_first_quarter = DEFAULT
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def beginning_of_first_quarter=(month_name)
|
|
55
|
+
unless MONTHS.key?(month_name)
|
|
56
|
+
raise ::ArgumentError,
|
|
57
|
+
"beginning_of_first_quarter must be one of #{MONTHS.keys.inspect} (got #{month_name.inspect})"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
@beginning_of_first_quarter = month_name
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# 開始月数
|
|
64
|
+
def beginning_of_first_quarter_month = MONTHS.fetch(beginning_of_first_quarter)
|
|
65
|
+
|
|
66
|
+
# 1月始まりとの開始月のずれ
|
|
67
|
+
def first_quarter_month_offset
|
|
68
|
+
beginning_of_first_quarter_month - 1
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|