holidate 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/holidate.rb +16 -17
- metadata +2 -2
data/lib/holidate.rb
CHANGED
@@ -1,62 +1,61 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
class Holidate
|
4
|
+
def self.find_day nth, wday, month, year=Date.today.year
|
5
|
+
if nth > 0
|
6
|
+
Date.new year, month, ( 1 + ( nth - 1) * 7 + (wday - Date.new(year, month, 1).wday) % 7)
|
7
|
+
elsif nth < 0
|
8
|
+
days_in_month = ((Date.new(year, month) >> 1) -1).day
|
9
|
+
Date.new year, month, (days_in_month - (-nth - 1) * 7 - (Date.new(year, month, days_in_month).wday - wday) % 7)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
def self.new_years_day year
|
5
|
-
|
6
|
-
Date.new year, 1
|
14
|
+
Date.new year, 1, 1
|
7
15
|
end
|
8
16
|
self.singleton_class.send(:alias_method, :new_year, :new_years_day)
|
9
17
|
|
10
18
|
def self.martin_luther_king_jr_day year
|
11
|
-
|
12
|
-
Date.new year, 1, (15 + (1 - Date.new(year, 1).wday)%7)
|
19
|
+
self.find_day 3, 1, 1, year
|
13
20
|
end
|
14
21
|
self.singleton_class.send(:alias_method, :mlk, :martin_luther_king_jr_day)
|
15
22
|
|
16
23
|
def self.washingtons_birthday year
|
17
|
-
|
18
|
-
Date.new year, 2, (15 + (1 - Date.new(year, 2).wday)%7)
|
24
|
+
self.find_day 3, 1, 2, year
|
19
25
|
end
|
20
26
|
self.singleton_class.send(:alias_method, :washington, :washingtons_birthday)
|
21
27
|
|
22
28
|
def self.memorial_day year
|
23
|
-
|
24
|
-
Date.new year, 5, (31 - (Date.new(year, 5, 31).wday - 1)%7)
|
29
|
+
self.find_day -1, 1, 5, year
|
25
30
|
end
|
26
31
|
self.singleton_class.send(:alias_method, :memorial, :memorial_day)
|
27
32
|
|
28
33
|
def self.independence_day year
|
29
|
-
raise ArgumentError, "Invalid value for method #{__method__}: #{year.inspect}" unless year.is_a? Integer
|
30
34
|
Date.new year, 7, 4
|
31
35
|
end
|
32
36
|
self.singleton_class.send(:alias_method, :july_4, :independence_day)
|
33
37
|
|
34
38
|
def self.labor_day year
|
35
|
-
|
36
|
-
Date.new year, 9, (1 + (1 - Date.new(year, 9).wday)%7)
|
39
|
+
self.find_day 1, 1, 9, year
|
37
40
|
end
|
38
41
|
self.singleton_class.send(:alias_method, :labor, :labor_day)
|
39
42
|
|
40
43
|
def self.columbus_day year
|
41
|
-
|
42
|
-
Date.new year, 10, (8 + (1 - Date.new(year, 10).wday)%7)
|
44
|
+
self.find_day 2, 1, 10, year
|
43
45
|
end
|
44
46
|
self.singleton_class.send(:alias_method, :columbus, :columbus_day)
|
45
47
|
|
46
48
|
def self.veterans_day year
|
47
|
-
raise ArgumentError, "Invalid value for method #{__method__}: #{year.inspect}" unless year.is_a? Integer
|
48
49
|
Date.new year, 11, 11
|
49
50
|
end
|
50
51
|
self.singleton_class.send(:alias_method, :veteran, :veterans_day)
|
51
52
|
|
52
53
|
def self.thanksgiving_day year
|
53
|
-
|
54
|
-
Date.new year, 11, (22 + (4 - Date.new(year, 11).wday)%7)
|
54
|
+
self.find_day 4, 4, 11, year
|
55
55
|
end
|
56
56
|
self.singleton_class.send(:alias_method, :thanksgiving, :thanksgiving_day)
|
57
57
|
|
58
58
|
def self.christmas_day year
|
59
|
-
raise ArgumentError, "Invalid value for method #{__method__}: #{year.inspect}" unless year.is_a? Integer
|
60
59
|
Date.new year, 12, 25
|
61
60
|
end
|
62
61
|
self.singleton_class.send(:alias_method, :xmas, :christmas_day)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holidate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-01-
|
12
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|