holidate 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/holidate.gemspec +1 -1
- data/lib/holidate.rb +55 -53
- data/spec/holidate_spec.rb +4 -0
- metadata +2 -2
data/holidate.gemspec
CHANGED
data/lib/holidate.rb
CHANGED
@@ -1,71 +1,73 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
3
|
class Holidate
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
class << self
|
5
|
+
|
6
|
+
undef_method(:new)
|
7
|
+
|
8
|
+
def find(nth_, wday_, month_, year_=Date.today.year)
|
9
|
+
nth = nth_int(nth_)
|
10
|
+
wday = wday_int(wday_)
|
11
|
+
month = month_int(month_)
|
12
|
+
year = year_int(year_)
|
13
|
+
if nth > 0
|
14
|
+
Date.new(year, month, (1 + (nth - 1) * 7 + (wday - Date.new(year, month, 1).wday) % 7))
|
15
|
+
else
|
16
|
+
days_in_month = ((Date.new(year, month) >> 1) - 1).day
|
17
|
+
Date.new(year, month, (days_in_month - (-nth - 1) * 7 - (Date.new(year, month, days_in_month).wday - wday) % 7))
|
18
|
+
end
|
14
19
|
end
|
15
|
-
end
|
16
|
-
singleton_class.send(:alias_method, :find_day, :find)
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
def new_years_day(year=Date.today.year)
|
22
|
+
Date.new(year, 1, 1)
|
23
|
+
end
|
24
|
+
alias_method(:new_year, :new_years_day)
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def martin_luther_king_jr_day(year=Date.today.year)
|
27
|
+
find('third', 'monday', 'january', year)
|
28
|
+
end
|
29
|
+
alias_method(:mlk, :martin_luther_king_jr_day)
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
def washingtons_birthday(year=Date.today.year)
|
32
|
+
find('third', 'monday', 'february', year)
|
33
|
+
end
|
34
|
+
alias_method(:washington, :washingtons_birthday)
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
def memorial_day(year=Date.today.year)
|
37
|
+
find('last', 'monday', 'may', year)
|
38
|
+
end
|
39
|
+
alias_method(:memorial, :memorial_day)
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
def independence_day(year=Date.today.year)
|
42
|
+
Date.new(year, 7, 4)
|
43
|
+
end
|
44
|
+
alias_method(:july_4, :independence_day)
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
46
|
+
def labor_day(year=Date.today.year)
|
47
|
+
find('first', 'monday', 'september', year)
|
48
|
+
end
|
49
|
+
alias_method(:labor, :labor_day)
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
def columbus_day(year=Date.today.year)
|
52
|
+
find('second', 'monday', 'october', year)
|
53
|
+
end
|
54
|
+
alias_method(:columbus, :columbus_day)
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
def veterans_day(year=Date.today.year)
|
57
|
+
Date.new(year, 11, 11)
|
58
|
+
end
|
59
|
+
alias_method(:veteran, :veterans_day)
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
61
|
+
def thanksgiving_day(year=Date.today.year)
|
62
|
+
find('fourth', 'thursday', 'november', year)
|
63
|
+
end
|
64
|
+
alias_method(:thanksgiving, :thanksgiving_day)
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
def christmas_day(year=Date.today.year)
|
67
|
+
Date.new(year, 12, 25)
|
68
|
+
end
|
69
|
+
alias_method(:xmas, :christmas_day)
|
67
70
|
|
68
|
-
class << self
|
69
71
|
protected
|
70
72
|
|
71
73
|
def nth_int(nth_)
|
data/spec/holidate_spec.rb
CHANGED
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: 1.0.0
|
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-
|
12
|
+
date: 2015-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|