increments-schedule 0.13.1 → 0.13.2

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: 5c89435ad919e28bd9aac089199b364729410eeb
4
- data.tar.gz: 30f5fc090856aa6156c177f96cff0e7b35efc3ec
3
+ metadata.gz: 6ed9a60f8d0e1e98939183fb197dbd40e50bf261
4
+ data.tar.gz: 27cf83e11edd682076f325f6112b9c06b14d3e69
5
5
  SHA512:
6
- metadata.gz: e2ba480c2f88ebe2dc0e73b6668bc20bc57914f8de908388c326d12135aceb186dc1ee27907c21aefbb34516057f5a62ad1d9f8c161cb1a56c82a0e3ba8fe69b
7
- data.tar.gz: f24162fd6498d1f8d6b301b9e626af278d62a07527c96a7308769627dfce6161687baa14ca9a0ab38c5a27cc8f4220f12a28ffbab766e5769cab492fbab76ef4
6
+ metadata.gz: 2b41c6f417c1fc3c5dcb9125e28b1328d118979fffe8940810b57586e5378bb9803aac7af5f44afe2766e913953e7adbf90af039f75edd01906473556082092b
7
+ data.tar.gz: e096e1f259d6ba2c5ebedecdd089326468aa900b1842156e2ae21b6ae35c741c5cda114640d0d3622ecc61b7c3033bead5b897c6fb30edbe0d51b0e27bb65f29
@@ -5,9 +5,6 @@ module Increments
5
5
  module Schedule
6
6
  extend self # rubocop:disable ModuleFunction
7
7
 
8
- INFINITY_FUTURE = Date.new(10_000, 1, 1)
9
- INFINITY_PAST = Date.new(0, 1, 1)
10
-
11
8
  def foundation_anniversary?(date = Date.today)
12
9
  date.month == 2 && date.day == 29
13
10
  end
@@ -47,11 +44,11 @@ module Increments
47
44
  def winter_vacation?(date = Date.today)
48
45
  case date.month
49
46
  when 1
50
- first_sunday = find_date(Date.new(date.year, 1, 1), :upto, &:sunday?)
51
- date <= first_sunday
47
+ return true if date.day <= 3
48
+ date <= ExtendedDate.new(date.year, 1, 1).find_next(&:sunday?)
52
49
  when 12
53
- last_saturday = find_date(Date.new(date.year, 12, 31), :downto, &:saturday?)
54
- date >= last_saturday
50
+ return true if date.day >= 28
51
+ date >= ExtendedDate.new(date.year, 12, 31).find_previous(&:saturday?)
55
52
  else
56
53
  false
57
54
  end
@@ -71,13 +68,20 @@ module Increments
71
68
  end
72
69
  end
73
70
 
74
- private
71
+ class ExtendedDate < Date
72
+ INFINITY_FUTURE = Date.new(10_000, 1, 1)
73
+ INFINITY_PAST = Date.new(0, 1, 1)
75
74
 
76
- def find_date(date, direction)
77
- raise ArgumentError unless [:upto, :downto].include?(direction)
78
- limit_date = direction == :upto ? INFINITY_FUTURE : INFINITY_PAST
79
- date.send(direction, limit_date) do |d|
80
- break d if yield d
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
81
85
  end
82
86
  end
83
87
  end
@@ -1,5 +1,5 @@
1
1
  module Increments
2
2
  module Schedule
3
- VERSION = '0.13.1'
3
+ VERSION = '0.13.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: increments-schedule
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuji Nakayama