increments-schedule 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/.travis.yml +5 -3
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/bin/setup +1 -0
- data/increments-schedule.gemspec +3 -1
- data/lib/increments/schedule.rb +9 -100
- 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 +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
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,9 +1,15 @@
|
|
1
|
-
Layout/
|
1
|
+
Layout/FirstArrayElementIndentation:
|
2
2
|
Enabled: false
|
3
3
|
|
4
4
|
Metrics/BlockLength:
|
5
5
|
Enabled: false
|
6
6
|
|
7
|
+
Gemspec/RequiredRubyVersion:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Lint/ConstantDefinitionInBlock:
|
11
|
+
Enabled: false
|
12
|
+
|
7
13
|
Metrics/LineLength:
|
8
14
|
Max: 100
|
9
15
|
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/increments-schedule.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path('lib', __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require 'increments/schedule/version'
|
@@ -20,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
20
22
|
|
21
23
|
spec.add_runtime_dependency 'holiday_japan', '~> 1.1'
|
22
24
|
|
23
|
-
spec.add_development_dependency 'bundler', '~>
|
25
|
+
spec.add_development_dependency 'bundler', '~> 2.2'
|
24
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,10 +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
|
|
20
|
-
next_basic_pay_day = Date.new(date.year, date.month,
|
24
|
+
next_basic_pay_day = Date.new(date.year, date.month, 15)
|
21
25
|
next_basic_pay_day = next_basic_pay_day.next_month if date > next_basic_pay_day
|
22
26
|
date.next_day.upto(next_basic_pay_day).all? do |date_until_basic_pay_day|
|
23
27
|
rest_day?(date_until_basic_pay_day)
|
@@ -45,13 +49,13 @@ module Increments
|
|
45
49
|
end
|
46
50
|
|
47
51
|
def winter_vacation_day?(date = Date.today)
|
48
|
-
WinterVacationSchedule.
|
52
|
+
WinterVacationSchedule.winter_vacation?(date)
|
49
53
|
end
|
50
54
|
|
51
55
|
alias winter_vacation? winter_vacation_day?
|
52
56
|
|
53
57
|
public_instance_methods.select { |name| name.to_s.end_with?('?') }.each do |predicate_method|
|
54
|
-
enumeration_method =
|
58
|
+
enumeration_method = "each_#{predicate_method.to_s.sub(/\?\z/, '')}"
|
55
59
|
|
56
60
|
define_method(enumeration_method) do |max_date = nil, &block|
|
57
61
|
return to_enum(__method__, max_date) unless block
|
@@ -63,100 +67,5 @@ module Increments
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
66
|
-
|
67
|
-
WinterVacationSchedule = Struct.new(:date) do
|
68
|
-
def winter_vacation?
|
69
|
-
year_end_vacation.days.include?(date) || new_year_vacation.days.include?(date)
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def year_end_vacation
|
75
|
-
@year_end_vacation ||= YearEndVacation.new(date.year)
|
76
|
-
end
|
77
|
-
|
78
|
-
def new_year_vacation
|
79
|
-
@new_year_vacation ||= NewYearVacation.new(date.year)
|
80
|
-
end
|
81
|
-
|
82
|
-
YearEndVacation = Struct.new(:year) do
|
83
|
-
def days
|
84
|
-
beginning_day..dec_31
|
85
|
-
end
|
86
|
-
|
87
|
-
def beginning_day
|
88
|
-
if coupled_new_year_vacation.days.count >= 5
|
89
|
-
last_saturday
|
90
|
-
else
|
91
|
-
[dec_28, last_saturday].min
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def dec_28
|
96
|
-
@dec_28 ||= Date.new(year, 12, 28)
|
97
|
-
end
|
98
|
-
|
99
|
-
def dec_31
|
100
|
-
@dec_31 ||= Date.new(year, 12, 31)
|
101
|
-
end
|
102
|
-
|
103
|
-
def last_saturday
|
104
|
-
@last_saturday ||= dec_31.find_previous(&:saturday?)
|
105
|
-
end
|
106
|
-
|
107
|
-
def coupled_new_year_vacation
|
108
|
-
@coupled_new_year_vacation ||= NewYearVacation.new(year + 1)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
NewYearVacation = Struct.new(:year) do
|
113
|
-
def days
|
114
|
-
jan_1..end_day
|
115
|
-
end
|
116
|
-
|
117
|
-
def end_day
|
118
|
-
return jan_3 if first_sunday <= jan_3
|
119
|
-
|
120
|
-
if first_weekend_almost_adjoins_jan_3?
|
121
|
-
first_sunday
|
122
|
-
else
|
123
|
-
jan_3
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def first_weekend_almost_adjoins_jan_3?
|
128
|
-
jan_3.next_day.upto(first_sunday).all? { |d| d.friday? || d.saturday? || d.sunday? }
|
129
|
-
end
|
130
|
-
|
131
|
-
def first_sunday
|
132
|
-
@first_sunday ||= jan_1.find_next(&:sunday?)
|
133
|
-
end
|
134
|
-
|
135
|
-
def jan_1
|
136
|
-
@jan_1 ||= Date.new(year, 1, 1)
|
137
|
-
end
|
138
|
-
|
139
|
-
def jan_3
|
140
|
-
@jan_3 ||= Date.new(year, 1, 3)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
class Date < Date
|
146
|
-
INFINITY_FUTURE = Date.new(10_000, 1, 1)
|
147
|
-
INFINITY_PAST = Date.new(0, 1, 1)
|
148
|
-
|
149
|
-
def find_next
|
150
|
-
upto(INFINITY_FUTURE) do |date|
|
151
|
-
break date if yield date
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def find_previous
|
156
|
-
downto(INFINITY_PAST) do |date|
|
157
|
-
break date if yield date
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
70
|
end
|
162
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,14 +30,14 @@ 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: '
|
40
|
+
version: '2.2'
|
41
41
|
description: Convenient library for checking Increments' company schedule
|
42
42
|
email:
|
43
43
|
- nkymyj@gmail.com
|
@@ -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,8 +80,7 @@ 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.7.7
|
83
|
+
rubygems_version: 3.0.3
|
83
84
|
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: Convenient library for checking Increments' company schedule
|