increments-schedule 0.16.1 → 0.17.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
2
  SHA256:
3
- metadata.gz: 273516dd5f8d88668dcdc503f160cbeb05771183ad1554d413bee129e6bfe88c
4
- data.tar.gz: '05476799e3a61e0e5305e9b2ec0d639cd254ff8cfe106713ce1a643795576c91'
3
+ metadata.gz: 82bb6909cb6c21c1c942ca749dd55b059c196d579a47a9c5ebc364e18c60ce2f
4
+ data.tar.gz: 3178e7321f0293c611a987fd93377c774ab68af96071b4e2917669be74725665
5
5
  SHA512:
6
- metadata.gz: f8a1ef7a936083a5151e92842bb04dfef915bc49beb0e5937a9db9f02c274a53911f338201649941c34a1c3a07345411118ccffe2a9eb40172139080bea55dfc
7
- data.tar.gz: a9a3df9e8feb60d151e7e0de0f24fc02642852712fa081ca757740c5e7236833f2295defbc69d0ef33a270a14d4b85826aa620595d31f10f66b03c9c7552671c
6
+ metadata.gz: 73875c7d926a760744b1ba833fa0dff3a73358dd7708d4eb1ad79d1529cd3986423d805637d396d1918c28b4c449a6fc90dad22deb18e68ddd7469f89916f090
7
+ data.tar.gz: f95a328aa00b00040a6567dd4826dc026eb426f1078bb3350eed1bb8fe643eccbf0ffbe5e057c1a01744da5141830b3f4a31e4310364c2b01a636c66f7255690
@@ -2,8 +2,7 @@ Layout/IndentArray:
2
2
  Enabled: false
3
3
 
4
4
  Metrics/BlockLength:
5
- Exclude:
6
- - spec/**/*.rb
5
+ Enabled: false
7
6
 
8
7
  Metrics/LineLength:
9
8
  Max: 100
@@ -45,14 +45,7 @@ module Increments
45
45
  end
46
46
 
47
47
  def winter_vacation_day?(date = Date.today)
48
- case date.month
49
- when 1
50
- first_three_days_or_adjoining_weekend?(date)
51
- when 12
52
- last_four_days_or_after_last_saturday?(date)
53
- else
54
- false
55
- end
48
+ WinterVacationSchedule.new(date).winter_vacation?
56
49
  end
57
50
 
58
51
  alias winter_vacation? winter_vacation_day?
@@ -71,25 +64,85 @@ module Increments
71
64
  end
72
65
  end
73
66
 
74
- private
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
75
71
 
76
- def first_three_days_or_adjoining_weekend?(date)
77
- jan_3 = ExtendedDate.new(date.year, 1, 3)
78
- return true if date <= jan_3
72
+ private
79
73
 
80
- first_sunday = ExtendedDate.new(date.year, 1, 1).find_next(&:sunday?)
81
- return false unless date.between?(jan_3, first_sunday)
74
+ def year_end_vacation
75
+ @year_end_vacation ||= YearEndVacation.new(date.year)
76
+ end
82
77
 
83
- jan_3.next_day.upto(first_sunday).all? { |d| weekend?(d) }
84
- end
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
85
106
 
86
- def last_four_days_or_after_last_saturday?(date)
87
- return true if date.day >= 28
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
88
116
 
89
- date >= ExtendedDate.new(date.year, 12, 31).find_previous(&:saturday?)
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
90
143
  end
91
144
 
92
- class ExtendedDate < Date
145
+ class Date < Date
93
146
  INFINITY_FUTURE = Date.new(10_000, 1, 1)
94
147
  INFINITY_PAST = Date.new(0, 1, 1)
95
148
 
@@ -1,5 +1,5 @@
1
1
  module Increments
2
2
  module Schedule
3
- VERSION = '0.16.1'
3
+ VERSION = '0.17.0'
4
4
  end
5
5
  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.16.1
4
+ version: 0.17.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: 2018-09-13 00:00:00.000000000 Z
11
+ date: 2018-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: holiday_japan