feriados 4.4.0 → 4.5.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.
- checksums.yaml +4 -4
- data/lib/feriados/calendar.rb +52 -5
- data/lib/feriados/rules.rb +12 -12
- data/lib/feriados.rb +0 -2
- metadata +25 -32
- data/test/date_test.rb +0 -21
- data/test/day_of_month_test.rb +0 -63
- data/test/day_off_week_test.rb +0 -71
- data/test/easter_test.rb +0 -52
- data/test/feriados_test.rb +0 -66
- data/test/fix_date_test.rb +0 -59
- data/test/fix_week_day_test.rb +0 -48
- data/test/holy_friday_test.rb +0 -52
- data/test/holy_thursday_test.rb +0 -28
- data/test/runner.rb +0 -10
- data/test/test_helper.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee24a27a0eda88f68deda3ffafbd5fc62830ed4cd7334273584b43045d367210
|
4
|
+
data.tar.gz: 0dc144579116f6e0eb1a4e33e94fc3812adc63e08060a4468173b5dc0ee29702
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 361ca07c20034224bcbed30f8a42647975e7bf1e63ae1d1e83c4ca609c3347596d2237aa0532a2730002327dfabb65ce135966070a349b1360a04284d9c59961
|
7
|
+
data.tar.gz: 916b8f3b1c335c4f2906c3447b32b0b191a58d0df70dcedeff487781dd465f97d11ca70f74eec9c83087490c8261208b831249118cff1534f15365c7578a3e73
|
data/lib/feriados/calendar.rb
CHANGED
@@ -27,6 +27,47 @@ module Feriados
|
|
27
27
|
Loader.new(rules, self).load
|
28
28
|
end
|
29
29
|
|
30
|
+
def holidays_in_year(year)
|
31
|
+
start_date = Date.new(year, 1, 1)
|
32
|
+
end_date = Date.new(year, 12, 31)
|
33
|
+
holidays_between(start_date, end_date)
|
34
|
+
end
|
35
|
+
|
36
|
+
def holidays_between(start_date, end_date)
|
37
|
+
holidays = []
|
38
|
+
current_date = start_date
|
39
|
+
|
40
|
+
while current_date <= end_date
|
41
|
+
if holiday?(current_date)
|
42
|
+
holidays << {
|
43
|
+
date: current_date,
|
44
|
+
name: holiday_name(current_date)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
current_date += 1
|
48
|
+
end
|
49
|
+
|
50
|
+
holidays
|
51
|
+
end
|
52
|
+
|
53
|
+
def next_holiday(from_date = Date.today)
|
54
|
+
# Search in the next 2 years to ensure finding at least one holiday
|
55
|
+
end_search_date = Date.new(from_date.year + 2, 12, 31)
|
56
|
+
current_date = from_date
|
57
|
+
|
58
|
+
while current_date <= end_search_date
|
59
|
+
if holiday?(current_date)
|
60
|
+
return {
|
61
|
+
date: current_date,
|
62
|
+
name: holiday_name(current_date)
|
63
|
+
}
|
64
|
+
end
|
65
|
+
current_date += 1
|
66
|
+
end
|
67
|
+
|
68
|
+
nil # No holidays found in the range
|
69
|
+
end
|
70
|
+
|
30
71
|
def eql?(other)
|
31
72
|
rules == other.rules
|
32
73
|
end
|
@@ -41,20 +82,26 @@ module Feriados
|
|
41
82
|
end
|
42
83
|
|
43
84
|
refine Date do
|
44
|
-
@calendar = nil
|
45
|
-
|
46
85
|
def holiday?
|
47
|
-
|
86
|
+
calendar = Date.class_variable_get(:@@calendar) if Date.class_variable_defined?(:@@calendar)
|
87
|
+
return false unless calendar
|
88
|
+
calendar.holiday?(self)
|
48
89
|
end
|
49
90
|
|
50
91
|
def holiday_name
|
51
|
-
|
92
|
+
calendar = Date.class_variable_get(:@@calendar) if Date.class_variable_defined?(:@@calendar)
|
93
|
+
return nil unless calendar
|
94
|
+
calendar.holiday_name(self)
|
52
95
|
end
|
53
96
|
end
|
54
97
|
|
55
98
|
refine Date.singleton_class do
|
56
99
|
def calendar=(calendar)
|
57
|
-
|
100
|
+
class_variable_set(:@@calendar, calendar)
|
101
|
+
end
|
102
|
+
|
103
|
+
def calendar
|
104
|
+
class_variable_get(:@@calendar) if class_variable_defined?(:@@calendar)
|
58
105
|
end
|
59
106
|
end
|
60
107
|
end
|
data/lib/feriados/rules.rb
CHANGED
@@ -18,44 +18,44 @@ module Feriados
|
|
18
18
|
class Rule
|
19
19
|
extend Forwardable
|
20
20
|
|
21
|
-
def_delegators :@
|
21
|
+
def_delegators :@data, :day, :month, :year, :week
|
22
22
|
|
23
|
-
attr_reader :
|
23
|
+
attr_reader :data
|
24
24
|
|
25
|
-
def initialize(
|
26
|
-
@
|
25
|
+
def initialize(data)
|
26
|
+
@data = OpenStruct.new(data)
|
27
27
|
end
|
28
28
|
|
29
29
|
def week_day?
|
30
|
-
|
30
|
+
data.day && data.month && data.week
|
31
31
|
end
|
32
32
|
|
33
33
|
def fix_date?
|
34
|
-
|
34
|
+
data.day && data.month && data.year
|
35
35
|
end
|
36
36
|
|
37
37
|
def day_of_month?
|
38
|
-
|
38
|
+
data.day && data.month && !fix_date? && !week_day?
|
39
39
|
end
|
40
40
|
|
41
41
|
def function?
|
42
42
|
functions = %i[easter holy_thursday holy_friday carnival_monday
|
43
43
|
carnival_tuesday]
|
44
44
|
|
45
|
-
functions.map { |e|
|
45
|
+
functions.map { |e| data.respond_to?(e) }.any?
|
46
46
|
end
|
47
47
|
|
48
48
|
def name
|
49
|
-
|
49
|
+
data[:name] || data.to_h.values.first
|
50
50
|
end
|
51
51
|
|
52
52
|
def function_name
|
53
|
-
|
53
|
+
data.to_h.keys.first.to_s.split('_').collect(&:capitalize).join
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def self.create_with(
|
58
|
-
rule = Rule.new(
|
57
|
+
def self.create_with(data)
|
58
|
+
rule = Rule.new(data)
|
59
59
|
return DayOfMonth.new(rule.day, rule.month, rule.name) if rule.day_of_month?
|
60
60
|
return FixWeekDay.new(rule.week, rule.day, rule.month, rule.name) if rule.week_day?
|
61
61
|
return FixDate.new(rule.year, rule.month, rule.day, rule.name) if rule.fix_date?
|
data/lib/feriados.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feriados
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Rabuini
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: minitest
|
@@ -38,7 +37,22 @@ dependencies:
|
|
38
37
|
- - "~>"
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0.17'
|
41
|
-
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rake
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '13.0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '13.0'
|
54
|
+
description: Make holidays calendars from rules. Supports querying holidays by year,
|
55
|
+
date ranges, and finding next holidays.
|
42
56
|
email:
|
43
57
|
- srabuini@gmail.com
|
44
58
|
executables: []
|
@@ -60,22 +74,13 @@ files:
|
|
60
74
|
- lib/feriados/rules/holy_friday.rb
|
61
75
|
- lib/feriados/rules/holy_thursday.rb
|
62
76
|
- lib/feriados/rules/rule_base.rb
|
63
|
-
- test/date_test.rb
|
64
|
-
- test/day_of_month_test.rb
|
65
|
-
- test/day_off_week_test.rb
|
66
|
-
- test/easter_test.rb
|
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
|
72
|
-
- test/runner.rb
|
73
|
-
- test/test_helper.rb
|
74
77
|
homepage: https://github.com/srabuini/feriados
|
75
78
|
licenses:
|
76
79
|
- MIT
|
77
|
-
metadata:
|
78
|
-
|
80
|
+
metadata:
|
81
|
+
bug_tracker_uri: https://github.com/srabuini/feriados/issues
|
82
|
+
changelog_uri: https://github.com/srabuini/feriados/blob/master/CHANGELOG.md
|
83
|
+
source_code_uri: https://github.com/srabuini/feriados
|
79
84
|
rdoc_options: []
|
80
85
|
require_paths:
|
81
86
|
- lib
|
@@ -90,19 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
95
|
- !ruby/object:Gem::Version
|
91
96
|
version: '0'
|
92
97
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
94
|
-
signing_key:
|
98
|
+
rubygems_version: 3.6.9
|
95
99
|
specification_version: 4
|
96
|
-
summary: Holidays calendars
|
97
|
-
test_files:
|
98
|
-
- test/holy_thursday_test.rb
|
99
|
-
- test/easter_test.rb
|
100
|
-
- test/date_test.rb
|
101
|
-
- test/fix_week_day_test.rb
|
102
|
-
- test/fix_date_test.rb
|
103
|
-
- test/feriados_test.rb
|
104
|
-
- test/day_off_week_test.rb
|
105
|
-
- test/day_of_month_test.rb
|
106
|
-
- test/test_helper.rb
|
107
|
-
- test/holy_friday_test.rb
|
108
|
-
- test/runner.rb
|
100
|
+
summary: Holidays calendars with advanced querying capabilities
|
101
|
+
test_files: []
|
data/test/date_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DateTest < Minitest::Test
|
4
|
-
include Feriados::Rules
|
5
|
-
include Feriados
|
6
|
-
using Feriados
|
7
|
-
|
8
|
-
def test_using_refinements
|
9
|
-
calendar = Calendar.new
|
10
|
-
Date.calendar = calendar
|
11
|
-
|
12
|
-
date = Date.new(2016, 5, 2)
|
13
|
-
|
14
|
-
calendar.add(FixDate.new(date.year, date.month, date.day, 'Bridge'))
|
15
|
-
|
16
|
-
assert calendar.holiday?(date)
|
17
|
-
|
18
|
-
assert date.holiday?
|
19
|
-
assert_equal date.holiday_name, 'Bridge'
|
20
|
-
end
|
21
|
-
end
|
data/test/day_of_month_test.rb
DELETED
@@ -1,63 +0,0 @@
|
|
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
|
data/test/day_off_week_test.rb
DELETED
@@ -1,71 +0,0 @@
|
|
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
DELETED
@@ -1,52 +0,0 @@
|
|
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
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CalendarTest < Minitest::Test
|
4
|
-
include Feriados::Rules
|
5
|
-
include Feriados
|
6
|
-
|
7
|
-
def test_load_argentinian_holidays
|
8
|
-
calendar = Calendar.new
|
9
|
-
|
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']
|
37
|
-
]
|
38
|
-
|
39
|
-
holidays2020_data.each do |month, day, description|
|
40
|
-
date = Date.new(2020, month, day)
|
41
|
-
|
42
|
-
assert calendar.holiday?(date), date
|
43
|
-
|
44
|
-
assert_equal description, calendar.holiday_name(date), date
|
45
|
-
end
|
46
|
-
|
47
|
-
date = Date.new(2020, 1, 1)
|
48
|
-
detected_holidays = []
|
49
|
-
|
50
|
-
0.upto(365) do |day|
|
51
|
-
detected_holidays << calendar.holiday?(date + day)
|
52
|
-
end
|
53
|
-
|
54
|
-
assert_equal(holidays2020_data.count, detected_holidays.count { |e| e })
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_load_incomplete_rules
|
58
|
-
rules = {}
|
59
|
-
|
60
|
-
calendar = Calendar.new
|
61
|
-
|
62
|
-
calendar.load(rules)
|
63
|
-
|
64
|
-
assert_equal calendar, Calendar.new
|
65
|
-
end
|
66
|
-
end
|
data/test/fix_date_test.rb
DELETED
@@ -1,59 +0,0 @@
|
|
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
|
data/test/fix_week_day_test.rb
DELETED
@@ -1,48 +0,0 @@
|
|
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
|
data/test/holy_friday_test.rb
DELETED
@@ -1,52 +0,0 @@
|
|
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
|
data/test/holy_thursday_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
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
DELETED