increments-schedule 0.13.2 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +22 -3
- data/.travis.yml +5 -2
- data/Gemfile +4 -2
- data/README.md +9 -10
- data/README.md.erb +5 -6
- data/Rakefile +3 -4
- data/bin/console +1 -0
- data/bin/setup +1 -0
- data/increments-schedule.gemspec +5 -4
- data/lib/increments/schedule.rb +17 -34
- data/lib/increments/schedule/date.rb +22 -0
- data/lib/increments/schedule/version.rb +3 -1
- data/lib/increments/schedule/winter_vacation_schedule.rb +91 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b172f3f34040984d943581777b5f72b5ee82ef0995d44b896684015d44e734e4
|
4
|
+
data.tar.gz: be80411c1e82320205c17954ff9d903d17208c3e5c0f537bf0cd3d343313fdb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66fcee8bdf9052e4f427a9788209993c33fb0e042d925ee3f890bc4a7da53cc4fef004b0bb639f332d0fef60c0b5c22c4a134c00368cd3f77ad15338040a7d2d
|
7
|
+
data.tar.gz: 465153b398642caa3739070baf258f481477f2ccf386e9ef2b77c04fb1e10af96278b566d2dc783e5df76637b600abb27d9d77a95080a8c54ec091246cff1a64
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,28 @@
|
|
1
|
+
Layout/FirstArrayElementIndentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/BlockLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Gemspec/RequiredRubyVersion:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Lint/ConstantDefinitionInBlock:
|
11
|
+
Enabled: false
|
12
|
+
|
1
13
|
Metrics/LineLength:
|
2
14
|
Max: 100
|
3
15
|
|
16
|
+
Naming/FileName:
|
17
|
+
Exclude:
|
18
|
+
- increments-schedule.gemspec
|
19
|
+
|
20
|
+
Naming/HeredocDelimiterNaming:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Naming/VariableNumber:
|
24
|
+
Enabled: false
|
25
|
+
|
4
26
|
Metrics/ModuleLength:
|
5
27
|
Enabled: false
|
6
28
|
|
@@ -13,9 +35,6 @@ Style/EmptyElse:
|
|
13
35
|
Style/GuardClause:
|
14
36
|
Enabled: false
|
15
37
|
|
16
|
-
Style/IndentArray:
|
17
|
-
Enabled: false
|
18
|
-
|
19
38
|
Style/MutableConstant:
|
20
39
|
Enabled: false
|
21
40
|
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gemspec
|
4
6
|
|
5
7
|
group :development, :test do
|
6
|
-
gem 'rake', '~>
|
8
|
+
gem 'rake', '~> 12.0'
|
7
9
|
gem 'rspec', '~> 3.2'
|
8
|
-
gem 'rubocop', '~> 0.
|
10
|
+
gem 'rubocop', '~> 0.52'
|
9
11
|
gem 'timecop', '~> 0.7'
|
10
12
|
end
|
11
13
|
|
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
[![Gem Version](http://img.shields.io/gem/v/increments-schedule.svg?style=flat)](http://badge.fury.io/rb/increments-schedule)
|
2
|
-
[![Dependency Status](http://img.shields.io/gemnasium/increments/increments-schedule.svg?style=flat)](https://gemnasium.com/increments/increments-schedule)
|
3
2
|
[![Build Status](https://travis-ci.org/increments/increments-schedule.svg?branch=master&style=flat)](https://travis-ci.org/increments/increments-schedule)
|
4
3
|
|
5
4
|
# Increments::Schedule
|
6
5
|
|
7
|
-
|
6
|
+
**Increments::Schedule** is a convenient library for checking Increments' company schedule.
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
@@ -31,26 +30,26 @@ $ gem install increments-schedule
|
|
31
30
|
### Predicate Methods
|
32
31
|
|
33
32
|
* `Increments::Schedule.foundation_anniversary?(date = Date.today)`
|
34
|
-
* `Increments::Schedule.
|
33
|
+
* `Increments::Schedule.holiday?(date = Date.today)`
|
35
34
|
* `Increments::Schedule.pay_day?(date = Date.today)`
|
36
|
-
* `Increments::Schedule.work_day?(date = Date.today)`
|
37
35
|
* `Increments::Schedule.remote_work_day?(date = Date.today)`
|
38
36
|
* `Increments::Schedule.rest_day?(date = Date.today)`
|
37
|
+
* `Increments::Schedule.super_hanakin?(date = Date.today)`
|
39
38
|
* `Increments::Schedule.weekend?(date = Date.today)`
|
40
|
-
* `Increments::Schedule.
|
41
|
-
* `Increments::Schedule.
|
39
|
+
* `Increments::Schedule.winter_vacation_day?(date = Date.today)`
|
40
|
+
* `Increments::Schedule.work_day?(date = Date.today)`
|
42
41
|
|
43
42
|
### Enumeration Methods
|
44
43
|
|
45
44
|
* `Increments::Schedule.each_foundation_anniversary(max_date = Date.today + 365)`
|
46
|
-
* `Increments::Schedule.
|
45
|
+
* `Increments::Schedule.each_holiday(max_date = Date.today + 365)`
|
47
46
|
* `Increments::Schedule.each_pay_day(max_date = Date.today + 365)`
|
48
|
-
* `Increments::Schedule.each_work_day(max_date = Date.today + 365)`
|
49
47
|
* `Increments::Schedule.each_remote_work_day(max_date = Date.today + 365)`
|
50
48
|
* `Increments::Schedule.each_rest_day(max_date = Date.today + 365)`
|
49
|
+
* `Increments::Schedule.each_super_hanakin(max_date = Date.today + 365)`
|
51
50
|
* `Increments::Schedule.each_weekend(max_date = Date.today + 365)`
|
52
|
-
* `Increments::Schedule.
|
53
|
-
* `Increments::Schedule.
|
51
|
+
* `Increments::Schedule.each_winter_vacation_day(max_date = Date.today + 365)`
|
52
|
+
* `Increments::Schedule.each_work_day(max_date = Date.today + 365)`
|
54
53
|
|
55
54
|
## Development
|
56
55
|
|
data/README.md.erb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
[![Gem Version](http://img.shields.io/gem/v/increments-schedule.svg?style=flat)](http://badge.fury.io/rb/increments-schedule)
|
2
|
-
[![Dependency Status](http://img.shields.io/gemnasium/increments/increments-schedule.svg?style=flat)](https://gemnasium.com/increments/increments-schedule)
|
3
2
|
[![Build Status](https://travis-ci.org/increments/increments-schedule.svg?branch=master&style=flat)](https://travis-ci.org/increments/increments-schedule)
|
4
3
|
|
5
4
|
# Increments::Schedule
|
6
5
|
|
7
|
-
|
6
|
+
**Increments::Schedule** is a convenient library for checking Increments' company schedule.
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
@@ -32,8 +31,8 @@ $ gem install increments-schedule
|
|
32
31
|
|
33
32
|
<%=
|
34
33
|
methods = Increments::Schedule.public_instance_methods.select do |method|
|
35
|
-
method.to_s.end_with?('?')
|
36
|
-
end
|
34
|
+
method.to_s.end_with?('?') && method != :winter_vacation?
|
35
|
+
end.sort
|
37
36
|
|
38
37
|
methods.map do |method|
|
39
38
|
"* `Increments::Schedule.#{method}(date = Date.today)`"
|
@@ -44,8 +43,8 @@ end.join("\n")
|
|
44
43
|
|
45
44
|
<%=
|
46
45
|
methods = Increments::Schedule.public_instance_methods.select do |method|
|
47
|
-
method.to_s.start_with?('each_')
|
48
|
-
end
|
46
|
+
method.to_s.start_with?('each_') && method != :each_winter_vacation
|
47
|
+
end.sort
|
49
48
|
|
50
49
|
methods.map do |method|
|
51
50
|
"* `Increments::Schedule.#{method}(max_date = Date.today + 365)`"
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
require 'rubocop/rake_task'
|
@@ -41,7 +43,4 @@ def generate_readme
|
|
41
43
|
erb.result(binding)
|
42
44
|
end
|
43
45
|
|
44
|
-
|
45
|
-
# For some reason MRI 2.3 returns the method list with different order.
|
46
|
-
ci_tasks << 'readme:validate' if RUBY_VERSION.start_with?('2.2.')
|
47
|
-
task ci: ci_tasks
|
46
|
+
task ci: %w[spec rubocop readme:validate]
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/increments-schedule.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'increments/schedule/version'
|
5
6
|
|
@@ -9,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Yuji Nakayama']
|
10
11
|
spec.email = ['nkymyj@gmail.com']
|
11
12
|
|
12
|
-
spec.summary = "Increments' schedule"
|
13
|
+
spec.summary = "Convenient library for checking Increments' company schedule"
|
13
14
|
spec.description = spec.summary
|
14
15
|
spec.homepage = 'https://github.com/increments/increments-schedule'
|
15
16
|
spec.license = 'MIT'
|
@@ -21,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
21
22
|
|
22
23
|
spec.add_runtime_dependency 'holiday_japan', '~> 1.1'
|
23
24
|
|
24
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.2'
|
25
26
|
end
|
data/lib/increments/schedule.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'increments/schedule/date'
|
1
4
|
require 'increments/schedule/version'
|
5
|
+
require 'increments/schedule/winter_vacation_schedule'
|
2
6
|
require 'holiday_japan'
|
3
7
|
|
4
8
|
module Increments
|
5
9
|
module Schedule
|
6
|
-
extend self # rubocop:disable ModuleFunction
|
10
|
+
extend self # rubocop:disable Style/ModuleFunction
|
7
11
|
|
8
12
|
def foundation_anniversary?(date = Date.today)
|
9
13
|
date.month == 2 && date.day == 29
|
@@ -14,9 +18,10 @@ module Increments
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def pay_day?(date = Date.today)
|
17
|
-
return work_day?(date) if date.day ==
|
21
|
+
return work_day?(date) if date.day == 15
|
18
22
|
return false if rest_day?(date)
|
19
|
-
|
23
|
+
|
24
|
+
next_basic_pay_day = Date.new(date.year, date.month, 15)
|
20
25
|
next_basic_pay_day = next_basic_pay_day.next_month if date > next_basic_pay_day
|
21
26
|
date.next_day.upto(next_basic_pay_day).all? do |date_until_basic_pay_day|
|
22
27
|
rest_day?(date_until_basic_pay_day)
|
@@ -27,10 +32,12 @@ module Increments
|
|
27
32
|
!rest_day?(date)
|
28
33
|
end
|
29
34
|
|
30
|
-
|
35
|
+
def remote_work_day?(date = Date.today)
|
36
|
+
date.wednesday? && work_day?(date)
|
37
|
+
end
|
31
38
|
|
32
39
|
def rest_day?(date = Date.today)
|
33
|
-
weekend?(date) || holiday?(date) ||
|
40
|
+
weekend?(date) || holiday?(date) || winter_vacation_day?(date)
|
34
41
|
end
|
35
42
|
|
36
43
|
def weekend?(date = Date.today)
|
@@ -41,21 +48,14 @@ module Increments
|
|
41
48
|
HolidayJapan.check(date)
|
42
49
|
end
|
43
50
|
|
44
|
-
def
|
45
|
-
|
46
|
-
when 1
|
47
|
-
return true if date.day <= 3
|
48
|
-
date <= ExtendedDate.new(date.year, 1, 1).find_next(&:sunday?)
|
49
|
-
when 12
|
50
|
-
return true if date.day >= 28
|
51
|
-
date >= ExtendedDate.new(date.year, 12, 31).find_previous(&:saturday?)
|
52
|
-
else
|
53
|
-
false
|
54
|
-
end
|
51
|
+
def winter_vacation_day?(date = Date.today)
|
52
|
+
WinterVacationSchedule.winter_vacation?(date)
|
55
53
|
end
|
56
54
|
|
55
|
+
alias winter_vacation? winter_vacation_day?
|
56
|
+
|
57
57
|
public_instance_methods.select { |name| name.to_s.end_with?('?') }.each do |predicate_method|
|
58
|
-
enumeration_method =
|
58
|
+
enumeration_method = "each_#{predicate_method.to_s.sub(/\?\z/, '')}"
|
59
59
|
|
60
60
|
define_method(enumeration_method) do |max_date = nil, &block|
|
61
61
|
return to_enum(__method__, max_date) unless block
|
@@ -67,22 +67,5 @@ module Increments
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
71
|
-
class ExtendedDate < Date
|
72
|
-
INFINITY_FUTURE = Date.new(10_000, 1, 1)
|
73
|
-
INFINITY_PAST = Date.new(0, 1, 1)
|
74
|
-
|
75
|
-
def find_next
|
76
|
-
upto(INFINITY_FUTURE) do |date|
|
77
|
-
break date if yield date
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def find_previous
|
82
|
-
downto(INFINITY_PAST) do |date|
|
83
|
-
break date if yield date
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
70
|
end
|
88
71
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Increments
|
4
|
+
module Schedule
|
5
|
+
class Date < ::Date
|
6
|
+
INFINITY_FUTURE = Date.new(10_000, 1, 1)
|
7
|
+
INFINITY_PAST = Date.new(0, 1, 1)
|
8
|
+
|
9
|
+
def find_next
|
10
|
+
upto(INFINITY_FUTURE) do |date|
|
11
|
+
break date if yield date
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_previous
|
16
|
+
downto(INFINITY_PAST) do |date|
|
17
|
+
break date if yield date
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Increments
|
4
|
+
module Schedule
|
5
|
+
WinterVacationSchedule = Struct.new(:date) do
|
6
|
+
def self.winter_vacation?(date)
|
7
|
+
new(date).winter_vacation?
|
8
|
+
end
|
9
|
+
|
10
|
+
def winter_vacation?
|
11
|
+
year_end_vacation.days.include?(date) || new_year_vacation.days.include?(date)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def year_end_vacation
|
17
|
+
@year_end_vacation ||= YearEndVacation.new(date.year)
|
18
|
+
end
|
19
|
+
|
20
|
+
def new_year_vacation
|
21
|
+
@new_year_vacation ||= NewYearVacation.new(date.year)
|
22
|
+
end
|
23
|
+
|
24
|
+
YearEndVacation = Struct.new(:year) do
|
25
|
+
def days
|
26
|
+
beginning_day..dec_31
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def beginning_day
|
32
|
+
if coupled_new_year_vacation.days.count >= 5
|
33
|
+
last_saturday
|
34
|
+
else
|
35
|
+
[dec_28, last_saturday].min
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def dec_28
|
40
|
+
@dec_28 ||= Date.new(year, 12, 28)
|
41
|
+
end
|
42
|
+
|
43
|
+
def dec_31
|
44
|
+
@dec_31 ||= Date.new(year, 12, 31)
|
45
|
+
end
|
46
|
+
|
47
|
+
def last_saturday
|
48
|
+
@last_saturday ||= dec_31.find_previous(&:saturday?)
|
49
|
+
end
|
50
|
+
|
51
|
+
def coupled_new_year_vacation
|
52
|
+
@coupled_new_year_vacation ||= NewYearVacation.new(year + 1)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
NewYearVacation = Struct.new(:year) do
|
57
|
+
def days
|
58
|
+
jan_1..end_day
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def end_day
|
64
|
+
return jan_3 if first_sunday <= jan_3
|
65
|
+
|
66
|
+
if first_weekend_almost_adjoins_jan_3?
|
67
|
+
first_sunday
|
68
|
+
else
|
69
|
+
jan_3
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def first_weekend_almost_adjoins_jan_3?
|
74
|
+
jan_3.next_day.upto(first_sunday).all? { |d| d.friday? || d.saturday? || d.sunday? }
|
75
|
+
end
|
76
|
+
|
77
|
+
def first_sunday
|
78
|
+
@first_sunday ||= jan_1.find_next(&:sunday?)
|
79
|
+
end
|
80
|
+
|
81
|
+
def jan_1
|
82
|
+
@jan_1 ||= Date.new(year, 1, 1)
|
83
|
+
end
|
84
|
+
|
85
|
+
def jan_3
|
86
|
+
@jan_3 ||= Date.new(year, 1, 3)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: increments-schedule
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: holiday_japan
|
@@ -30,15 +30,15 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
description: Increments' schedule
|
40
|
+
version: '2.2'
|
41
|
+
description: Convenient library for checking Increments' company schedule
|
42
42
|
email:
|
43
43
|
- nkymyj@gmail.com
|
44
44
|
executables: []
|
@@ -58,7 +58,9 @@ files:
|
|
58
58
|
- bin/setup
|
59
59
|
- increments-schedule.gemspec
|
60
60
|
- lib/increments/schedule.rb
|
61
|
+
- lib/increments/schedule/date.rb
|
61
62
|
- lib/increments/schedule/version.rb
|
63
|
+
- lib/increments/schedule/winter_vacation_schedule.rb
|
62
64
|
homepage: https://github.com/increments/increments-schedule
|
63
65
|
licenses:
|
64
66
|
- MIT
|
@@ -78,9 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
80
|
- !ruby/object:Gem::Version
|
79
81
|
version: '0'
|
80
82
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.6.8
|
83
|
+
rubygems_version: 3.0.3
|
83
84
|
signing_key:
|
84
85
|
specification_version: 4
|
85
|
-
summary: Increments' schedule
|
86
|
+
summary: Convenient library for checking Increments' company schedule
|
86
87
|
test_files: []
|