feriados 3.0.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/feriados/argentina.rb +45 -53
- data/lib/feriados/calendar.rb +34 -0
- data/lib/feriados/rules.rb +142 -0
- data/lib/feriados.rb +3 -91
- data/test/date_test.rb +12 -72
- data/test/feriados_test.rb +287 -0
- data/test/runner.rb +10 -0
- data/test/test_helper.rb +5 -3
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 238748dcfdbda85030648b930c354f509349e22a
|
4
|
+
data.tar.gz: e5c7ba38d9aea3a7bfdbb057d9e992982ac0e1ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fab654d36cfc9e4522d45afb3ca5e656c8db64831a1c7522ed71605f2d16d7a75aa49fc864ff42aaa5e9509c36d807c183a88142ce97bdfeed0f062778757c9c
|
7
|
+
data.tar.gz: 4ee6370b10f3a098a7cb783bb4ece0d139f21a5532ff3fd15d7f706a2ae7ed2dd67ac45251d314b826a4009f396e51b96beef756a5b33837cdb94541ef995e0c
|
data/lib/feriados/argentina.rb
CHANGED
@@ -1,57 +1,49 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
module Feriados
|
4
2
|
module Argentina
|
5
|
-
Feriados
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
Feriados.add 'Feriado puente', day: 23, month: 3, year: 2015
|
52
|
-
Feriados.add 'Feriado puente', day: 7, month: 12, year: 2015
|
53
|
-
|
54
|
-
Feriados.add 'Feriado puente', day: 8, month: 7, year: 2016
|
55
|
-
Feriados.add 'Feriado puente', day: 9, month: 12, year: 2016
|
3
|
+
include Feriados::Rules
|
4
|
+
|
5
|
+
def self.rules
|
6
|
+
[
|
7
|
+
DayOfMonth.new(1, 1),
|
8
|
+
DayOfMonth.new(24, 3),
|
9
|
+
DayOfMonth.new(2, 4),
|
10
|
+
DayOfMonth.new(1, 5),
|
11
|
+
DayOfMonth.new(25, 5),
|
12
|
+
DayOfMonth.new(20, 6),
|
13
|
+
DayOfMonth.new(9, 7),
|
14
|
+
DayOfMonth.new(8, 12),
|
15
|
+
DayOfMonth.new(25, 12),
|
16
|
+
|
17
|
+
Easter,
|
18
|
+
HolyThursday,
|
19
|
+
HolyFriday,
|
20
|
+
CarnivalMonday,
|
21
|
+
CarnivalTuesday,
|
22
|
+
|
23
|
+
FixWeekDay.new(3, 1, 8),
|
24
|
+
FixWeekDay.new(2, 1, 10),
|
25
|
+
FixWeekDay.new(4, 1, 11),
|
26
|
+
|
27
|
+
FixDate.new(2012, 2, 27),
|
28
|
+
FixDate.new(2012, 9, 24),
|
29
|
+
FixDate.new(2012, 4, 30),
|
30
|
+
FixDate.new(2012, 12, 24),
|
31
|
+
|
32
|
+
FixDate.new(2013, 1, 31),
|
33
|
+
FixDate.new(2013, 2, 20),
|
34
|
+
FixDate.new(2013, 1, 31),
|
35
|
+
FixDate.new(2013, 4, 1),
|
36
|
+
FixDate.new(2013, 6, 21),
|
37
|
+
|
38
|
+
FixDate.new(2014, 5, 2),
|
39
|
+
FixDate.new(2014, 12, 26),
|
40
|
+
|
41
|
+
FixDate.new(2015, 3, 23),
|
42
|
+
FixDate.new(2015, 12, 7),
|
43
|
+
|
44
|
+
FixDate.new(2016, 7, 8),
|
45
|
+
FixDate.new(2016, 12, 9)
|
46
|
+
]
|
47
|
+
end
|
56
48
|
end
|
57
49
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Feriados
|
5
|
+
class Calendar
|
6
|
+
def initialize
|
7
|
+
@rules = Set.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def holiday?(date)
|
11
|
+
@rules.any? { |rule| rule.holiday?(date) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(rule)
|
15
|
+
@rules << rule
|
16
|
+
end
|
17
|
+
|
18
|
+
def remove(rule)
|
19
|
+
@rules.delete(rule)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
refine Date do
|
24
|
+
def holiday?
|
25
|
+
@@calendar.holiday?(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
refine Date.singleton_class do
|
30
|
+
def calendar=(calendar)
|
31
|
+
@@calendar = calendar
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Feriados
|
2
|
+
module Rules
|
3
|
+
class RuleBase
|
4
|
+
def hash
|
5
|
+
state.hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def eql?(other)
|
9
|
+
hash == other.hash
|
10
|
+
end
|
11
|
+
|
12
|
+
def ==(other)
|
13
|
+
eql?(other)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class DayOfWeek < RuleBase
|
18
|
+
def initialize(wday)
|
19
|
+
@wday = wday
|
20
|
+
end
|
21
|
+
|
22
|
+
def holiday?(date)
|
23
|
+
@wday == date.wday
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def state
|
29
|
+
[@wday]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class DayOfMonth < RuleBase
|
34
|
+
def initialize(day, month)
|
35
|
+
@day = day
|
36
|
+
@month = month
|
37
|
+
end
|
38
|
+
|
39
|
+
def holiday?(date)
|
40
|
+
@day == date.day && @month == date.month
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def state
|
46
|
+
[@day, @month]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class FixDate < RuleBase
|
51
|
+
def initialize(year, month, day)
|
52
|
+
@year = year
|
53
|
+
@month = month
|
54
|
+
@day = day
|
55
|
+
end
|
56
|
+
|
57
|
+
def holiday?(date)
|
58
|
+
@year == date.year && @month == date.month && @day = date.day
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
def state
|
64
|
+
[@year, @month, @day]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Easter
|
69
|
+
def initialize(year)
|
70
|
+
@year = year
|
71
|
+
end
|
72
|
+
|
73
|
+
def date
|
74
|
+
a = @year % 19
|
75
|
+
b = @year / 100
|
76
|
+
c = @year % 100
|
77
|
+
d = b / 4
|
78
|
+
e = b % 4
|
79
|
+
f = (b + 8) / 25
|
80
|
+
g = (b - f + 1) / 3
|
81
|
+
h = (19 * a + b - d - g + 15) % 30
|
82
|
+
i = c / 4
|
83
|
+
k = c % 4
|
84
|
+
l = (32 + 2 * e + 2 * i - h - k) % 7
|
85
|
+
m = (a + 11 * h + 22 * l) / 451
|
86
|
+
month = (h + l - 7 * m + 114) / 31
|
87
|
+
day = ((h + l - 7 * m + 114) % 31) + 1
|
88
|
+
|
89
|
+
Date.new(@year, month, day)
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.holiday?(date)
|
93
|
+
easter = Easter.new(date.year)
|
94
|
+
|
95
|
+
easter.date == date
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class HolyFriday
|
100
|
+
def self.holiday?(date)
|
101
|
+
Easter.new(date.year).date - 2 == date
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class HolyThursday
|
106
|
+
def self.holiday?(date)
|
107
|
+
Easter.new(date.year).date - 3 == date
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class CarnivalMonday
|
112
|
+
def self.holiday?(date)
|
113
|
+
Easter.new(date.year).date - 48 == date
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class CarnivalTuesday
|
118
|
+
def self.holiday?(date)
|
119
|
+
Easter.new(date.year).date - 47 == date
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class FixWeekDay < RuleBase
|
124
|
+
def initialize(week, wday, month)
|
125
|
+
@week = week
|
126
|
+
@wday = wday
|
127
|
+
@month = month
|
128
|
+
end
|
129
|
+
|
130
|
+
def holiday?(date)
|
131
|
+
week = (date.day - 1) / 7 + 1
|
132
|
+
@wday == date.wday && @month == date.month && @week == week
|
133
|
+
end
|
134
|
+
|
135
|
+
protected
|
136
|
+
|
137
|
+
def state
|
138
|
+
[@week, @wday, @month]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/lib/feriados.rb
CHANGED
@@ -1,91 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
DAYS = { sunday: 7, monday: 1, tuesday: 2, wednesday: 3, thursday: 4,
|
5
|
-
friday: 5, saturday: 6 }
|
6
|
-
|
7
|
-
def self.add(description, options = {})
|
8
|
-
month = options[:month] || 0
|
9
|
-
@holidays_by_month ||= {}
|
10
|
-
@holidays_by_month[month] ||= []
|
11
|
-
@holidays_by_month[month] << { description: description }.merge!(options)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.calculated(th, day, month, year)
|
15
|
-
n = { first: 1, second: 2, third: 3, fourth: 4 }
|
16
|
-
|
17
|
-
week = n[th]
|
18
|
-
date = Date.civil(year, month, 1)
|
19
|
-
offset = DAYS[day] - date.wday
|
20
|
-
offset += 7 if offset < 0
|
21
|
-
offset += 7 * (week - 1)
|
22
|
-
date + offset
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.easter(year)
|
26
|
-
a = year % 19
|
27
|
-
b = year / 100
|
28
|
-
c = year % 100
|
29
|
-
d = b / 4
|
30
|
-
e = b % 4
|
31
|
-
f = (b + 8) / 25
|
32
|
-
g = (b - f + 1) / 3
|
33
|
-
h = (19 * a + b - d - g + 15) % 30
|
34
|
-
i = c / 4
|
35
|
-
k = c % 4
|
36
|
-
l = (32 + 2 * e + 2 * i - h - k) % 7
|
37
|
-
m = (a + 11 * h + 22 * l) / 451
|
38
|
-
month = (h + l - 7 * m + 114) / 31
|
39
|
-
day = ((h + l - 7 * m + 114) % 31) + 1
|
40
|
-
|
41
|
-
Date.civil(year, month, day)
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.between(start_date, end_date)
|
45
|
-
dates, list = {}, []
|
46
|
-
|
47
|
-
(start_date..end_date).each do |date|
|
48
|
-
dates[date.year] = [0] unless dates[date.year]
|
49
|
-
unless dates[date.year].include?(date.month)
|
50
|
-
dates[date.year] << date.month
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
dates.each do |year, months|
|
55
|
-
months.each do |month|
|
56
|
-
next unless (holidays = @holidays_by_month[month])
|
57
|
-
holidays.each do |holiday|
|
58
|
-
description = holiday[:description]
|
59
|
-
date = if holiday[:function]
|
60
|
-
holiday[:function].call(year)
|
61
|
-
elsif holiday[:fix_change]
|
62
|
-
calculated(holiday[:fix_change][0], holiday[:fix_change][1],
|
63
|
-
month, year)
|
64
|
-
elsif holiday[:variable_change]
|
65
|
-
holiday[:variable_change].call(Date.civil(year, month,
|
66
|
-
holiday[:day]))
|
67
|
-
else
|
68
|
-
Date.civil(holiday[:year] || year, month, holiday[:day])
|
69
|
-
end
|
70
|
-
|
71
|
-
if date.between?(start_date, end_date) && date.year == year
|
72
|
-
list << { date: date, description: description }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
list.sort_by { |holidays| holidays[:date] }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class Date
|
83
|
-
def holiday?
|
84
|
-
holidays = Feriados.between(self, self)
|
85
|
-
holidays && !holidays.empty?
|
86
|
-
end
|
87
|
-
|
88
|
-
def week_end?
|
89
|
-
wday == 6 || wday == 0
|
90
|
-
end
|
91
|
-
end
|
1
|
+
require_relative './feriados/calendar'
|
2
|
+
require_relative './feriados/rules'
|
3
|
+
require_relative './feriados/argentina'
|
data/test/date_test.rb
CHANGED
@@ -1,80 +1,20 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
class DateTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
using Feriados
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
def test_using_refinements
|
9
|
+
calendar = Calendar.new
|
10
|
+
Date.calendar = calendar
|
8
11
|
|
9
|
-
|
10
|
-
assert @date.respond_to?('week_end?')
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_week_end
|
14
|
-
(2012..2015).each do |year|
|
15
|
-
(1..12).each do |month|
|
16
|
-
nths.each do |n|
|
17
|
-
regulars.each do |day|
|
18
|
-
refute Feriados.calculated(n, day, month, year).week_end?
|
19
|
-
end
|
20
|
-
week_end.each do |day|
|
21
|
-
assert Feriados.calculated(n, day, month, year).week_end?
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_calculated
|
29
|
-
# Dia de la bandera.
|
30
|
-
assert_equal 18, Feriados.calculated(:third, :monday, 6, 2012).day
|
31
|
-
assert_equal 17, Feriados.calculated(:third, :monday, 6, 2013).day
|
32
|
-
assert_equal 16, Feriados.calculated(:third, :monday, 6, 2014).day
|
33
|
-
assert_equal 15, Feriados.calculated(:third, :monday, 6, 2015).day
|
12
|
+
date = Date.new(2016, 5, 2)
|
34
13
|
|
35
|
-
|
36
|
-
assert_equal 20, Feriados.calculated(:third, :monday, 8, 2012).day
|
37
|
-
assert_equal 19, Feriados.calculated(:third, :monday, 8, 2013).day
|
38
|
-
assert_equal 18, Feriados.calculated(:third, :monday, 8, 2014).day
|
39
|
-
assert_equal 17, Feriados.calculated(:third, :monday, 8, 2015).day
|
14
|
+
calendar.add(FixDate.new(date.year, date.month, date.day))
|
40
15
|
|
41
|
-
|
42
|
-
assert_equal 8, Feriados.easter(2012).day
|
43
|
-
assert_equal 31, Feriados.easter(2013).day
|
44
|
-
assert_equal 20, Feriados.easter(2014).day
|
45
|
-
assert_equal 5, Feriados.easter(2015).day
|
46
|
-
|
47
|
-
# Carnaval
|
48
|
-
assert_equal 11, (Feriados.easter(2013) - 48).day
|
49
|
-
assert_equal 3, (Feriados.easter(2014) - 48).day
|
50
|
-
assert_equal 16, (Feriados.easter(2015) - 48).day
|
51
|
-
|
52
|
-
assert_equal 12, (Feriados.easter(2013) - 47).day
|
53
|
-
assert_equal 4, (Feriados.easter(2014) - 47).day
|
54
|
-
assert_equal 17, (Feriados.easter(2015) - 47).day
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_fix_holidays
|
58
|
-
2012.upto(2015) do |year|
|
59
|
-
assert Date.civil(year, 1, 1).holiday?
|
60
|
-
assert Date.civil(year, 3, 24).holiday?
|
61
|
-
assert Date.civil(year, 4, 2).holiday?
|
62
|
-
assert Date.civil(year, 5, 1).holiday?
|
63
|
-
assert Date.civil(year, 7, 9).holiday?
|
64
|
-
assert Date.civil(year, 12, 8).holiday?
|
65
|
-
assert Date.civil(year, 12, 25).holiday?
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def regulars
|
70
|
-
[:monday, :tuesday, :wednesday, :thursday, :friday]
|
71
|
-
end
|
72
|
-
|
73
|
-
def week_end
|
74
|
-
[:saturday, :sunday]
|
75
|
-
end
|
16
|
+
assert calendar.holiday?(date)
|
76
17
|
|
77
|
-
|
78
|
-
[:first, :second, :third, :fourth]
|
18
|
+
assert date.holiday?
|
79
19
|
end
|
80
20
|
end
|
@@ -0,0 +1,287 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CalendarTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_a_day_of_week_can_be_a_holiday
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
a_saturday = Date.new(2016, 4, 30)
|
11
|
+
|
12
|
+
calendar.add(DayOfWeek.new(a_saturday.wday))
|
13
|
+
|
14
|
+
assert calendar.holiday?(a_saturday)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_a_day_of_week_can_be_not_a_holiday
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
a_monday = Date.new(2016, 5, 2)
|
21
|
+
|
22
|
+
refute calendar.holiday?(a_monday)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_a_bunch_of_days_can_be_a_holiday
|
26
|
+
calendar = Calendar.new
|
27
|
+
|
28
|
+
a_saturday = Date.new(2016, 4, 30)
|
29
|
+
a_sunday = Date.new(2016, 5, 1)
|
30
|
+
|
31
|
+
calendar.add(DayOfWeek.new(a_saturday.wday))
|
32
|
+
calendar.add(DayOfWeek.new(a_sunday.wday))
|
33
|
+
|
34
|
+
assert calendar.holiday?(a_sunday)
|
35
|
+
assert calendar.holiday?(a_saturday)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_a_day_of_week_rule_can_be_deleted
|
39
|
+
calendar = Calendar.new
|
40
|
+
|
41
|
+
date = Date.new(2016, 5, 1)
|
42
|
+
|
43
|
+
calendar.add(DayOfWeek.new(date.wday))
|
44
|
+
|
45
|
+
assert calendar.holiday?(date)
|
46
|
+
|
47
|
+
calendar.remove(DayOfWeek.new(date.wday))
|
48
|
+
|
49
|
+
refute calendar.holiday?(date)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_a_date_of_month_can_be_a_holiday
|
53
|
+
calendar = Calendar.new
|
54
|
+
|
55
|
+
a_january_first = Date.new(2016, 1, 1)
|
56
|
+
|
57
|
+
calendar.add(DayOfMonth.new(1, 1))
|
58
|
+
|
59
|
+
assert calendar.holiday?(a_january_first)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_a_day_of_month_can_be_not_a_holiday
|
63
|
+
calendar = Calendar.new
|
64
|
+
|
65
|
+
a_day = Date.new(2016, 1, 2)
|
66
|
+
|
67
|
+
calendar.add(DayOfMonth.new(1, 1))
|
68
|
+
|
69
|
+
refute calendar.holiday?(a_day)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_a_bunch_of_days_of_month_can_be_a_holiday
|
73
|
+
calendar = Calendar.new
|
74
|
+
|
75
|
+
a_christmas = Date.new(2016, 12, 25)
|
76
|
+
a_january_first = Date.new(2016, 1, 1)
|
77
|
+
|
78
|
+
calendar.add(DayOfMonth.new(1, 1))
|
79
|
+
calendar.add(DayOfMonth.new(25, 12))
|
80
|
+
|
81
|
+
assert calendar.holiday?(a_christmas)
|
82
|
+
assert calendar.holiday?(a_january_first)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_a_day_of_month_rule_can_be_deleted
|
86
|
+
calendar = Calendar.new
|
87
|
+
|
88
|
+
date = Date.new(2016, 5, 1)
|
89
|
+
|
90
|
+
calendar.add(DayOfMonth.new(date.day, date.month))
|
91
|
+
|
92
|
+
assert calendar.holiday?(date)
|
93
|
+
|
94
|
+
calendar.remove(DayOfMonth.new(date.day, date.month))
|
95
|
+
|
96
|
+
refute calendar.holiday?(date)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_a_date_can_be_a_holiday
|
100
|
+
calendar = Calendar.new
|
101
|
+
|
102
|
+
date = Date.new(2016, 1, 1)
|
103
|
+
|
104
|
+
calendar.add(FixDate.new(2016, 1, 1))
|
105
|
+
|
106
|
+
assert calendar.holiday?(date)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_a_date_can_be_not_a_holiday
|
110
|
+
calendar = Calendar.new
|
111
|
+
|
112
|
+
refute calendar.holiday?(Date.new(2016, 1, 1))
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_a_bunch_of_dates_can_be_a_holiday
|
116
|
+
calendar = Calendar.new
|
117
|
+
|
118
|
+
date = Date.new(2016, 4, 29)
|
119
|
+
another_date = Date.new(2016, 4, 30)
|
120
|
+
|
121
|
+
calendar.add(FixDate.new(2016, 4, 29))
|
122
|
+
calendar.add(FixDate.new(2016, 4, 30))
|
123
|
+
|
124
|
+
assert calendar.holiday?(date)
|
125
|
+
assert calendar.holiday?(another_date)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_a_date_rule_can_be_deleted
|
129
|
+
calendar = Calendar.new
|
130
|
+
|
131
|
+
date = Date.new(2016, 5, 1)
|
132
|
+
|
133
|
+
calendar.add(FixDate.new(date.year, date.month, date.day))
|
134
|
+
|
135
|
+
assert calendar.holiday?(date)
|
136
|
+
|
137
|
+
calendar.remove(FixDate.new(date.year, date.month, date.day))
|
138
|
+
|
139
|
+
refute calendar.holiday?(date)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_easter
|
143
|
+
calendar = Calendar.new
|
144
|
+
|
145
|
+
date = Date.new(2016, 3, 27)
|
146
|
+
|
147
|
+
calendar.add(Easter)
|
148
|
+
|
149
|
+
assert calendar.holiday?(date)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_not_easter
|
153
|
+
calendar = Calendar.new
|
154
|
+
|
155
|
+
date = Date.new(2016, 3, 26)
|
156
|
+
|
157
|
+
calendar.add(Easter)
|
158
|
+
|
159
|
+
refute calendar.holiday?(date)
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_remove_easter
|
163
|
+
calendar = Calendar.new
|
164
|
+
|
165
|
+
date = Date.new(2016, 3, 27)
|
166
|
+
|
167
|
+
calendar.add(Easter)
|
168
|
+
|
169
|
+
assert calendar.holiday?(date)
|
170
|
+
|
171
|
+
calendar.remove(Easter)
|
172
|
+
|
173
|
+
refute calendar.holiday?(date)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_holy_friday
|
177
|
+
calendar = Calendar.new
|
178
|
+
|
179
|
+
date = Date.new(2016, 3, 25)
|
180
|
+
|
181
|
+
calendar.add(HolyFriday)
|
182
|
+
|
183
|
+
assert calendar.holiday?(date)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_not_holy_friday
|
187
|
+
calendar = Calendar.new
|
188
|
+
|
189
|
+
date = Date.new(2016, 3, 20)
|
190
|
+
|
191
|
+
calendar.add(HolyFriday)
|
192
|
+
|
193
|
+
refute calendar.holiday?(date)
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_remove_holy_friday
|
197
|
+
calendar = Calendar.new
|
198
|
+
|
199
|
+
date = Date.new(2016, 3, 25)
|
200
|
+
|
201
|
+
calendar.add(HolyFriday)
|
202
|
+
|
203
|
+
assert calendar.holiday?(date)
|
204
|
+
|
205
|
+
calendar.remove(HolyFriday)
|
206
|
+
|
207
|
+
refute calendar.holiday?(date)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_holy_thursday
|
211
|
+
calendar = Calendar.new
|
212
|
+
|
213
|
+
date = Date.new(2016, 3, 24)
|
214
|
+
|
215
|
+
calendar.add(HolyThursday)
|
216
|
+
|
217
|
+
assert calendar.holiday?(date)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_fix_week_day_rule
|
221
|
+
calendar = Calendar.new
|
222
|
+
|
223
|
+
calendar.add(FixWeekDay.new(4, 1, 11))
|
224
|
+
calendar.add(FixWeekDay.new(3, 1, 8))
|
225
|
+
|
226
|
+
assert calendar.holiday?(Date.new(2016, 11, 28))
|
227
|
+
assert calendar.holiday?(Date.new(2016, 8, 15))
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_not_fix_week_day_rule
|
231
|
+
calendar = Calendar.new
|
232
|
+
|
233
|
+
date = Date.new(2016, 5, 2)
|
234
|
+
|
235
|
+
calendar.add(FixWeekDay.new(2, 1, 5))
|
236
|
+
|
237
|
+
refute calendar.holiday?(date)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_remove_fix_week_day_rule
|
241
|
+
calendar = Calendar.new
|
242
|
+
|
243
|
+
date = Date.new(2016, 11, 28)
|
244
|
+
|
245
|
+
calendar.add(FixWeekDay.new(4, 1, 11))
|
246
|
+
|
247
|
+
assert calendar.holiday?(date)
|
248
|
+
|
249
|
+
calendar.remove(FixWeekDay.new(4, 1, 11))
|
250
|
+
|
251
|
+
refute calendar.holiday?(date)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_load_argentinian_holidays
|
255
|
+
calendar = Calendar.new
|
256
|
+
|
257
|
+
Feriados::Argentina.rules.each { |rule| calendar.add rule }
|
258
|
+
|
259
|
+
assert calendar.holiday?(Date.new(2016, 1, 1))
|
260
|
+
|
261
|
+
assert calendar.holiday?(Date.new(2016, 2, 8))
|
262
|
+
assert calendar.holiday?(Date.new(2016, 2, 9))
|
263
|
+
|
264
|
+
assert calendar.holiday?(Date.new(2016, 3, 24))
|
265
|
+
assert calendar.holiday?(Date.new(2016, 3, 25))
|
266
|
+
assert calendar.holiday?(Date.new(2016, 3, 27))
|
267
|
+
|
268
|
+
assert calendar.holiday?(Date.new(2016, 4, 2))
|
269
|
+
|
270
|
+
assert calendar.holiday?(Date.new(2016, 5, 1))
|
271
|
+
assert calendar.holiday?(Date.new(2016, 5, 25))
|
272
|
+
|
273
|
+
assert calendar.holiday?(Date.new(2016, 6, 20))
|
274
|
+
|
275
|
+
assert calendar.holiday?(Date.new(2016, 7, 8))
|
276
|
+
assert calendar.holiday?(Date.new(2016, 7, 9))
|
277
|
+
|
278
|
+
assert calendar.holiday?(Date.new(2016, 8, 15))
|
279
|
+
|
280
|
+
assert calendar.holiday?(Date.new(2016, 10, 10))
|
281
|
+
|
282
|
+
assert calendar.holiday?(Date.new(2016, 11, 28))
|
283
|
+
|
284
|
+
assert calendar.holiday?(Date.new(2016, 12, 8))
|
285
|
+
assert calendar.holiday?(Date.new(2016, 12, 25))
|
286
|
+
end
|
287
|
+
end
|
data/test/runner.rb
ADDED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feriados
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Rabuini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Make holidays calendars from rules
|
14
14
|
email:
|
15
15
|
- srabuini@gmail.com
|
16
16
|
executables: []
|
@@ -19,7 +19,11 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/feriados.rb
|
21
21
|
- lib/feriados/argentina.rb
|
22
|
+
- lib/feriados/calendar.rb
|
23
|
+
- lib/feriados/rules.rb
|
22
24
|
- test/date_test.rb
|
25
|
+
- test/feriados_test.rb
|
26
|
+
- test/runner.rb
|
23
27
|
- test/test_helper.rb
|
24
28
|
homepage: https://github.com/srabuini/feriados
|
25
29
|
licenses:
|
@@ -41,11 +45,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
45
|
version: '0'
|
42
46
|
requirements: []
|
43
47
|
rubyforge_project:
|
44
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.5.1
|
45
49
|
signing_key:
|
46
50
|
specification_version: 4
|
47
|
-
summary:
|
51
|
+
summary: Holidays calendars
|
48
52
|
test_files:
|
49
53
|
- test/date_test.rb
|
54
|
+
- test/feriados_test.rb
|
55
|
+
- test/runner.rb
|
50
56
|
- test/test_helper.rb
|
51
|
-
has_rdoc:
|