feriados 2.1.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 +7 -0
- data/lib/feriados/argentina.rb +61 -0
- data/lib/feriados.rb +93 -0
- data/test/helper.rb +4 -0
- data/test/test_date.rb +74 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 71cd22bc425ac6ae05dc1627bf19c299259854b2
|
4
|
+
data.tar.gz: 81b3267c496407e6c68fd9906198bd7e598f9cc6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a46fc0d08030e46a3305dc3607eff76db05a8af2b6efa3a44a189735643e052c86bdf6a0381dc1f90791c3b8ee3099b2b2c9e1ccd15d0abc844d116a0bb245c2
|
7
|
+
data.tar.gz: a8d4d901173bcfef33a62abbe356f308fe97b3f68389105481024c217203b9163e4ed93b7272540655330a1ed5e33e59529ab074104b9d3e7b7c824e429cae8c
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module Feriados
|
4
|
+
module Argentina
|
5
|
+
# Feriados Fijos
|
6
|
+
Feriados.add 'Año nuevo', day: 1, month: 1
|
7
|
+
Feriados.add 'Día Nacional de la Memoria por la Verdad y la Justicia',
|
8
|
+
day: 24, month: 3
|
9
|
+
Feriados.add 'Día del Veterano y de los Caídos en la Guerra de Malvinas',
|
10
|
+
day: 2, month: 4
|
11
|
+
Feriados.add 'Día del trabajador', day: 1, month: 5
|
12
|
+
Feriados.add 'Día de la Revolución de Mayo', day: 25, month: 5
|
13
|
+
Feriados.add 'Paso a la Inmortalidad del General Manuel Belgrano', day: 20,
|
14
|
+
month: 6
|
15
|
+
Feriados.add 'Día de la Independencia', day: 9, month: 7
|
16
|
+
Feriados.add 'Inmaculada Concepción de María', day: 8, month: 12
|
17
|
+
Feriados.add 'Navidad', day: 25, month: 12
|
18
|
+
|
19
|
+
# Feriados calculados
|
20
|
+
Feriados.add 'easter', function: ->(year) { Feriados.easter(year) }
|
21
|
+
Feriados.add 'Viernes Santo', function: ->(year) { Feriados.easter(year) - 2 }
|
22
|
+
Feriados.add 'Jueves Santo', function: ->(year) { Feriados.easter(year) - 3 }
|
23
|
+
Feriados.add 'Lunes de Carnaval', function: ->(year) { Feriados.easter(year) - 48 }
|
24
|
+
Feriados.add 'Martes de Carnaval', function: ->(year) { Feriados.easter(year) - 47 }
|
25
|
+
|
26
|
+
# Feriados relativos
|
27
|
+
Feriados.add 'Paso a la Inmortalidad del General José de San Martín',
|
28
|
+
day: 17, month: 8, fix_change: [:third, :monday]
|
29
|
+
Feriados.add 'Día del Respeto a la Diversidad Cultural', day: 12, month: 10,
|
30
|
+
fix_change: [:second, :monday]
|
31
|
+
Feriados.add 'Día de la Soberanía Nacional', day: 20, month: 11,
|
32
|
+
fix_change: [:fourth, :monday]
|
33
|
+
|
34
|
+
# Feriados especiales 2012
|
35
|
+
Feriados.add "Día del Bicentenario de la Creación y Primera Jura de la \
|
36
|
+
Bandera Argentina", day: 27, month: 2, year: 2012
|
37
|
+
Feriados.add "Día del Bicentenario de la Batalla de Tucumán", day: 24,
|
38
|
+
month: 9, year: 2012
|
39
|
+
Feriados.add "Feriado puente", day: 30, month: 4, year: 2012
|
40
|
+
Feriados.add "Feriado puente", day: 24, month: 12, year: 2012
|
41
|
+
|
42
|
+
# Feriados especiales 2013
|
43
|
+
Feriados.add "Bicentenario de la Asamblea General Constituyente de 1813",
|
44
|
+
day: 31, month: 1, year: 2013
|
45
|
+
Feriados.add "Día de la Batalla de Salta", day: 20, month: 2
|
46
|
+
Feriados.add "Feriado puente", day: 1, month: 4, year: 2013
|
47
|
+
Feriados.add "Feriado puente", day: 21, month: 6, year: 2013
|
48
|
+
|
49
|
+
# Feriados especiales 2014
|
50
|
+
Feriados.add "Feriado puente", day: 2, month: 5, year: 2014
|
51
|
+
Feriados.add "Feriado puente", day: 26, month: 12, year: 2014
|
52
|
+
|
53
|
+
# Feriados especiales 2015
|
54
|
+
Feriados.add "Feriado puente", day: 23, month: 3, year: 2015
|
55
|
+
Feriados.add "Feriado puente", day: 7, month: 12, year: 2015
|
56
|
+
|
57
|
+
# Feriados especiales 2016
|
58
|
+
Feriados.add "Feriado puente", day: 8, month: 7, year: 2016
|
59
|
+
Feriados.add "Feriado puente", day: 9, month: 12, year: 2016
|
60
|
+
end
|
61
|
+
end
|
data/lib/feriados.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Feriados
|
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
|
+
@holidays_by_month ||= {}
|
9
|
+
month = options[:month] || 0
|
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
|
+
y = year
|
27
|
+
a = y % 19
|
28
|
+
b = y / 100
|
29
|
+
c = y % 100
|
30
|
+
d = b / 4
|
31
|
+
e = b % 4
|
32
|
+
f = (b + 8) / 25
|
33
|
+
g = (b - f + 1) / 3
|
34
|
+
h = (19 * a + b - d - g + 15) % 30
|
35
|
+
i = c / 4
|
36
|
+
k = c % 4
|
37
|
+
l = (32 + 2 * e + 2 * i - h - k) % 7
|
38
|
+
m = (a + 11 * h + 22 * l) / 451
|
39
|
+
month = (h + l - 7 * m + 114) / 31
|
40
|
+
day = ((h + l - 7 * m + 114) % 31) + 1
|
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
|
+
if holidays = @holidays_by_month[month]
|
57
|
+
holidays.each do |holiday|
|
58
|
+
description = holiday[:description]
|
59
|
+
|
60
|
+
date = if holiday[:function]
|
61
|
+
holiday[:function].call(year)
|
62
|
+
elsif holiday[:fix_change]
|
63
|
+
calculated(holiday[:fix_change][0], holiday[:fix_change][1],
|
64
|
+
month, year)
|
65
|
+
elsif holiday[:variable_change]
|
66
|
+
holiday[:variable_change].call(Date.civil(year, month,
|
67
|
+
holiday[:day]))
|
68
|
+
else
|
69
|
+
Date.civil(holiday[:year] || year, month, holiday[:day])
|
70
|
+
end
|
71
|
+
|
72
|
+
if date.between?(start_date, end_date) && date.year == year
|
73
|
+
list << { date: date, description: description }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
list.sort_by { |holidays| holidays[:date] }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Date
|
85
|
+
def is_holiday?
|
86
|
+
holidays = Feriados.between(self, self)
|
87
|
+
holidays && !holidays.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
def is_week_end?
|
91
|
+
self.wday == 6 or self.wday == 0
|
92
|
+
end
|
93
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_date.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#encoding:utf-8
|
2
|
+
|
3
|
+
require 'helper.rb'
|
4
|
+
|
5
|
+
class DateTests < MiniTest::Test
|
6
|
+
def setup
|
7
|
+
@date = Date.civil(2012,1,1)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_extending_date_class
|
11
|
+
assert @date.respond_to?('is_holiday?')
|
12
|
+
assert @date.respond_to?('is_week_end?')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_week_end
|
16
|
+
regulars = [ :monday, :tuesday, :wednesday, :thursday, :friday ]
|
17
|
+
week_end = [ :saturday, :sunday ]
|
18
|
+
nths = [ :first, :second, :third, :fourth ]
|
19
|
+
|
20
|
+
(2012..2015).each do |year|
|
21
|
+
(1..12).each do |month|
|
22
|
+
nths.each do |n|
|
23
|
+
regulars.each do |day|
|
24
|
+
assert !Feriados.calculated(n, day, month, year).is_week_end?
|
25
|
+
end
|
26
|
+
week_end.each do |day|
|
27
|
+
assert Feriados.calculated(n, day, month, year).is_week_end?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_calculated
|
35
|
+
# Día de la bandera.
|
36
|
+
assert_equal 18, Feriados.calculated(:third, :monday, 6, 2012).day
|
37
|
+
assert_equal 17, Feriados.calculated(:third, :monday, 6, 2013).day
|
38
|
+
assert_equal 16, Feriados.calculated(:third, :monday, 6, 2014).day
|
39
|
+
assert_equal 15, Feriados.calculated(:third, :monday, 6, 2015).day
|
40
|
+
|
41
|
+
# Diecisiete de Agosto.
|
42
|
+
assert_equal 20, Feriados.calculated(:third, :monday, 8, 2012).day
|
43
|
+
assert_equal 19, Feriados.calculated(:third, :monday, 8, 2013).day
|
44
|
+
assert_equal 18, Feriados.calculated(:third, :monday, 8, 2014).day
|
45
|
+
assert_equal 17, Feriados.calculated(:third, :monday, 8, 2015).day
|
46
|
+
|
47
|
+
# Easter.
|
48
|
+
assert_equal 8, Feriados.easter(2012).day
|
49
|
+
assert_equal 31, Feriados.easter(2013).day
|
50
|
+
assert_equal 20, Feriados.easter(2014).day
|
51
|
+
assert_equal 5, Feriados.easter(2015).day
|
52
|
+
|
53
|
+
# Carnaval
|
54
|
+
assert_equal 11, (Feriados.easter(2013) - 48).day
|
55
|
+
assert_equal 3, (Feriados.easter(2014) - 48).day
|
56
|
+
assert_equal 16, (Feriados.easter(2015) - 48).day
|
57
|
+
|
58
|
+
assert_equal 12, (Feriados.easter(2013) - 47).day
|
59
|
+
assert_equal 4, (Feriados.easter(2014) - 47).day
|
60
|
+
assert_equal 17, (Feriados.easter(2015) - 47).day
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_fix_holidays
|
64
|
+
2012.upto(2015) do |year|
|
65
|
+
assert Date.civil(year, 1, 1).is_holiday?
|
66
|
+
assert Date.civil(year, 3, 24).is_holiday?
|
67
|
+
assert Date.civil(year, 4, 2).is_holiday?
|
68
|
+
assert Date.civil(year, 5, 1).is_holiday?
|
69
|
+
assert Date.civil(year, 7, 9).is_holiday?
|
70
|
+
assert Date.civil(year, 12, 8).is_holiday?
|
71
|
+
assert Date.civil(year, 12, 25).is_holiday?
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feriados
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Rabuini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Feriados argentinos. Adaptable to other countries
|
14
|
+
email:
|
15
|
+
- srabuini@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/feriados.rb
|
21
|
+
- lib/feriados/argentina.rb
|
22
|
+
- test/helper.rb
|
23
|
+
- test/test_date.rb
|
24
|
+
homepage: https://github.com/srabuini/feriados
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.2.2
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Feriados argentinos
|
48
|
+
test_files:
|
49
|
+
- test/helper.rb
|
50
|
+
- test/test_date.rb
|