national_government_organization_holiday 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/lib/national_government_organization_holiday/duration.rb +34 -0
- data/lib/national_government_organization_holiday/integer_patch.rb +17 -0
- data/lib/national_government_organization_holiday/value.rb +30 -0
- data/lib/national_government_organization_holiday/version.rb +5 -0
- data/lib/national_government_organization_holiday.rb +4 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: debecd725d5fee2100ec5ccd6cf059ac2e17b6d97e78cd040945796df4d9ab58
|
4
|
+
data.tar.gz: 22a492ff126690b8beb69fb6aa12f2a08cc2938db0533f55cd149a5d5aceadb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4571f41199e20db4609253427282e5abee90a636749b5d6b91804be8404825f90e105120a63a4a1d4c9b87dd56b745ded7108cb4c4d9b299ac0df570d99971cf
|
7
|
+
data.tar.gz: 0c421e8bbfccced6f28fe3be1b25ebba64980f06dde10860424ad3e79330df597fef76f8a2a9372913883cc7cd001169a65331e97f5b386a9de0bb453d19a6f6
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.2
|
3
|
+
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
Layout/EndOfLine:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: lf
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- spec/**/*
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Lint/ScriptPermission:
|
18
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
national_government_organization_holiday (1.0.0)
|
5
|
+
activesupport (~> 7.0)
|
6
|
+
holiday_japan (~> 1.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (7.0.5)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 1.6, < 2)
|
14
|
+
minitest (>= 5.1)
|
15
|
+
tzinfo (~> 2.0)
|
16
|
+
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.2.2)
|
18
|
+
diff-lcs (1.5.0)
|
19
|
+
holiday_japan (1.4.4)
|
20
|
+
i18n (1.14.1)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
json (2.6.3)
|
23
|
+
minitest (5.18.1)
|
24
|
+
parallel (1.23.0)
|
25
|
+
parser (3.2.2.3)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
racc
|
28
|
+
racc (1.7.1)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.8.1)
|
32
|
+
rexml (3.2.5)
|
33
|
+
rspec (3.12.0)
|
34
|
+
rspec-core (~> 3.12.0)
|
35
|
+
rspec-expectations (~> 3.12.0)
|
36
|
+
rspec-mocks (~> 3.12.0)
|
37
|
+
rspec-core (3.12.2)
|
38
|
+
rspec-support (~> 3.12.0)
|
39
|
+
rspec-expectations (3.12.3)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-mocks (3.12.5)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-support (3.12.0)
|
46
|
+
rubocop (1.52.1)
|
47
|
+
json (~> 2.3)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.2.2.3)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml (>= 3.2.5, < 4.0)
|
53
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.29.0)
|
57
|
+
parser (>= 3.2.1.0)
|
58
|
+
ruby-progressbar (1.13.0)
|
59
|
+
tzinfo (2.0.6)
|
60
|
+
concurrent-ruby (~> 1.0)
|
61
|
+
unicode-display_width (2.4.2)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
x64-mingw-ucrt
|
65
|
+
x86_64-linux
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
national_government_organization_holiday!
|
69
|
+
rake (~> 13.0)
|
70
|
+
rspec (~> 3.0)
|
71
|
+
rubocop (~> 1.21)
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.4.10
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Minoru Maeda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# NationalGovernmentOrganizationHoliday
|
2
|
+
|
3
|
+
[行政機関の休日](https://elaws.e-gov.go.jp/document?lawid=363AC0000000091) を計算するgemです。
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add national_government_organization_holiday
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install national_government_organization_holiday
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Date.new(2023, 12, 27) + 2.national_gov_org_weekdays
|
19
|
+
#=> 2024-01-04
|
20
|
+
|
21
|
+
Date.new(2023, 12, 29).on_weekday?
|
22
|
+
#=> true
|
23
|
+
value = NationalGovernmentOrganizationHoliday::Value
|
24
|
+
value.new(Date.new(2023, 12, 29)).on_weekday?
|
25
|
+
#=> false
|
26
|
+
```
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
`e.g. docker run -it -v $PWD/national_government_organization_holiday:/opt ruby:3.2 bash`
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/maeda-m/national_government_organization_holiday.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'value'
|
4
|
+
require 'active_support/duration'
|
5
|
+
|
6
|
+
module NationalGovernmentOrganizationHoliday
|
7
|
+
class Duration < ActiveSupport::Duration
|
8
|
+
MIN_PLUS_DAYS = 1
|
9
|
+
MAX_PLUS_DAYS = 7
|
10
|
+
|
11
|
+
def initialize(plus_days)
|
12
|
+
raise TypeError unless plus_days.is_a?(Integer)
|
13
|
+
raise ArgumentError unless (MIN_PLUS_DAYS..MAX_PLUS_DAYS).cover?(plus_days)
|
14
|
+
|
15
|
+
# See: https://github.com/rails/rails/blob/v7.0.4.3/activesupport/lib/active_support/duration.rb#L166-L167
|
16
|
+
super(plus_days * SECONDS_PER_DAY, { days: plus_days }, true)
|
17
|
+
end
|
18
|
+
|
19
|
+
# See: https://github.com/rails/rails/blob/v7.0.4.3/activesupport/lib/active_support/core_ext/date/calculations.rb#L90-L98
|
20
|
+
def since(beginning_day)
|
21
|
+
weekdays = []
|
22
|
+
|
23
|
+
plus_days = parts[:days]
|
24
|
+
max_day = beginning_day.next_month
|
25
|
+
beginning_day.next.upto(max_day) do |next_day|
|
26
|
+
weekdays << next_day if Value.new(next_day).on_weekday?
|
27
|
+
|
28
|
+
break if weekdays.count == plus_days
|
29
|
+
end
|
30
|
+
|
31
|
+
weekdays.last
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'duration'
|
4
|
+
require 'active_support/core_ext/numeric/time'
|
5
|
+
|
6
|
+
module NationalGovernmentOrganizationHoliday
|
7
|
+
module IntegerPatch
|
8
|
+
def national_gov_org_weekdays
|
9
|
+
NationalGovernmentOrganizationHoliday::Duration.new(self)
|
10
|
+
end
|
11
|
+
alias national_gov_org_weekday national_gov_org_weekdays
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
NationalGovernmentOrganizationHoliday::IntegerPatch.then do |mod|
|
16
|
+
Integer.send(:prepend, mod) unless Integer.include?(mod)
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'holiday_japan'
|
4
|
+
|
5
|
+
module NationalGovernmentOrganizationHoliday
|
6
|
+
class Value
|
7
|
+
def initialize(value)
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
# See: https://elaws.e-gov.go.jp/document?lawid=363AC0000000091
|
12
|
+
def on_weekday?
|
13
|
+
return false if @value.on_weekend?
|
14
|
+
return false if on_new_year_holiday_season?
|
15
|
+
return false if @value.national_holiday?
|
16
|
+
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def on_new_year_holiday_season?
|
23
|
+
current_year = @value.year
|
24
|
+
new_year = Date.new(current_year, 1, 1)..Date.new(current_year, 1, 3)
|
25
|
+
year_end = Date.new(current_year, 12, 29)..Date.new(current_year, 12, 31)
|
26
|
+
|
27
|
+
new_year.cover?(@value) || year_end.cover?(@value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: national_government_organization_holiday
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Minoru Maeda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: holiday_japan
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".rspec"
|
48
|
+
- ".rubocop.yml"
|
49
|
+
- CHANGELOG.md
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/national_government_organization_holiday.rb
|
56
|
+
- lib/national_government_organization_holiday/duration.rb
|
57
|
+
- lib/national_government_organization_holiday/integer_patch.rb
|
58
|
+
- lib/national_government_organization_holiday/value.rb
|
59
|
+
- lib/national_government_organization_holiday/version.rb
|
60
|
+
homepage:
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
rubygems_mfa_required: 'true'
|
65
|
+
source_code_uri: https://github.com/maeda-m/national_government_organization_holiday
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.2.2
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.4.10
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: 行政機関の休日を計算する。
|
85
|
+
test_files: []
|