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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6ed9a60f8d0e1e98939183fb197dbd40e50bf261
4
- data.tar.gz: 27cf83e11edd682076f325f6112b9c06b14d3e69
2
+ SHA256:
3
+ metadata.gz: b172f3f34040984d943581777b5f72b5ee82ef0995d44b896684015d44e734e4
4
+ data.tar.gz: be80411c1e82320205c17954ff9d903d17208c3e5c0f537bf0cd3d343313fdb8
5
5
  SHA512:
6
- metadata.gz: 2b41c6f417c1fc3c5dcb9125e28b1328d118979fffe8940810b57586e5378bb9803aac7af5f44afe2766e913953e7adbf90af039f75edd01906473556082092b
7
- data.tar.gz: e096e1f259d6ba2c5ebedecdd089326468aa900b1842156e2ae21b6ae35c741c5cda114640d0d3622ecc61b7c3033bead5b897c6fb30edbe0d51b0e27bb65f29
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
@@ -1,7 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
- - 2.3.0
3
+ - 2.5.7
4
+ - 2.6.7
5
+ - 2.7.2
6
+ before_install:
7
+ - gem update bundler
5
8
  script: bundle exec rake ci
6
9
  sudo: false
7
10
  cache: bundler
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', '~> 10.0'
8
+ gem 'rake', '~> 12.0'
7
9
  gem 'rspec', '~> 3.2'
8
- gem 'rubocop', '~> 0.30'
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
- Find out our special remote days and eagerly wait for them!
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.super_hanakin?(date = Date.today)`
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.holiday?(date = Date.today)`
41
- * `Increments::Schedule.winter_vacation?(date = Date.today)`
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.each_super_hanakin(max_date = Date.today + 365)`
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.each_holiday(max_date = Date.today + 365)`
53
- * `Increments::Schedule.each_winter_vacation(max_date = Date.today + 365)`
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
- Find out our special remote days and eagerly wait for them!
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
- ci_tasks = %w(spec rubocop)
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
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'increments/schedule'
data/bin/setup CHANGED
@@ -2,6 +2,7 @@
2
2
  set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
 
5
+ gem install bundler
5
6
  bundle install
6
7
 
7
8
  # Do any other automated setup that you need to do here
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
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', '~> 1.3'
25
+ spec.add_development_dependency 'bundler', '~> 2.2'
25
26
  end
@@ -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 == 25
21
+ return work_day?(date) if date.day == 15
18
22
  return false if rest_day?(date)
19
- next_basic_pay_day = Date.new(date.year, date.month, 25)
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
- alias remote_work_day? work_day?
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) || winter_vacation?(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 winter_vacation?(date = Date.today)
45
- case date.month
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 = 'each_' + predicate_method.to_s.sub(/\?\z/, '')
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
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Increments
2
4
  module Schedule
3
- VERSION = '0.13.2'
5
+ VERSION = '0.18.0'
4
6
  end
5
7
  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.13.2
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: 2016-12-23 00:00:00.000000000 Z
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: '1.3'
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: '1.3'
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
- rubyforge_project:
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: []