feriados 4.2.0 → 4.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/feriados/calendar.rb +7 -5
- data/lib/feriados/loader.rb +42 -22
- data/lib/feriados/rules/carnival_monday.rb +1 -1
- data/lib/feriados/rules/carnival_tuesday.rb +1 -1
- data/lib/feriados/rules/day_of_month.rb +2 -1
- data/lib/feriados/rules/day_of_week.rb +3 -1
- data/lib/feriados/rules/easter.rb +52 -13
- data/lib/feriados/rules/fix_date.rb +2 -1
- data/lib/feriados/rules/fix_week_day.rb +2 -1
- data/lib/feriados/rules/function.rb +9 -0
- data/lib/feriados/rules/holy_friday.rb +1 -1
- data/lib/feriados/rules/holy_thursday.rb +1 -1
- data/lib/feriados/rules/rule_base.rb +6 -0
- data/lib/feriados/rules.rb +1 -0
- data/test/day_of_month_test.rb +63 -0
- data/test/day_off_week_test.rb +71 -0
- data/test/easter_test.rb +52 -0
- data/test/feriados_test.rb +37 -279
- data/test/fix_date_test.rb +59 -0
- data/test/fix_week_day_test.rb +48 -0
- data/test/holy_friday_test.rb +52 -0
- data/test/holy_thursday_test.rb +28 -0
- data/test/runner.rb +1 -1
- data/test/test_helper.rb +3 -0
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f987e77a82fb0a2f30fb0712c5238df644e19b17d774b82d2431e837f36f0073
|
4
|
+
data.tar.gz: c2d5fb6517a05649ca540e41644f3bf4052c64cca2dee4a90cbe2551b2720e4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55c8afdf959e9144c5d9bd23469d56a4a8c0b73b5b29263e420d585b40a764b986d41aa5e36d6842b964e45c29e8fa84854667ec2d360f66fd2784d8055aa99b
|
7
|
+
data.tar.gz: 98eb156d025c308deed1ddc498b08f8b1427be7d819b14bfe3523a10ed5c493053a7a75a1ad3d01cc5dd622af604826c7bc7ac10c2d4532e7eabdd42cebbb2ac
|
data/lib/feriados/calendar.rb
CHANGED
@@ -11,6 +11,10 @@ module Feriados
|
|
11
11
|
rules.any? { |rule| rule.holiday?(date) }
|
12
12
|
end
|
13
13
|
|
14
|
+
def holiday_name(date)
|
15
|
+
rules.find { |rule| rule.holiday?(date) }&.name
|
16
|
+
end
|
17
|
+
|
14
18
|
def add(rule)
|
15
19
|
rules << rule
|
16
20
|
end
|
@@ -19,11 +23,7 @@ module Feriados
|
|
19
23
|
rules.delete(rule)
|
20
24
|
end
|
21
25
|
|
22
|
-
def
|
23
|
-
self.rules = rules
|
24
|
-
end
|
25
|
-
|
26
|
-
def load_rules(file)
|
26
|
+
def load(file)
|
27
27
|
Loader.new(file, self).load
|
28
28
|
end
|
29
29
|
|
@@ -33,6 +33,8 @@ module Feriados
|
|
33
33
|
end
|
34
34
|
|
35
35
|
refine Date do
|
36
|
+
@calendar = nil
|
37
|
+
|
36
38
|
def holiday?
|
37
39
|
@@calendar.holiday?(self)
|
38
40
|
end
|
data/lib/feriados/loader.rb
CHANGED
@@ -1,59 +1,79 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Feriados
|
2
4
|
class Loader
|
3
|
-
|
4
|
-
|
5
|
+
include Rules
|
6
|
+
|
7
|
+
def initialize(data, calendar)
|
8
|
+
@data = data
|
5
9
|
@calendar = calendar
|
6
10
|
end
|
7
11
|
|
8
12
|
def load
|
9
13
|
load_day_of_month
|
10
14
|
load_functions
|
11
|
-
|
12
|
-
|
15
|
+
load_fix_week_days
|
16
|
+
load_fix_dates
|
13
17
|
end
|
14
18
|
|
15
19
|
private
|
16
20
|
|
17
|
-
attr_reader :
|
18
|
-
|
19
|
-
def config_rules
|
20
|
-
@config_rules ||= YAML.load_file(file)
|
21
|
-
end
|
21
|
+
attr_reader :data, :calendar
|
22
22
|
|
23
23
|
def load_day_of_month
|
24
|
-
|
25
|
-
rules.each do |
|
26
|
-
|
24
|
+
day_of_month.each do |month, rules|
|
25
|
+
rules.each do |rule_data|
|
26
|
+
rule = OpenStruct.new(rule_data)
|
27
|
+
calendar.add(DayOfMonth.new(rule.day, month, rule.name))
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
32
|
def load_functions
|
32
|
-
|
33
|
-
function_name =
|
33
|
+
function.each do |function, name|
|
34
|
+
function_name = function.split('_').collect(&:capitalize).join
|
34
35
|
class_name = "Feriados::Rules::#{function_name}".split('::')
|
35
36
|
|
36
37
|
klass = class_name.inject(Object) { |obj, const| obj.const_get(const) }
|
38
|
+
klass.name = name
|
37
39
|
calendar.add(klass)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
def
|
42
|
-
|
43
|
-
rules.each do |
|
44
|
-
|
43
|
+
def load_fix_week_days
|
44
|
+
fix_week_day.each do |month, rules|
|
45
|
+
rules.each do |rule_data|
|
46
|
+
rule = OpenStruct.new(rule_data)
|
47
|
+
calendar.add(FixWeekDay.new(rule.week, rule.day, month, rule.name))
|
45
48
|
end
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
49
|
-
def
|
50
|
-
|
52
|
+
def load_fix_dates
|
53
|
+
fix_date.each do |year, months|
|
51
54
|
months.each do |month, rules|
|
52
|
-
rules.each do |
|
53
|
-
|
55
|
+
rules.each do |rule_data|
|
56
|
+
rule = OpenStruct.new(rule_data)
|
57
|
+
calendar.add(FixDate.new(year, month, rule.day, rule.name))
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
57
61
|
end
|
62
|
+
|
63
|
+
def day_of_month
|
64
|
+
data['day_of_month']['month']
|
65
|
+
end
|
66
|
+
|
67
|
+
def function
|
68
|
+
data['function']
|
69
|
+
end
|
70
|
+
|
71
|
+
def fix_week_day
|
72
|
+
data['fix_week_day']['month']
|
73
|
+
end
|
74
|
+
|
75
|
+
def fix_date
|
76
|
+
data['fix_date']
|
77
|
+
end
|
58
78
|
end
|
59
79
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Feriados
|
2
2
|
module Rules
|
3
3
|
class DayOfWeek < RuleBase
|
4
|
-
def initialize(wday)
|
4
|
+
def initialize(wday, name = nil)
|
5
|
+
super(name)
|
5
6
|
@wday = wday
|
6
7
|
end
|
7
8
|
|
@@ -10,6 +11,7 @@ module Feriados
|
|
10
11
|
end
|
11
12
|
|
12
13
|
protected
|
14
|
+
|
13
15
|
attr_reader :wday
|
14
16
|
|
15
17
|
def state
|
@@ -1,24 +1,15 @@
|
|
1
1
|
module Feriados
|
2
2
|
module Rules
|
3
|
-
class Easter
|
3
|
+
class Easter < Function
|
4
|
+
@name = nil
|
5
|
+
|
4
6
|
def initialize(year)
|
5
7
|
@year = year
|
6
8
|
end
|
7
9
|
|
8
10
|
def date
|
9
|
-
a = year % 19
|
10
|
-
b = year / 100
|
11
|
-
c = year % 100
|
12
|
-
d = b / 4
|
13
|
-
e = b % 4
|
14
|
-
f = (b + 8) / 25
|
15
|
-
g = (b - f + 1) / 3
|
16
|
-
h = (19 * a + b - d - g + 15) % 30
|
17
|
-
i = c / 4
|
18
|
-
k = c % 4
|
19
|
-
l = (32 + 2 * e + 2 * i - h - k) % 7
|
20
|
-
m = (a + 11 * h + 22 * l) / 451
|
21
11
|
result = h + l - 7 * m + 114
|
12
|
+
|
22
13
|
month = result / 31
|
23
14
|
day = (result % 31) + 1
|
24
15
|
|
@@ -33,6 +24,54 @@ module Feriados
|
|
33
24
|
|
34
25
|
private
|
35
26
|
|
27
|
+
def a
|
28
|
+
year % 19
|
29
|
+
end
|
30
|
+
|
31
|
+
def b
|
32
|
+
year / 100
|
33
|
+
end
|
34
|
+
|
35
|
+
def c
|
36
|
+
year % 100
|
37
|
+
end
|
38
|
+
|
39
|
+
def d
|
40
|
+
b / 4
|
41
|
+
end
|
42
|
+
|
43
|
+
def e
|
44
|
+
b % 4
|
45
|
+
end
|
46
|
+
|
47
|
+
def f
|
48
|
+
(b + 8) / 25
|
49
|
+
end
|
50
|
+
|
51
|
+
def g
|
52
|
+
(b - f + 1) / 3
|
53
|
+
end
|
54
|
+
|
55
|
+
def h
|
56
|
+
(19 * a + b - d - g + 15) % 30
|
57
|
+
end
|
58
|
+
|
59
|
+
def i
|
60
|
+
c / 4
|
61
|
+
end
|
62
|
+
|
63
|
+
def k
|
64
|
+
c % 4
|
65
|
+
end
|
66
|
+
|
67
|
+
def l
|
68
|
+
(32 + 2 * e + 2 * i - h - k) % 7
|
69
|
+
end
|
70
|
+
|
71
|
+
def m
|
72
|
+
(a + 11 * h + 22 * l) / 451
|
73
|
+
end
|
74
|
+
|
36
75
|
attr_reader :year
|
37
76
|
end
|
38
77
|
end
|
data/lib/feriados/rules.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DayOfMonthTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_a_date_of_month_can_be_a_holiday
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
a_january_first = Date.new(2016, 1, 1)
|
11
|
+
|
12
|
+
calendar.add(DayOfMonth.new(1, 1))
|
13
|
+
|
14
|
+
assert calendar.holiday?(a_january_first)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_a_date_of_month_can_have_a_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
a_january_first = Date.new(2016, 1, 1)
|
21
|
+
|
22
|
+
calendar.add(DayOfMonth.new(1, 1, 'new year'))
|
23
|
+
|
24
|
+
assert_equal 'new year', calendar.holiday_name(a_january_first)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_a_day_of_month_can_be_not_a_holiday
|
28
|
+
calendar = Calendar.new
|
29
|
+
|
30
|
+
a_day = Date.new(2016, 1, 2)
|
31
|
+
|
32
|
+
calendar.add(DayOfMonth.new(1, 1))
|
33
|
+
|
34
|
+
refute calendar.holiday?(a_day)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_a_bunch_of_days_of_month_can_be_a_holiday
|
38
|
+
calendar = Calendar.new
|
39
|
+
|
40
|
+
a_christmas = Date.new(2016, 12, 25)
|
41
|
+
a_january_first = Date.new(2016, 1, 1)
|
42
|
+
|
43
|
+
calendar.add(DayOfMonth.new(1, 1))
|
44
|
+
calendar.add(DayOfMonth.new(25, 12))
|
45
|
+
|
46
|
+
assert calendar.holiday?(a_christmas)
|
47
|
+
assert calendar.holiday?(a_january_first)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_a_day_of_month_rule_can_be_deleted
|
51
|
+
calendar = Calendar.new
|
52
|
+
|
53
|
+
date = Date.new(2016, 5, 1)
|
54
|
+
|
55
|
+
calendar.add(DayOfMonth.new(date.day, date.month))
|
56
|
+
|
57
|
+
assert calendar.holiday?(date)
|
58
|
+
|
59
|
+
calendar.remove(DayOfMonth.new(date.day, date.month))
|
60
|
+
|
61
|
+
refute calendar.holiday?(date)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DayOfWeekTest < 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__a_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
a_saturday = Date.new(2016, 4, 30)
|
21
|
+
|
22
|
+
calendar.add(DayOfWeek.new(a_saturday.wday, 'saturday night live'))
|
23
|
+
|
24
|
+
assert_equal 'saturday night live', calendar.holiday_name(a_saturday)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_a_day_of_week_with_no_a_name
|
28
|
+
calendar = Calendar.new
|
29
|
+
|
30
|
+
a_saturday = Date.new(2016, 4, 30)
|
31
|
+
|
32
|
+
calendar.add(DayOfWeek.new(a_saturday.wday))
|
33
|
+
|
34
|
+
assert_nil calendar.holiday_name(a_saturday)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_a_day_of_week_can_be_not_a_holiday
|
38
|
+
calendar = Calendar.new
|
39
|
+
|
40
|
+
a_monday = Date.new(2016, 5, 2)
|
41
|
+
|
42
|
+
refute calendar.holiday?(a_monday)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_a_bunch_of_days_can_be_a_holiday
|
46
|
+
calendar = Calendar.new
|
47
|
+
|
48
|
+
a_saturday = Date.new(2016, 4, 30)
|
49
|
+
a_sunday = Date.new(2016, 5, 1)
|
50
|
+
|
51
|
+
calendar.add(DayOfWeek.new(a_saturday.wday))
|
52
|
+
calendar.add(DayOfWeek.new(a_sunday.wday))
|
53
|
+
|
54
|
+
assert calendar.holiday?(a_sunday)
|
55
|
+
assert calendar.holiday?(a_saturday)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_a_day_of_week_rule_can_be_deleted
|
59
|
+
calendar = Calendar.new
|
60
|
+
|
61
|
+
date = Date.new(2016, 5, 1)
|
62
|
+
|
63
|
+
calendar.add(DayOfWeek.new(date.wday))
|
64
|
+
|
65
|
+
assert calendar.holiday?(date)
|
66
|
+
|
67
|
+
calendar.remove(DayOfWeek.new(date.wday))
|
68
|
+
|
69
|
+
refute calendar.holiday?(date)
|
70
|
+
end
|
71
|
+
end
|
data/test/easter_test.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class EasterTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_easter
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
date = Date.new(2016, 3, 27)
|
11
|
+
|
12
|
+
calendar.add(Easter)
|
13
|
+
|
14
|
+
assert calendar.holiday?(date)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_easter_can_have_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
date = Date.new(2016, 3, 27)
|
21
|
+
|
22
|
+
Easter.name = 'pascua'
|
23
|
+
|
24
|
+
calendar.add(Easter)
|
25
|
+
|
26
|
+
assert_equal 'pascua', calendar.holiday_name(date)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_not_easter
|
30
|
+
calendar = Calendar.new
|
31
|
+
|
32
|
+
date = Date.new(2016, 3, 26)
|
33
|
+
|
34
|
+
calendar.add(Easter)
|
35
|
+
|
36
|
+
refute calendar.holiday?(date)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_remove_easter
|
40
|
+
calendar = Calendar.new
|
41
|
+
|
42
|
+
date = Date.new(2016, 3, 27)
|
43
|
+
|
44
|
+
calendar.add(Easter)
|
45
|
+
|
46
|
+
assert calendar.holiday?(date)
|
47
|
+
|
48
|
+
calendar.remove(Easter)
|
49
|
+
|
50
|
+
refute calendar.holiday?(date)
|
51
|
+
end
|
52
|
+
end
|
data/test/feriados_test.rb
CHANGED
@@ -4,295 +4,53 @@ class CalendarTest < Minitest::Test
|
|
4
4
|
include Feriados::Rules
|
5
5
|
include Feriados
|
6
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
7
|
def test_load_argentinian_holidays
|
255
8
|
calendar = Calendar.new
|
256
9
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
[
|
264
|
-
[
|
265
|
-
[
|
266
|
-
[
|
267
|
-
[
|
268
|
-
[4,
|
269
|
-
[
|
270
|
-
[
|
271
|
-
[
|
272
|
-
[
|
273
|
-
[
|
274
|
-
[
|
275
|
-
[
|
276
|
-
[
|
277
|
-
[
|
278
|
-
[
|
279
|
-
[12,
|
280
|
-
[
|
10
|
+
file = File.join(__dir__, './argentina.yml')
|
11
|
+
rules = YAML.load_file(file)
|
12
|
+
|
13
|
+
calendar.load(rules)
|
14
|
+
|
15
|
+
holidays2020_data = [
|
16
|
+
[1, 1, 'Año nuevo'],
|
17
|
+
[2, 24, 'Lunes de carnaval'],
|
18
|
+
[2, 25, 'Martes de carnaval'],
|
19
|
+
[3, 23, 'Feriado con fines turísticos'],
|
20
|
+
[3, 24, 'Día Nacional de la Memoria por la Verdad y la Justicia'],
|
21
|
+
[4, 2, 'Día del Veterano y de los Caídos en la Guerra de Malvinas'],
|
22
|
+
[4, 9, 'Jueves Santo'],
|
23
|
+
[4, 10, 'Viernes Santo'],
|
24
|
+
[4, 12, 'Pascua'],
|
25
|
+
[5, 1, 'Día del Trabajador'],
|
26
|
+
[5, 25, 'Día de la Revolución de Mayo'],
|
27
|
+
[6, 15, 'Día Paso a la Inmortalidad del General Martín Miguel de Güemes'],
|
28
|
+
[6, 20, 'Día de la Bandera'],
|
29
|
+
[7, 9, 'Día de la Independencia'],
|
30
|
+
[7, 10, 'Feriado con fines turísticos'],
|
31
|
+
[8, 17, 'Paso a la Inmortalidad del Gral. José de San Martín'],
|
32
|
+
[10, 12, 'Día del Respeto a la Diversidad Cultural'],
|
33
|
+
[11, 23, 'Día de la Soberanía Nacional'],
|
34
|
+
[12, 7, 'Feriado con fines turísticos'],
|
35
|
+
[12, 8, 'Inmaculada Concepción de María'],
|
36
|
+
[12, 25, 'Navidad']
|
281
37
|
]
|
282
38
|
|
283
|
-
|
284
|
-
|
39
|
+
holidays2020_data.each do |month, day, description|
|
40
|
+
date = Date.new(2020, month, day)
|
41
|
+
|
42
|
+
assert calendar.holiday?(date)
|
43
|
+
|
44
|
+
assert_equal description, calendar.holiday_name(date), date
|
285
45
|
end
|
286
46
|
|
287
47
|
date = Date.new(2020, 1, 1)
|
288
|
-
|
289
|
-
0.upto(365) do |day|
|
290
|
-
today = date + day
|
291
|
-
holiday = calendar.holiday?(today)
|
48
|
+
detected_holidays = []
|
292
49
|
|
293
|
-
|
50
|
+
0.upto(365) do |day|
|
51
|
+
detected_holidays << calendar.holiday?(date + day)
|
294
52
|
end
|
295
53
|
|
296
|
-
assert_equal(
|
54
|
+
assert_equal(holidays2020_data.count, detected_holidays.count { |e| e })
|
297
55
|
end
|
298
56
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FixDateTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_a_fix_date_can_be_a_holiday
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
date = Date.new(2016, 1, 1)
|
11
|
+
|
12
|
+
calendar.add(FixDate.new(2016, 1, 1))
|
13
|
+
|
14
|
+
assert calendar.holiday?(date)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_a_fix_date_can_have_a_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
date = Date.new(2016, 1, 1)
|
21
|
+
|
22
|
+
calendar.add(FixDate.new(2016, 1, 1, 'new year'))
|
23
|
+
|
24
|
+
assert calendar.holiday_name(date)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_a_fix_date_can_be_not_a_holiday
|
28
|
+
calendar = Calendar.new
|
29
|
+
|
30
|
+
refute calendar.holiday?(Date.new(2016, 1, 1))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_a_bunch_of_dates_can_be_a_holiday
|
34
|
+
calendar = Calendar.new
|
35
|
+
|
36
|
+
date = Date.new(2016, 4, 29)
|
37
|
+
another_date = Date.new(2016, 4, 30)
|
38
|
+
|
39
|
+
calendar.add(FixDate.new(2016, 4, 29))
|
40
|
+
calendar.add(FixDate.new(2016, 4, 30))
|
41
|
+
|
42
|
+
assert calendar.holiday?(date)
|
43
|
+
assert calendar.holiday?(another_date)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_a_fix_date_rule_can_be_deleted
|
47
|
+
calendar = Calendar.new
|
48
|
+
|
49
|
+
date = Date.new(2016, 5, 1)
|
50
|
+
|
51
|
+
calendar.add(FixDate.new(date.year, date.month, date.day))
|
52
|
+
|
53
|
+
assert calendar.holiday?(date)
|
54
|
+
|
55
|
+
calendar.remove(FixDate.new(date.year, date.month, date.day))
|
56
|
+
|
57
|
+
refute calendar.holiday?(date)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FixWeekDayTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_fix_week_day_rule
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
calendar.add(FixWeekDay.new(4, 1, 11))
|
11
|
+
calendar.add(FixWeekDay.new(3, 1, 8))
|
12
|
+
|
13
|
+
assert calendar.holiday?(Date.new(2016, 11, 28))
|
14
|
+
assert calendar.holiday?(Date.new(2016, 8, 15))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_fix_week_can_have_a_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
calendar.add(FixWeekDay.new(3, 1, 8, 'nice holiday'))
|
21
|
+
|
22
|
+
assert_equal 'nice holiday', calendar.holiday_name(Date.new(2016, 8, 15))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_not_fix_week_day_rule
|
26
|
+
calendar = Calendar.new
|
27
|
+
|
28
|
+
date = Date.new(2016, 5, 2)
|
29
|
+
|
30
|
+
calendar.add(FixWeekDay.new(2, 1, 5))
|
31
|
+
|
32
|
+
refute calendar.holiday?(date)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_remove_fix_week_day_rule
|
36
|
+
calendar = Calendar.new
|
37
|
+
|
38
|
+
date = Date.new(2016, 11, 28)
|
39
|
+
|
40
|
+
calendar.add(FixWeekDay.new(4, 1, 11))
|
41
|
+
|
42
|
+
assert calendar.holiday?(date)
|
43
|
+
|
44
|
+
calendar.remove(FixWeekDay.new(4, 1, 11))
|
45
|
+
|
46
|
+
refute calendar.holiday?(date)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HolyFridayTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_holy_friday
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
date = Date.new(2016, 3, 25)
|
11
|
+
|
12
|
+
calendar.add(HolyFriday)
|
13
|
+
|
14
|
+
assert calendar.holiday?(date)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_holy_friday_has_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
date = Date.new(2016, 3, 25)
|
21
|
+
|
22
|
+
calendar.add(HolyFriday)
|
23
|
+
|
24
|
+
HolyFriday.name = 'viernes santo'
|
25
|
+
|
26
|
+
assert_equal 'viernes santo', calendar.holiday_name(date)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_not_holy_friday
|
30
|
+
calendar = Calendar.new
|
31
|
+
|
32
|
+
date = Date.new(2016, 3, 20)
|
33
|
+
|
34
|
+
calendar.add(HolyFriday)
|
35
|
+
|
36
|
+
refute calendar.holiday?(date)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_remove_holy_friday
|
40
|
+
calendar = Calendar.new
|
41
|
+
|
42
|
+
date = Date.new(2016, 3, 25)
|
43
|
+
|
44
|
+
calendar.add(HolyFriday)
|
45
|
+
|
46
|
+
assert calendar.holiday?(date)
|
47
|
+
|
48
|
+
calendar.remove(HolyFriday)
|
49
|
+
|
50
|
+
refute calendar.holiday?(date)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HolyThursdayTest < Minitest::Test
|
4
|
+
include Feriados::Rules
|
5
|
+
include Feriados
|
6
|
+
|
7
|
+
def test_holy_thursday
|
8
|
+
calendar = Calendar.new
|
9
|
+
|
10
|
+
date = Date.new(2016, 3, 24)
|
11
|
+
|
12
|
+
calendar.add(HolyThursday)
|
13
|
+
|
14
|
+
assert calendar.holiday?(date)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_holy_thursday_has_name
|
18
|
+
calendar = Calendar.new
|
19
|
+
|
20
|
+
date = Date.new(2016, 3, 24)
|
21
|
+
|
22
|
+
calendar.add(HolyThursday)
|
23
|
+
|
24
|
+
HolyThursday.name = 'jueves santo'
|
25
|
+
|
26
|
+
assert_equal 'jueves santo', calendar.holiday_name(date)
|
27
|
+
end
|
28
|
+
end
|
data/test/runner.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feriados
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Rabuini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.17'
|
13
41
|
description: Make holidays calendars from rules
|
14
42
|
email:
|
15
43
|
- srabuini@gmail.com
|
@@ -28,11 +56,19 @@ files:
|
|
28
56
|
- lib/feriados/rules/easter.rb
|
29
57
|
- lib/feriados/rules/fix_date.rb
|
30
58
|
- lib/feriados/rules/fix_week_day.rb
|
59
|
+
- lib/feriados/rules/function.rb
|
31
60
|
- lib/feriados/rules/holy_friday.rb
|
32
61
|
- lib/feriados/rules/holy_thursday.rb
|
33
62
|
- lib/feriados/rules/rule_base.rb
|
34
63
|
- test/date_test.rb
|
64
|
+
- test/day_of_month_test.rb
|
65
|
+
- test/day_off_week_test.rb
|
66
|
+
- test/easter_test.rb
|
35
67
|
- test/feriados_test.rb
|
68
|
+
- test/fix_date_test.rb
|
69
|
+
- test/fix_week_day_test.rb
|
70
|
+
- test/holy_friday_test.rb
|
71
|
+
- test/holy_thursday_test.rb
|
36
72
|
- test/runner.rb
|
37
73
|
- test/test_helper.rb
|
38
74
|
homepage: https://github.com/srabuini/feriados
|
@@ -59,7 +95,14 @@ signing_key:
|
|
59
95
|
specification_version: 4
|
60
96
|
summary: Holidays calendars
|
61
97
|
test_files:
|
98
|
+
- test/holy_thursday_test.rb
|
99
|
+
- test/easter_test.rb
|
62
100
|
- test/date_test.rb
|
101
|
+
- test/fix_week_day_test.rb
|
102
|
+
- test/fix_date_test.rb
|
63
103
|
- test/feriados_test.rb
|
104
|
+
- test/day_off_week_test.rb
|
105
|
+
- test/day_of_month_test.rb
|
64
106
|
- test/test_helper.rb
|
107
|
+
- test/holy_friday_test.rb
|
65
108
|
- test/runner.rb
|