increments-schedule 0.7.2 → 0.8.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
  SHA1:
3
- metadata.gz: 5af9bc5241d6bb863be27b1f3cbb446eb527d0d9
4
- data.tar.gz: f25e5c329de7bf4093e877c777b89644e6f8b22a
3
+ metadata.gz: f13ed5fd026db1faec2d393c864ece53137b5a78
4
+ data.tar.gz: 4ba62e8a04fcc48e5aea04a6a882d8250d92e1c2
5
5
  SHA512:
6
- metadata.gz: 2c5654c4aee0faa6bd06f428e795d061f26f50320862a70bf386a7cd90a9aee457b89befc6bd516f603ea65e256fbbf8957975fbeccbf8a152a481bf31cbe0fc
7
- data.tar.gz: cac94e597dec58fd46af36f51a8b1b9bb9ca18c68843c24bbf735c24ffd395c8c6cb9f25731502ed245386521f2ca3579d5411fef9b92fc692dd7ed35e1a058b
6
+ metadata.gz: 56e40597aef88f79d7dff1788d433f2e2e08c905aabc4b98b69d9c062050838201cab436a1881bde6fc13c7b66136993e341e79cfe759661581d3a8064584a34
7
+ data.tar.gz: 91755ebd876d4a341815cd6e937314ed596e9759757ff4d6bd0ad525b57335a54d5310339dfb582f579a39f9e01bf0b97bed34d96f1f6526ab0fb679bd93779a
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
+ /spec/examples.txt
9
10
  /tmp/
data/README.md CHANGED
@@ -31,7 +31,6 @@ $ gem install increments-schedule
31
31
  ### Predicate Methods
32
32
 
33
33
  * `Increments::Schedule.super_hanakin?(date = Date.today)`
34
- * `Increments::Schedule.tgif_party_day?(date = Date.today)`
35
34
  * `Increments::Schedule.pay_day?(date = Date.today)`
36
35
  * `Increments::Schedule.work_day?(date = Date.today)`
37
36
  * `Increments::Schedule.office_work_day?(date = Date.today)`
@@ -41,11 +40,11 @@ $ gem install increments-schedule
41
40
  * `Increments::Schedule.rest_day?(date = Date.today)`
42
41
  * `Increments::Schedule.weekend?(date = Date.today)`
43
42
  * `Increments::Schedule.holiday?(date = Date.today)`
43
+ * `Increments::Schedule.winter_vacation?(date = Date.today)`
44
44
 
45
45
  ### Enumeration Methods
46
46
 
47
47
  * `Increments::Schedule.each_super_hanakin(max_date = Date.today + 365)`
48
- * `Increments::Schedule.each_tgif_party_day(max_date = Date.today + 365)`
49
48
  * `Increments::Schedule.each_pay_day(max_date = Date.today + 365)`
50
49
  * `Increments::Schedule.each_work_day(max_date = Date.today + 365)`
51
50
  * `Increments::Schedule.each_office_work_day(max_date = Date.today + 365)`
@@ -55,6 +54,7 @@ $ gem install increments-schedule
55
54
  * `Increments::Schedule.each_rest_day(max_date = Date.today + 365)`
56
55
  * `Increments::Schedule.each_weekend(max_date = Date.today + 365)`
57
56
  * `Increments::Schedule.each_holiday(max_date = Date.today + 365)`
57
+ * `Increments::Schedule.each_winter_vacation(max_date = Date.today + 365)`
58
58
  * `Increments::Schedule.each_work_time_range(max_date = Date.today + 365)`
59
59
 
60
60
  ## Development
@@ -5,26 +5,13 @@ module Increments
5
5
  module Schedule
6
6
  extend self # rubocop:disable ModuleFunction
7
7
 
8
- DATE_OF_SPECIAL_TGIF_PARTY = Date.new(2015, 6, 19)
9
- START_DATE_OF_NORMAL_TGIF_PARTY_SCHEDULE = Date.new(2015, 7, 1)
10
- DATE_RANGE_OF_YAPC_ASIA = Date.new(2015, 8, 20)..Date.new(2015, 8, 22)
8
+ INFINITY_FUTURE = Date.new(10_000, 1, 1)
9
+ INFINITY_PAST = Date.new(0, 1, 1)
11
10
 
12
11
  def super_hanakin?(date = Date.today)
13
12
  date.friday? && pay_day?(date)
14
13
  end
15
14
 
16
- def tgif_party_day?(date = Date.today)
17
- if date >= START_DATE_OF_NORMAL_TGIF_PARTY_SCHEDULE
18
- if second_or_fourth_friday_in_month?(date)
19
- !cancelled_tgif_party_day?(date)
20
- else
21
- cancelled_tgif_party_day?(date - 7) && !cancelled_tgif_party_day?(date)
22
- end
23
- else
24
- date == DATE_OF_SPECIAL_TGIF_PARTY
25
- end
26
- end
27
-
28
15
  def pay_day?(date = Date.today)
29
16
  return work_day?(date) if date.day == 25
30
17
  next_basic_pay_day = Date.new(date.year, date.month, 25)
@@ -56,7 +43,7 @@ module Increments
56
43
  end
57
44
 
58
45
  def rest_day?(date = Date.today)
59
- weekend?(date) || holiday?(date)
46
+ weekend?(date) || holiday?(date) || winter_vacation?(date)
60
47
  end
61
48
 
62
49
  def weekend?(date = Date.today)
@@ -67,6 +54,19 @@ module Increments
67
54
  HolidayJapan.check(date)
68
55
  end
69
56
 
57
+ def winter_vacation?(date = Date.today)
58
+ case date.month
59
+ when 1
60
+ first_sunday = find_date(Date.new(date.year, 1, 1), :upto, &:sunday?)
61
+ date <= first_sunday
62
+ when 12
63
+ last_saturday = find_date(Date.new(date.year, 12, 31), :downto, &:saturday?)
64
+ date >= last_saturday
65
+ else
66
+ false
67
+ end
68
+ end
69
+
70
70
  public_instance_methods.select { |name| name.to_s.end_with?('?') }.each do |predicate_method|
71
71
  enumeration_method = 'each_' + predicate_method.to_s.sub(/\?\z/, '')
72
72
 
@@ -95,18 +95,6 @@ module Increments
95
95
  !rest_day?(date) && !normal_remote_work_day?(date)
96
96
  end
97
97
 
98
- def second_or_fourth_friday_in_month?(date)
99
- date.friday? && (date.day / 7).odd?
100
- end
101
-
102
- def cancelled_tgif_party_day?(date)
103
- second_or_fourth_friday_in_month?(date) && (rest_day?(date) || yapc_asia_day?(date))
104
- end
105
-
106
- def yapc_asia_day?(date)
107
- DATE_RANGE_OF_YAPC_ASIA.include?(date)
108
- end
109
-
110
98
  def opening_time_of_date(date)
111
99
  date.to_time + 10 * 60 * 60
112
100
  end
@@ -114,5 +102,13 @@ module Increments
114
102
  def closing_time_of_date(date)
115
103
  date.to_time + 19 * 60 * 60
116
104
  end
105
+
106
+ def find_date(date, direction)
107
+ fail ArgumentError unless [:upto, :downto].include?(direction)
108
+ limit_date = direction == :upto ? INFINITY_FUTURE : INFINITY_PAST
109
+ date.send(direction, limit_date) do |d|
110
+ break d if yield d
111
+ end
112
+ end
117
113
  end
118
114
  end
@@ -1,5 +1,5 @@
1
1
  module Increments
2
2
  module Schedule
3
- VERSION = '0.7.2'
3
+ VERSION = '0.8.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.7.2
4
+ version: 0.8.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: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: holiday_japan
@@ -79,8 +79,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.4.8
82
+ rubygems_version: 2.5.1
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Increments' schedule
86
86
  test_files: []
87
+ has_rdoc: