This commit is contained in:
Alex Dunae 2007-11-24 00:45:30 +00:00
parent 3781e24a30
commit 02e323ce9c
30 changed files with 1911 additions and 580 deletions

22
MANIFEST Normal file
View file

@ -0,0 +1,22 @@
==== Regional definitions
The following definition files are included in the default
installation:
* holidays/au
* holidays/ca
* holidays/de
* holidays/dk
* holidays/es
* holidays/europe
* holidays/fr
* holidays/gb
* holidays/ie
* holidays/is
* holidays/it
* holidays/lv
* holidays/mx
* holidays/nl
* holidays/north_america
* holidays/united_nations
* holidays/us
* holidays/za

110
bin/build_defs.rb Normal file
View file

@ -0,0 +1,110 @@
require 'yaml'
def parse_holiday_defs(module_name, files)
regions = []
rules_by_month = {}
custom_methods = {}
files.each do |file|
def_file = YAML.load_file(file)
puts " Loading #{file}"
if def_file['months']
puts " - importing dates..."
def_file['months'].each do |month, definitions|
rules_by_month[month] = [] unless rules_by_month[month]
definitions.each do |definition|
rule = {}
definition.each do |key, val|
rule[key] = val
end
rule['regions'] = rule['regions'].collect { |r| r.to_sym }
regions << rule['regions']
exists = false
rules_by_month[month].each do |ex|
if ex['name'] == rule['name'] and ex['wday'] == rule['wday'] and ex['mday'] == rule['mday'] and ex['week'] == rule['week']
ex['regions'] << rule['regions'].flatten
exists = true
end
end
unless exists
rules_by_month[month] << rule
end
end # /defs.each
end
end
if def_file['methods']
puts " - importing methods..."
def_file['methods'].each do |name, code|
custom_methods[name] = code
end # /methods.each
end
end
# Build the definitions
month_strs = []
rules_by_month.each do |month, rules|
month_str = " #{month.to_s} => ["
rule_strings = []
rules.each do |rule|
str = '{'
if rule['mday']
str << ":mday => #{rule['mday']}, "
elsif rule['function']
str << ":function => #{rule['function']}, "
else
str << ":wday => #{rule['wday']}, :week => #{rule['week']}, "
end
# shouldn't allow the same region twice
str << ":name => \"#{rule['name']}\", :regions => [:" + rule['regions'].uniq.join(', :') + "]}"
rule_strings << str
end
month_str << rule_strings.join(",\n ") + "]"
month_strs << month_str
end
month_strs.join(",\n")
# Build the methods
method_str = ''
custom_methods.each do |key, code|
method_str << code + "\n\n"
end
# Build the output file
out =<<-EOC
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: #{files.join(', ')}
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/#{module_name.downcase}'
#
# More definitions are available at http://code.dunae.ca/holidays.
module #{module_name} # :nodoc:
DEFINED_REGIONS = [:#{regions.flatten.uniq.join(', :')}]
HOLIDAYS_BY_MONTH = {
#{month_strs.join(",\n")}
}
#{method_str}
end
end
Holidays.merge_defs(Holidays::#{module_name}::DEFINED_REGIONS, Holidays::#{module_name}::HOLIDAYS_BY_MONTH)
EOC
end

View file

@ -1,119 +0,0 @@
require 'yaml'
#module_name = 'NorthAmerica'
#files = ['data/ca.yaml', 'data/mx.yaml', 'data/us.yaml', 'data/common_methods.yaml', 'data/north_america_informal.yaml']
#module_name = 'Europe'
#files = ['data/dk.yaml', 'data/es.yaml', 'data/fr.yaml', 'data/gb.yaml', 'data/ie.yaml', 'data/is.yaml', 'data/common_methods.yaml']
module_name = 'CA'
files = ['data/ca.yaml', 'data/common_methods.yaml', 'data/north_america_informal.yaml']
regions = []
rules_by_month = {}
custom_methods = {}
files.each do |file|
def_file = YAML.load_file(file)
puts "Loading #{file}"
if def_file['months']
puts " importing dates..."
def_file['months'].each do |month, definitions|
rules_by_month[month] = [] unless rules_by_month[month]
definitions.each do |definition|
rule = {}
definition.each do |key, val|
rule[key] = val
end
rule['regions'] = rule['regions'].collect { |r| r.to_sym }
regions << rule['regions']
exists = false
rules_by_month[month].each do |ex|
if ex['name'] == rule['name'] and ex['wday'] == rule['wday'] and ex['mday'] == rule['mday'] and ex['week'] == rule['week']
ex['regions'] << rule['regions'].flatten
exists = true
end
end
unless exists
rules_by_month[month] << rule
end
end # /defs.each
end
end
if def_file['methods']
puts " importing methods..."
def_file['methods'].each do |name, code|
custom_methods[name] = code
end # /methods.each
end
end
# Build the definitions
month_strs = []
rules_by_month.each do |month, rules|
month_str = " #{month.to_s} => ["
rule_strings = []
rules.each do |rule|
str = '{'
if rule['mday']
str << ":mday => #{rule['mday']}, "
elsif rule['function']
str << ":function => #{rule['function']}, "
else
str << ":wday => #{rule['wday']}, :week => #{rule['week']}, "
end
# shouldn't allow the same region twice
str << ":name => \"#{rule['name']}\", :regions => [:" + rule['regions'].uniq.join(', :') + "]}"
rule_strings << str
end
month_str << rule_strings.join(",\n ") + "]"
month_strs << month_str
end
month_strs.join(",\n")
# Build the methods
method_str = ''
custom_methods.each do |key, code|
method_str << code + "\n\n"
end
# Build the output file
out =<<-EOC
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: #{files.join(', ')}
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/#{module_name.downcase}'
#
# More definitions are available at http://code.dunae.ca/holidays.
module #{module_name} # :nodoc:
DEFINED_REGIONS = [:#{regions.flatten.uniq.join(', :')}]
HOLIDAYS_BY_MONTH = {
#{month_strs.join(",\n")}
}
#{method_str}
end
end
Holidays.merge_defs(Holidays::#{module_name}::DEFINED_REGIONS, Holidays::#{module_name}::HOLIDAYS_BY_MONTH)
EOC
File.open("test_file.rb","w") do |file|
file.puts out
end

59
data/de.yaml Normal file
View file

@ -0,0 +1,59 @@
# German holiday definitions for the Ruby Holiday gem.
#
# Updated: 2008-11-23.
# Sources:
# - http://en.wikipedia.org/wiki/Holidays_in_Germany
---
months:
0:
- name: Karfreitag
regions: [de]
function: lambda { |year| easter(year)-2 }
- name: Ostermontag
regions: [de]
function: lambda { |year| easter(year)+1 }
- name: Christi Himmelfahrt
regions: [de]
function: lambda { |year| easter(year)+39 }
- name: Pfingstmontag
regions: [de]
function: lambda { |year| easter(year)+50 }
- name: Fronleichnam
regions: [de_bw, de_by, de_he, de_nw, de_rp, de_sl, de_sn, de_th]
function: lambda { |year| easter(year)+60 }
1:
- name: Neujahrstag
regions: [de]
mday: 1
- name: Heilige Drei Könige
regions: [de_bw, de_by]
mday: 6
5:
- name: Tag der Arbeit
regions: [de]
mday: 1
- name: Victoire 1945
regions: [de]
mday: 8
8:
- name: Mariä Himmelfahrt
regions: [de_by]
mday: 15
10:
- name: Tag der Deutschen Einheit
regions: [de]
mday: 3
- name: Reformationstag
regions: [de_bb, de_mv, de_sn, de_st, de_th]
mday: 31
11:
- name: Allerheiligen
regions: [de_bw, de_by, de_nw, de_rp, de_sl]
mday: 1
12:
- name: 1. Weihnachtstag
regions: [de]
mday: 25
- name: 2. Weihnachtstag
regions: [de]
mday: 25

51
data/it.yaml Normal file
View file

@ -0,0 +1,51 @@
# Italian holiday definitions for the Ruby Holiday gem.
#
# Updated: 2008-11-23.
# Sources:
# - http://en.wikipedia.org/wiki/Holidays_in_Italy
---
months:
0:
- name: Pasqua
regions: [it]
function: lambda { |year| easter(year) }
- name: Lunedì dell'Angelo
regions: [it]
function: lambda { |year| easter(year)+1 }
1:
- name: Capodanno
regions: [it]
mday: 1
- name: Epifania
regions: [it]
mday: 6
4:
- name: Festa della Liberazione
regions: [it]
mday: 25
5:
- name: Festa dei Lavoratori
regions: [it]
mday: 1
6:
- name: Festa della Repubblica
regions: [it]
mday: 2
8:
- name: Assunzione
regions: [it]
mday: 15
11:
- name: Ognissanti
regions: [it]
mday: 1
12:
- name: Immacolata Concezione
regions: [it]
mday: 8
- name: Natale
regions: [it]
mday: 25
- name: Santo Stefano
regions: [it]
mday: 26

49
data/lv.yaml Normal file
View file

@ -0,0 +1,49 @@
# Latvian holiday definitions for the Ruby Holiday gem.
#
# Updated: 2008-11-23.
# Sources:
# - http://en.wikipedia.org/wiki/Holidays_in_Latvia
---
months:
0:
- name: Liela Piektdiena
regions: [lv]
function: lambda { |year| easter(year)-2 }
- name: Lieldienas
regions: [lv]
function: lambda { |year| easter(year) }
- name: 2. Lieldienas
regions: [lv]
function: lambda { |year| easter(year)+1 }
1:
- name: Jaunais Gads
regions: [lv]
mday: 1
5:
- name: Darba svetki
regions: [lv]
mday: 1
- name: Neatkaribas deklaracijas pasludinašanas diena
regions: [lv]
mday: 4
6:
- name: Ligo Diena
regions: [lv]
mday: 23
- name: Jani
regions: [lv]
mday: 24
11:
- name: Latvijas Republikas proklamešanas diena
regions: [lv]
mday: 18
12:
- name: Ziemassvetki
regions: [lv]
mday: 25
- name: 2. Ziemassvetki
regions: [lv]
mday: 25
- name: Vecgada vakars
regions: [lv]
mday: 31

51
data/nl.yaml Normal file
View file

@ -0,0 +1,51 @@
# Dutch holiday definitions for the Ruby Holiday gem.
#
# Updated: 2008-11-23.
# Sources:
# - http://en.wikipedia.org/wiki/Public_holidays_in_the_Netherlands
---
months:
0:
- name: Goede Vrijdag
regions: [nl]
function: lambda { |year| easter(year)-2 }
- name: Pasen
regions: [nl]
function: lambda { |year| easter(year) }
- name: Pasen
regions: [nl]
function: lambda { |year| easter(year)+1 }
- name: Hemelvaartsdag
regions: [nl]
function: lambda { |year| easter(year)+40 }
- name: Pinksteren
regions: [nl]
function: lambda { |year| easter(year)+49 }
- name: Pinksteren
regions: [nl]
function: lambda { |year| easter(year)+50 }
1:
- name: Nieuwjaar
regions: [nl]
mday: 1
4:
- name: Koninginnedag
regions: [nl]
mday: 30
5:
- name: Dodenherdenking
regions: [nl]
mday: 4
- name: Bevrijdingsdag
regions: [nl]
mday: 5
12:
- name: Sinterklaas
regions: [nl]
mday: 5
- name: Kerstmis
regions: [nl]
mday: 25
- name: Kerstmis
regions: [nl]
mday: 26

View file

@ -1,5 +1,7 @@
$:.unshift File.dirname(__FILE__)
require 'digest/md5'
module Holidays
# Exception thrown when an unknown region is requested.
class UnkownRegionError < ArgumentError; end
@ -8,6 +10,7 @@ module Holidays
@@regions = []
@@holidays_by_month = {}
@@proc_cache = {}
WEEKS = {:first => 1, :second => 2, :third => 3, :fourth => 4, :fifth => 5, :last => -1}
MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
@ -61,7 +64,8 @@ module Holidays
next unless in_region?(regions, h[:regions])
if h[:function]
result = h[:function].call(year)
#result = h[:function].call(year)
result = call_proc(h[:function], year)
if result.kind_of?(Date)
month = result.month
mday = result.mday
@ -129,6 +133,39 @@ private
available.any? { |r| requested.include?(r) }
end
# Call a proc function defined in a holiday definition file.
#
# Procs are cached.
#
# ==== Benchmarks
#
# Lookup Easter Sunday, with caching, by number of iterations:
#
# user system total real
# 0001 0.000000 0.000000 0.000000 ( 0.000000)
# 0010 0.000000 0.000000 0.000000 ( 0.000000)
# 0100 0.078000 0.000000 0.078000 ( 0.078000)
# 1000 0.641000 0.000000 0.641000 ( 0.641000)
# 5000 3.172000 0.015000 3.187000 ( 3.219000)
#
# Lookup Easter Sunday, without caching, by number of iterations:
#
# user system total real
# 0001 0.000000 0.000000 0.000000 ( 0.000000)
# 0010 0.016000 0.000000 0.016000 ( 0.016000)
# 0100 0.125000 0.000000 0.125000 ( 0.125000)
# 1000 1.234000 0.000000 1.234000 ( 1.234000)
# 5000 6.094000 0.031000 6.125000 ( 6.141000)
def self.call_proc(function, year) # :nodoc:
proc_key = Digest::MD5.hexdigest("#{function.to_s}_#{year.to_s}")
@@proc_cache[proc_key] = function.call(year) unless @@proc_cache[proc_key]
@@proc_cache[proc_key]
end
end
@ -164,24 +201,27 @@ class Date
# week.
#
# ==== Parameters
# [<tt>year</tt>] Integer.
# [<tt>year</tt>] Integer.
# [<tt>month</tt>] Integer from 1-12.
# [<tt>week</tt>] One of <tt>:first</tt>, <tt>:second</tt>, <tt>:third</tt>,
# <tt>:fourth</tt> or <tt>:fifth</tt>.
# [<tt>wday</tt>] Day of the week as an integer from 0 (Sunday) to 6
# (Saturday) or as a symbol (e.g. <tt>:monday</tt>).
# [<tt>week</tt>] One of <tt>:first</tt>, <tt>:second</tt>, <tt>:third</tt>,
# <tt>:fourth</tt> or <tt>:fifth</tt>.
# [<tt>wday</tt>] Day of the week as an integer from 0 (Sunday) to 6
# (Saturday) or as a symbol (e.g. <tt>:monday</tt>).
#
# Returns an integer.
#
# ===== Examples
# First Monday of January, 2008:
# calculate_mday(2008, 1, :first, :monday)
# => 7
#
# Third Thursday of December, 2008:
# calculate_mday(2008, 12, :third, 4)
# => 18
#
# Last Monday of January, 2008:
# calculate_mday(2008, 1, :last, 1)
# => 28
#--
# see http://www.irt.org/articles/js050/index.htm
def self.calculate_mday(year, month, week, wday)

76
lib/holidays/au.rb Normal file
View file

@ -0,0 +1,76 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/au.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/au'
#
# More definitions are available at http://code.dunae.ca/holidays.
module AU # :nodoc:
DEFINED_REGIONS = [:au_qld, :au_nt, :au, :au_tas, :au_wa, :au_vic, :au_act, :au_nsw, :au_sa]
HOLIDAYS_BY_MONTH = {
5 => [{:wday => 1, :week => 1, :name => "Labour Day", :regions => [:au_qld, :au_nt]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:au]},
{:function => lambda { |year| easter(year)-1 }, :name => "Easter Saturday", :regions => [:au]},
{:function => lambda { |year| easter(year)+1 }, :name => "Easter Monday", :regions => [:au, :au_tas]}],
6 => [{:wday => 1, :week => 2, :name => "Queen's Birthday", :regions => [:au]},
{:mday => 6, :name => "Queensland Day", :regions => [:au_qld]}],
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:au]},
{:mday => 26, :name => "Australia Day", :regions => [:au]}],
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:au]},
{:mday => 26, :name => "Boxing Day", :regions => [:au]}],
3 => [{:wday => 1, :week => 1, :name => "Labour Day", :regions => [:au_wa]},
{:wday => 1, :week => 2, :name => "Labour Day", :regions => [:au_vic, :au_tas]}],
4 => [{:mday => 25, :name => "ANZAC Day", :regions => [:au]}],
10 => [{:wday => 1, :week => 1, :name => "Labour Day", :regions => [:au_act, :au_nsw, :au_sa]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
# Monday on or before May 24
def self.ca_victoria_day(year)
date = Date.civil(year,5,24)
if date.wday > 1
date -= (date.wday - 1)
elsif date.wday == 0
date -= 6
end
date
end
end
end
Holidays.merge_defs(Holidays::AU::DEFINED_REGIONS, Holidays::AU::HOLIDAYS_BY_MONTH)

View file

@ -21,7 +21,7 @@ module Holidays
{:function => lambda { |year| easter(year)+1 }, :name => "Easter Monday", :regions => [:ca_qc]}],
11 => [{:mday => 11, :name => "Rememberance Day", :regions => [:ca]}],
6 => [{:mday => 24, :name => "Discovery Day", :regions => [:ca_nf]},
{:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
{:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
{:mday => 21, :name => "National Aboriginal Day", :regions => [:ca_nt]}],
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ca]},
{:mday => 2, :name => "New Year's", :regions => [:ca_qc]}],

66
lib/holidays/de.rb Normal file
View file

@ -0,0 +1,66 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/de.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/de'
#
# More definitions are available at http://code.dunae.ca/holidays.
module DE # :nodoc:
DEFINED_REGIONS = [:de, :de_bw, :de_by, :de_nw, :de_rp, :de_sl, :de_he, :de_sn, :de_th, :de_bb, :de_mv, :de_st]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Tag der Arbeit", :regions => [:de]},
{:mday => 8, :name => "Victoire 1945", :regions => [:de]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Karfreitag", :regions => [:de]},
{:function => lambda { |year| easter(year)+1 }, :name => "Ostermontag", :regions => [:de]},
{:function => lambda { |year| easter(year)+39 }, :name => "Christi Himmelfahrt", :regions => [:de]},
{:function => lambda { |year| easter(year)+50 }, :name => "Pfingstmontag", :regions => [:de]},
{:function => lambda { |year| easter(year)+60 }, :name => "Fronleichnam", :regions => [:de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn, :de_th]}],
11 => [{:mday => 1, :name => "Allerheiligen", :regions => [:de_bw, :de_by, :de_nw, :de_rp, :de_sl]}],
1 => [{:mday => 1, :name => "Neujahrstag", :regions => [:de]},
{:mday => 6, :name => "Heilige Drei Könige", :regions => [:de_bw, :de_by]}],
12 => [{:mday => 25, :name => "1. Weihnachtstag", :regions => [:de]},
{:mday => 25, :name => "2. Weihnachtstag", :regions => [:de]}],
8 => [{:mday => 15, :name => "Mariä Himmelfahrt", :regions => [:de_by]}],
10 => [{:mday => 3, :name => "Tag der Deutschen Einheit", :regions => [:de]},
{:mday => 31, :name => "Reformationstag", :regions => [:de_bb, :de_mv, :de_sn, :de_st, :de_th]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::DE::DEFINED_REGIONS, Holidays::DE::HOLIDAYS_BY_MONTH)

75
lib/holidays/dk.rb Normal file
View file

@ -0,0 +1,75 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/dk.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/dk'
#
# More definitions are available at http://code.dunae.ca/holidays.
module DK # :nodoc:
DEFINED_REGIONS = [:dk, :dk_]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Arbejdernes kampdag", :regions => [:dk]},
{:mday => 5, :name => "Danmarks befrielse", :regions => [:dk]}],
0 => [{:function => lambda { |year| easter(year)-49 }, :name => "Fastelavn", :regions => [:dk]},
{:function => lambda { |year| easter(year)-7 }, :name => "Palmesøndag", :regions => [:dk]},
{:function => lambda { |year| easter(year)-3 }, :name => "Skærtorsdag", :regions => [:dk]},
{:function => lambda { |year| easter(year)-2 }, :name => "Langfredag", :regions => [:dk]},
{:function => lambda { |year| easter(year) }, :name => "Påskedag", :regions => [:dk]},
{:function => lambda { |year| easter(year)+1 }, :name => "2. påskedag", :regions => [:dk]},
{:function => lambda { |year| easter(year)+26 }, :name => "Store Bededag", :regions => [:dk]},
{:function => lambda { |year| easter(year)+40 }, :name => "Kristi Himmelfartsdag", :regions => [:dk, :dk]},
{:function => lambda { |year| easter(year)+49 }, :name => "2. Pinsedag", :regions => [:dk]},
{:function => lambda { |year| easter(year)+50 }, :name => "Pinsedag", :regions => [:dk]}],
11 => [{:mday => 10, :name => "Mortensaften", :regions => [:dk]}],
6 => [{:mday => 5, :name => "Grundlovsdag", :regions => [:dk]},
{:mday => 15, :name => "Valdemarsdag og Genforeningsdag", :regions => [:dk]},
{:mday => 23, :name => "Sankt Hans aften", :regions => [:dk]}],
1 => [{:mday => 1, :name => "Nytårsdag", :regions => [:dk]}],
12 => [{:mday => 13, :name => "Sankt Lucia", :regions => [:dk]},
{:mday => 24, :name => "Juleaftensdag", :regions => [:dk]},
{:mday => 25, :name => "1. juledag", :regions => [:dk]},
{:mday => 26, :name => "2. juledag", :regions => [:dk_]}],
4 => [{:mday => 1, :name => "1. april", :regions => [:dk]},
{:mday => 9, :name => "Danmarks besættelse", :regions => [:dk]},
{:mday => 16, :name => "Dronningens fødselsdag", :regions => [:dk]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::DK::DEFINED_REGIONS, Holidays::DK::HOLIDAYS_BY_MONTH)

80
lib/holidays/es.rb Normal file
View file

@ -0,0 +1,80 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/es.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/es'
#
# More definitions are available at http://code.dunae.ca/holidays.
module ES # :nodoc:
DEFINED_REGIONS = [:es, :es_m, :es_cn, :es_cm, :es_pv, :es_ct, :es_na, :es_v, :es_vc, :es_mu, :es_lo, :es_ib, :es_ga, :es_an, :es_ce, :es_o, :es_ex, :es_ar, :es_cl]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Día del Trabajador", :regions => [:es]},
{:mday => 2, :name => "Fiesta de la Comunidad", :regions => [:es_m]},
{:mday => 30, :name => "Día de las Canarias", :regions => [:es_cn]},
{:mday => 31, :name => "Día de la Región Castilla-La Mancha", :regions => [:es_cm]}],
0 => [{:function => lambda { |year| easter(year)-3 }, :name => "Jueves Santo", :regions => [:es_pv, :es_ct, :es_na, :es_v, :es_vc]},
{:function => lambda { |year| easter(year)-2 }, :name => "Viernes Santo", :regions => [:es]},
{:function => lambda { |year| easter(year)+1 }, :name => "Lunes de Pascua", :regions => [:es_pv, :es_ct, :es_na, :es_v, :es_vc]}],
11 => [{:mday => 1, :name => "Todos los Santos", :regions => [:es]}],
6 => [{:mday => 9, :name => "Día de la Región de Murcia", :regions => [:es_mu]},
{:mday => 9, :name => "Día de La Rioja", :regions => [:es_lo]}],
1 => [{:mday => 1, :name => "Año Nuevo", :regions => [:es]},
{:mday => 6, :name => "Día de Reyes", :regions => [:es]}],
12 => [{:mday => 6, :name => "Día de la Constitución", :regions => [:es]},
{:mday => 8, :name => "Inmaculada Concepción", :regions => [:es]},
{:mday => 25, :name => "Navidad del Señor", :regions => [:es]},
{:mday => 26, :name => "San Esteban", :regions => [:es_ib, :es_ct]}],
7 => [{:mday => 23, :name => "Santiago Apostol", :regions => [:es_ga]}],
2 => [{:mday => 28, :name => "Día de Andalucía", :regions => [:es_an]}],
8 => [{:mday => 15, :name => "Asunción", :regions => [:es]}],
3 => [{:mday => 1, :name => "Día de las Islas Baleares", :regions => [:es_ib]},
{:mday => 19, :name => "San José", :regions => [:es_v, :es_vc, :es_cm, :es_mu, :es_m]}],
9 => [{:mday => 2, :name => "Día de Ceuta", :regions => [:es_ce]},
{:mday => 8, :name => "Día de Asturias", :regions => [:es_o]},
{:mday => 8, :name => "Día de Extremadura", :regions => [:es_ex]},
{:mday => 11, :name => "Fiesta Nacional de Cataluña", :regions => [:es_ct]}],
4 => [{:mday => 23, :name => "San Jorge", :regions => [:es_ar, :es_cl]},
{:mday => 23, :name => "Día de Aragón", :regions => [:es_ar]}],
10 => [{:mday => 9, :name => "Día de Valencia", :regions => [:es_vc, :es_v]},
{:mday => 12, :name => "Día de la Hispanidad", :regions => [:es]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::ES::DEFINED_REGIONS, Holidays::ES::HOLIDAYS_BY_MONTH)

216
lib/holidays/europe.rb Normal file
View file

@ -0,0 +1,216 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/dk.yaml, data/common_methods.yaml, data/de.yaml, data/es.yaml, data/fr.yaml, data/gb.yaml, data/ie.yaml, data/is.yaml, data/it.yaml, data/nl.yaml, data/lv.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/europe'
#
# More definitions are available at http://code.dunae.ca/holidays.
module EUROPE # :nodoc:
DEFINED_REGIONS = [:dk, :is, :dk_, :de, :fr, :de_bw, :de_by, :de_nw, :de_rp, :de_sl, :de_he, :de_sn, :de_th, :de_bb, :de_mv, :de_st, :es, :es_m, :es_cn, :es_cm, :es_pv, :es_ct, :es_na, :es_v, :es_vc, :es_mu, :es_lo, :es_ib, :es_ga, :es_an, :es_ce, :es_o, :es_ex, :es_ar, :es_cl, :gb, :ie, :je, :gb_jsy, :gg, :gb_gsy, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :gb_sct, :im, :gb_iom, :gb_con, :it, :nl, :lv]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Arbejdernes kampdag", :regions => [:dk]},
{:mday => 5, :name => "Danmarks befrielse", :regions => [:dk]},
{:mday => 1, :name => "Tag der Arbeit", :regions => [:de]},
{:mday => 8, :name => "Victoire 1945", :regions => [:de, :fr]},
{:mday => 1, :name => "Día del Trabajador", :regions => [:es]},
{:mday => 2, :name => "Fiesta de la Comunidad", :regions => [:es_m]},
{:mday => 30, :name => "Día de las Canarias", :regions => [:es_cn]},
{:mday => 31, :name => "Día de la Región Castilla-La Mancha", :regions => [:es_cm]},
{:mday => 1, :name => "Fête du travail", :regions => [:fr]},
{:wday => 1, :week => 1, :name => "May Day", :regions => [:gb, :ie]},
{:mday => 9, :name => "Liberation Day", :regions => [:je, :gb_jsy, :gg, :gb_gsy]},
{:wday => 1, :week => -1, :name => "Bank Holiday", :regions => [:gb]},
{:mday => 3, :name => "Sjómannadagurinn", :regions => [:is]},
{:mday => 17, :name => "Lýðveldisdagurinn", :regions => [:is]},
{:mday => 1, :name => "Festa dei Lavoratori", :regions => [:it]},
{:mday => 4, :name => "Dodenherdenking", :regions => [:nl]},
{:mday => 5, :name => "Bevrijdingsdag", :regions => [:nl]},
{:mday => 1, :name => "Darba svetki", :regions => [:lv]},
{:mday => 4, :name => "Neatkaribas deklaracijas pasludinašanas diena", :regions => [:lv]}],
0 => [{:function => lambda { |year| easter(year)-49 }, :name => "Fastelavn", :regions => [:dk]},
{:function => lambda { |year| easter(year)-7 }, :name => "Palmesøndag", :regions => [:dk]},
{:function => lambda { |year| easter(year)-3 }, :name => "Skærtorsdag", :regions => [:dk]},
{:function => lambda { |year| easter(year)-2 }, :name => "Langfredag", :regions => [:dk]},
{:function => lambda { |year| easter(year) }, :name => "Påskedag", :regions => [:dk]},
{:function => lambda { |year| easter(year)+1 }, :name => "2. påskedag", :regions => [:dk]},
{:function => lambda { |year| easter(year)+26 }, :name => "Store Bededag", :regions => [:dk, :is]},
{:function => lambda { |year| easter(year)+40 }, :name => "Kristi Himmelfartsdag", :regions => [:dk, :dk, :is]},
{:function => lambda { |year| easter(year)+49 }, :name => "2. Pinsedag", :regions => [:dk, :is]},
{:function => lambda { |year| easter(year)+50 }, :name => "Pinsedag", :regions => [:dk, :is]},
{:function => lambda { |year| easter(year)-2 }, :name => "Karfreitag", :regions => [:de]},
{:function => lambda { |year| easter(year)+1 }, :name => "Ostermontag", :regions => [:de]},
{:function => lambda { |year| easter(year)+39 }, :name => "Christi Himmelfahrt", :regions => [:de]},
{:function => lambda { |year| easter(year)+50 }, :name => "Pfingstmontag", :regions => [:de]},
{:function => lambda { |year| easter(year)+60 }, :name => "Fronleichnam", :regions => [:de_bw, :de_by, :de_he, :de_nw, :de_rp, :de_sl, :de_sn, :de_th]},
{:function => lambda { |year| easter(year)-3 }, :name => "Jueves Santo", :regions => [:es_pv, :es_ct, :es_na, :es_v, :es_vc]},
{:function => lambda { |year| easter(year)-2 }, :name => "Viernes Santo", :regions => [:es]},
{:function => lambda { |year| easter(year)+1 }, :name => "Lunes de Pascua", :regions => [:es_pv, :es_ct, :es_na, :es_v, :es_vc]},
{:function => lambda { |year| easter(year) }, :name => "Pâques", :regions => [:fr]},
{:function => lambda { |year| easter(year)+40 }, :name => "Ascension", :regions => [:fr]},
{:function => lambda { |year| easter(year)+49 }, :name => "Pentecôte", :regions => [:fr]},
{:function => lambda { |year| easter(year)+50 }, :name => "Lundi de Pentecôte", :regions => [:fr]},
{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:gb]},
{:function => lambda { |year| easter(year) }, :name => "Easter Sunday", :regions => [:gb]},
{:function => lambda { |year| easter(year)+1 }, :name => "Easter Monday", :regions => [:gb_eng, :gb_wls, :gb_eaw, :gb_nir, :ie]},
{:function => lambda { |year| easter(year)-48 }, :name => "Bolludagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-47 }, :name => "Sprengidagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-46 }, :name => "Öskudagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-7 }, :name => "Pálmasunnudagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-3 }, :name => "Skírdagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-2 }, :name => "Föstudaginn langi", :regions => [:is]},
{:function => lambda { |year| easter(year) }, :name => "Páskadagur", :regions => [:is]},
{:function => lambda { |year| easter(year)+1 }, :name => "Annar í páskum", :regions => [:is]},
{:function => lambda { |year| easter(year) }, :name => "Pasqua", :regions => [:it]},
{:function => lambda { |year| easter(year)+1 }, :name => "Lunedì dell'Angelo", :regions => [:it]},
{:function => lambda { |year| easter(year)-2 }, :name => "Goede Vrijdag", :regions => [:nl]},
{:function => lambda { |year| easter(year) }, :name => "Pasen", :regions => [:nl, :nl]},
{:function => lambda { |year| easter(year)+40 }, :name => "Hemelvaartsdag", :regions => [:nl]},
{:function => lambda { |year| easter(year)+49 }, :name => "Pinksteren", :regions => [:nl, :nl]},
{:function => lambda { |year| easter(year)-2 }, :name => "Liela Piektdiena", :regions => [:lv]},
{:function => lambda { |year| easter(year) }, :name => "Lieldienas", :regions => [:lv]},
{:function => lambda { |year| easter(year)+1 }, :name => "2. Lieldienas", :regions => [:lv]}],
11 => [{:mday => 10, :name => "Mortensaften", :regions => [:dk]},
{:mday => 1, :name => "Allerheiligen", :regions => [:de_bw, :de_by, :de_nw, :de_rp, :de_sl]},
{:mday => 1, :name => "Todos los Santos", :regions => [:es]},
{:mday => 1, :name => "Toussaint", :regions => [:fr]},
{:mday => 11, :name => "Armistice 1918", :regions => [:fr]},
{:mday => 16, :name => "Dagur íslenskrar tungu", :regions => [:is]},
{:mday => 1, :name => "Ognissanti", :regions => [:it]},
{:mday => 18, :name => "Latvijas Republikas proklamešanas diena", :regions => [:lv]}],
6 => [{:mday => 5, :name => "Grundlovsdag", :regions => [:dk]},
{:mday => 15, :name => "Valdemarsdag og Genforeningsdag", :regions => [:dk]},
{:mday => 23, :name => "Sankt Hans aften", :regions => [:dk]},
{:mday => 9, :name => "Día de la Región de Murcia", :regions => [:es_mu]},
{:mday => 9, :name => "Día de La Rioja", :regions => [:es_lo]},
{:wday => 1, :week => 1, :name => "Labour Day/May Day", :regions => [:ie]},
{:mday => 2, :name => "Festa della Repubblica", :regions => [:it]},
{:mday => 23, :name => "Ligo Diena", :regions => [:lv]},
{:mday => 24, :name => "Jani", :regions => [:lv]}],
1 => [{:mday => 1, :name => "Nytårsdag", :regions => [:dk]},
{:mday => 1, :name => "Neujahrstag", :regions => [:de]},
{:mday => 6, :name => "Heilige Drei Könige", :regions => [:de_bw, :de_by]},
{:mday => 1, :name => "Año Nuevo", :regions => [:es]},
{:mday => 6, :name => "Día de Reyes", :regions => [:es]},
{:mday => 1, :name => "Jour de l'an", :regions => [:fr]},
{:mday => 1, :name => "New Year's Day", :regions => [:gb, :ie]},
{:mday => 2, :name => "New Year's", :regions => [:gb_sct]},
{:mday => 1, :name => "Nýársdagur", :regions => [:is]},
{:mday => 6, :name => "Þrettándinn", :regions => [:is]},
{:mday => 19, :name => "Bóndadagur", :regions => [:is]},
{:mday => 1, :name => "Capodanno", :regions => [:it]},
{:mday => 6, :name => "Epifania", :regions => [:it]},
{:mday => 1, :name => "Nieuwjaar", :regions => [:nl]},
{:mday => 1, :name => "Jaunais Gads", :regions => [:lv]}],
12 => [{:mday => 13, :name => "Sankt Lucia", :regions => [:dk]},
{:mday => 24, :name => "Juleaftensdag", :regions => [:dk]},
{:mday => 25, :name => "1. juledag", :regions => [:dk]},
{:mday => 26, :name => "2. juledag", :regions => [:dk_]},
{:mday => 25, :name => "1. Weihnachtstag", :regions => [:de]},
{:mday => 25, :name => "2. Weihnachtstag", :regions => [:de]},
{:mday => 6, :name => "Día de la Constitución", :regions => [:es]},
{:mday => 8, :name => "Inmaculada Concepción", :regions => [:es]},
{:mday => 25, :name => "Navidad del Señor", :regions => [:es]},
{:mday => 26, :name => "San Esteban", :regions => [:es_ib, :es_ct]},
{:mday => 25, :name => "Nöel", :regions => [:fr]},
{:mday => 25, :name => "Christmas Day", :regions => [:gb, :ie]},
{:mday => 26, :name => "Boxing Day", :regions => [:gb]},
{:mday => 26, :name => "St. Stephen's Day", :regions => [:ie]},
{:mday => 24, :name => "Jól", :regions => [:is]},
{:mday => 25, :name => "Jól", :regions => [:is]},
{:mday => 26, :name => "Jól", :regions => [:is]},
{:mday => 31, :name => "Gamlárskvöld", :regions => [:is]},
{:mday => 8, :name => "Immacolata Concezione", :regions => [:it]},
{:mday => 25, :name => "Natale", :regions => [:it]},
{:mday => 26, :name => "Santo Stefano", :regions => [:it]},
{:mday => 5, :name => "Sinterklaas", :regions => [:nl]},
{:mday => 25, :name => "Kerstmis", :regions => [:nl]},
{:mday => 26, :name => "Kerstmis", :regions => [:nl]},
{:mday => 25, :name => "Ziemassvetki", :regions => [:lv]},
{:mday => 25, :name => "2. Ziemassvetki", :regions => [:lv]},
{:mday => 31, :name => "Vecgada vakars", :regions => [:lv]}],
7 => [{:mday => 23, :name => "Santiago Apostol", :regions => [:es_ga]},
{:mday => 14, :name => "Fête nationale", :regions => [:fr]},
{:mday => 5, :name => "Tynwald Day", :regions => [:im, :gb_iom]},
{:mday => 12, :name => "Battle of the Boyne", :regions => [:gb_nir]}],
2 => [{:mday => 28, :name => "Día de Andalucía", :regions => [:es_an]},
{:mday => 18, :name => "Konudagur", :regions => [:is]}],
8 => [{:mday => 15, :name => "Mariä Himmelfahrt", :regions => [:de_by]},
{:mday => 15, :name => "Asunción", :regions => [:es]},
{:mday => 15, :name => "Assomption", :regions => [:fr]},
{:wday => 1, :week => 1, :name => "Bank Holiday", :regions => [:gb_sct]},
{:wday => 1, :week => -1, :name => "Bank Holiday", :regions => [:gb_eng, :gb_wls, :gb_eaw]},
{:wday => 1, :week => 1, :name => "August Holiday", :regions => [:ie]},
{:wday => 1, :week => 1, :name => "Frídagur verslunarmanna", :regions => [:is]},
{:mday => 15, :name => "Assunzione", :regions => [:it]}],
3 => [{:mday => 1, :name => "Día de las Islas Baleares", :regions => [:es_ib]},
{:mday => 19, :name => "San José", :regions => [:es_v, :es_vc, :es_cm, :es_mu, :es_m]},
{:mday => 5, :name => "St. Piran's Day", :regions => [:gb_con]},
{:mday => 17, :name => "St. Patrick's Day", :regions => [:gb_nir, :ie]}],
9 => [{:mday => 2, :name => "Día de Ceuta", :regions => [:es_ce]},
{:mday => 8, :name => "Día de Asturias", :regions => [:es_o]},
{:mday => 8, :name => "Día de Extremadura", :regions => [:es_ex]},
{:mday => 11, :name => "Fiesta Nacional de Cataluña", :regions => [:es_ct]}],
4 => [{:mday => 1, :name => "1. april", :regions => [:dk]},
{:mday => 9, :name => "Danmarks besættelse", :regions => [:dk]},
{:mday => 16, :name => "Dronningens fødselsdag", :regions => [:dk]},
{:mday => 23, :name => "San Jorge", :regions => [:es_ar, :es_cl]},
{:mday => 23, :name => "Día de Aragón", :regions => [:es_ar]},
{:mday => 25, :name => "Festa della Liberazione", :regions => [:it]},
{:mday => 30, :name => "Koninginnedag", :regions => [:nl]}],
10 => [{:mday => 3, :name => "Tag der Deutschen Einheit", :regions => [:de]},
{:mday => 31, :name => "Reformationstag", :regions => [:de_bb, :de_mv, :de_sn, :de_st, :de_th]},
{:mday => 9, :name => "Día de Valencia", :regions => [:es_vc, :es_v]},
{:mday => 12, :name => "Día de la Hispanidad", :regions => [:es]},
{:wday => 1, :week => -1, :name => "October Holiday", :regions => [:ie]}]
}
# Iceland: first day of summer (Thursday after 18 April)
def self.is_sumardagurinn_fyrsti(year)
date = Date.civil(year,4,18)
if date.wday < 4
date += (4 - date.wday)
else date
date += (11 - date.wday)
end
date
end
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::EUROPE::DEFINED_REGIONS, Holidays::EUROPE::HOLIDAYS_BY_MONTH)

63
lib/holidays/fr.rb Normal file
View file

@ -0,0 +1,63 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/fr.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/fr'
#
# More definitions are available at http://code.dunae.ca/holidays.
module FR # :nodoc:
DEFINED_REGIONS = [:fr]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Fête du travail", :regions => [:fr]},
{:mday => 8, :name => "Victoire 1945", :regions => [:fr]}],
0 => [{:function => lambda { |year| easter(year) }, :name => "Pâques", :regions => [:fr]},
{:function => lambda { |year| easter(year)+40 }, :name => "Ascension", :regions => [:fr]},
{:function => lambda { |year| easter(year)+49 }, :name => "Pentecôte", :regions => [:fr]},
{:function => lambda { |year| easter(year)+50 }, :name => "Lundi de Pentecôte", :regions => [:fr]}],
11 => [{:mday => 1, :name => "Toussaint", :regions => [:fr]},
{:mday => 11, :name => "Armistice 1918", :regions => [:fr]}],
1 => [{:mday => 1, :name => "Jour de l'an", :regions => [:fr]}],
12 => [{:mday => 25, :name => "Nöel", :regions => [:fr]}],
7 => [{:mday => 14, :name => "Fête nationale", :regions => [:fr]}],
8 => [{:mday => 15, :name => "Assomption", :regions => [:fr]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::FR::DEFINED_REGIONS, Holidays::FR::HOLIDAYS_BY_MONTH)

86
lib/holidays/is.rb Normal file
View file

@ -0,0 +1,86 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/is.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/is'
#
# More definitions are available at http://code.dunae.ca/holidays.
module IS # :nodoc:
DEFINED_REGIONS = [:is]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 3, :name => "Sjómannadagurinn", :regions => [:is]},
{:mday => 17, :name => "Lýðveldisdagurinn", :regions => [:is]}],
0 => [{:function => lambda { |year| easter(year)-48 }, :name => "Bolludagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-47 }, :name => "Sprengidagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-46 }, :name => "Öskudagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-7 }, :name => "Pálmasunnudagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-3 }, :name => "Skírdagur", :regions => [:is]},
{:function => lambda { |year| easter(year)-2 }, :name => "Föstudaginn langi", :regions => [:is]},
{:function => lambda { |year| easter(year) }, :name => "Páskadagur", :regions => [:is]},
{:function => lambda { |year| easter(year)+1 }, :name => "Annar í páskum", :regions => [:is]},
{:function => lambda { |year| easter(year)+26 }, :name => "Store Bededag", :regions => [:is]},
{:function => lambda { |year| easter(year)+40 }, :name => "Kristi Himmelfartsdag", :regions => [:is, :is]},
{:function => lambda { |year| easter(year)+49 }, :name => "2. Pinsedag", :regions => [:is]},
{:function => lambda { |year| easter(year)+50 }, :name => "Pinsedag", :regions => [:is]}],
11 => [{:mday => 16, :name => "Dagur íslenskrar tungu", :regions => [:is]}],
1 => [{:mday => 1, :name => "Nýársdagur", :regions => [:is]},
{:mday => 6, :name => "Þrettándinn", :regions => [:is]},
{:mday => 19, :name => "Bóndadagur", :regions => [:is]}],
12 => [{:mday => 24, :name => "Jól", :regions => [:is]},
{:mday => 25, :name => "Jól", :regions => [:is]},
{:mday => 26, :name => "Jól", :regions => [:is]},
{:mday => 31, :name => "Gamlárskvöld", :regions => [:is]}],
2 => [{:mday => 18, :name => "Konudagur", :regions => [:is]}],
8 => [{:wday => 1, :week => 1, :name => "Frídagur verslunarmanna", :regions => [:is]}]
}
# Iceland: first day of summer (Thursday after 18 April)
def self.is_sumardagurinn_fyrsti(year)
date = Date.civil(year,4,18)
if date.wday < 4
date += (4 - date.wday)
else date
date += (11 - date.wday)
end
date
end
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::IS::DEFINED_REGIONS, Holidays::IS::HOLIDAYS_BY_MONTH)

63
lib/holidays/it.rb Normal file
View file

@ -0,0 +1,63 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/it.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/it'
#
# More definitions are available at http://code.dunae.ca/holidays.
module IT # :nodoc:
DEFINED_REGIONS = [:it]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Festa dei Lavoratori", :regions => [:it]}],
0 => [{:function => lambda { |year| easter(year) }, :name => "Pasqua", :regions => [:it]},
{:function => lambda { |year| easter(year)+1 }, :name => "Lunedì dell'Angelo", :regions => [:it]}],
11 => [{:mday => 1, :name => "Ognissanti", :regions => [:it]}],
6 => [{:mday => 2, :name => "Festa della Repubblica", :regions => [:it]}],
1 => [{:mday => 1, :name => "Capodanno", :regions => [:it]},
{:mday => 6, :name => "Epifania", :regions => [:it]}],
12 => [{:mday => 8, :name => "Immacolata Concezione", :regions => [:it]},
{:mday => 25, :name => "Natale", :regions => [:it]},
{:mday => 26, :name => "Santo Stefano", :regions => [:it]}],
8 => [{:mday => 15, :name => "Assunzione", :regions => [:it]}],
4 => [{:mday => 25, :name => "Festa della Liberazione", :regions => [:it]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::IT::DEFINED_REGIONS, Holidays::IT::HOLIDAYS_BY_MONTH)

63
lib/holidays/lv.rb Normal file
View file

@ -0,0 +1,63 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/lv.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/lv'
#
# More definitions are available at http://code.dunae.ca/holidays.
module LV # :nodoc:
DEFINED_REGIONS = [:lv]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "Darba svetki", :regions => [:lv]},
{:mday => 4, :name => "Neatkaribas deklaracijas pasludinašanas diena", :regions => [:lv]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Liela Piektdiena", :regions => [:lv]},
{:function => lambda { |year| easter(year) }, :name => "Lieldienas", :regions => [:lv]},
{:function => lambda { |year| easter(year)+1 }, :name => "2. Lieldienas", :regions => [:lv]}],
11 => [{:mday => 18, :name => "Latvijas Republikas proklamešanas diena", :regions => [:lv]}],
6 => [{:mday => 23, :name => "Ligo Diena", :regions => [:lv]},
{:mday => 24, :name => "Jani", :regions => [:lv]}],
1 => [{:mday => 1, :name => "Jaunais Gads", :regions => [:lv]}],
12 => [{:mday => 25, :name => "Ziemassvetki", :regions => [:lv]},
{:mday => 25, :name => "2. Ziemassvetki", :regions => [:lv]},
{:mday => 31, :name => "Vecgada vakars", :regions => [:lv]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::LV::DEFINED_REGIONS, Holidays::LV::HOLIDAYS_BY_MONTH)

72
lib/holidays/mx.rb Normal file
View file

@ -0,0 +1,72 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/mx.yaml, data/common_methods.yaml, data/north_america_informal.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/mx'
#
# More definitions are available at http://code.dunae.ca/holidays.
module MX # :nodoc:
DEFINED_REGIONS = [:mx, :us, :ca]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 1, :name => "D\xC3\xADa del Trabajo", :regions => [:mx]},
{:mday => 5, :name => "La Batalla de Puebla", :regions => [:mx]},
{:wday => 0, :week => 3, :name => "Father's Day", :regions => [:us, :ca]}],
0 => [{:function => lambda { |year| easter(year)-3 }, :name => "Good Thursday", :regions => [:mx]},
{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:mx, :us]},
{:function => lambda { |year| easter(year) }, :name => "Easter Sunday", :regions => [:mx]}],
11 => [{:mday => 2, :name => "Dia de Muertos", :regions => [:mx]},
{:wday => 1, :week => 3, :name => "D\xC3\xADa de la Revoluci\xC3\xB3n", :regions => [:mx]}],
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:mx]},
{:mday => 2, :name => "New Year's Day", :regions => [:mx]}],
12 => [{:mday => 12, :name => "Our Lady of Guadalupe's day", :regions => [:mx]},
{:mday => 25, :name => "Christmas Day", :regions => [:mx]}],
2 => [{:wday => 1, :week => 1, :name => "D\xC3\xADa de la Constituci\xC3\xB3n", :regions => [:mx]},
{:mday => 2, :name => "Groundhog Day", :regions => [:us, :ca]},
{:mday => 14, :name => "Valentine's Day", :regions => [:us, :ca]}],
3 => [{:wday => 1, :week => 3, :name => "Natalicio de Benito Ju\xC3\xA1rez", :regions => [:mx]},
{:mday => 17, :name => "St. Patrick's Day", :regions => [:us, :ca]}],
9 => [{:mday => 16, :name => "D\xC3\xADa de Independencia", :regions => [:mx]}],
4 => [{:mday => 1, :name => "April Fool's Day", :regions => [:us, :ca]},
{:mday => 22, :name => "Earth Day", :regions => [:us, :ca]}],
10 => [{:mday => 31, :name => "Halloween", :regions => [:us, :ca]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::MX::DEFINED_REGIONS, Holidays::MX::HOLIDAYS_BY_MONTH)

62
lib/holidays/nl.rb Normal file
View file

@ -0,0 +1,62 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/nl.yaml, data/common_methods.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/nl'
#
# More definitions are available at http://code.dunae.ca/holidays.
module NL # :nodoc:
DEFINED_REGIONS = [:nl]
HOLIDAYS_BY_MONTH = {
5 => [{:mday => 4, :name => "Dodenherdenking", :regions => [:nl]},
{:mday => 5, :name => "Bevrijdingsdag", :regions => [:nl]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Goede Vrijdag", :regions => [:nl]},
{:function => lambda { |year| easter(year) }, :name => "Pasen", :regions => [:nl, :nl]},
{:function => lambda { |year| easter(year)+40 }, :name => "Hemelvaartsdag", :regions => [:nl]},
{:function => lambda { |year| easter(year)+49 }, :name => "Pinksteren", :regions => [:nl, :nl]}],
1 => [{:mday => 1, :name => "Nieuwjaar", :regions => [:nl]}],
12 => [{:mday => 5, :name => "Sinterklaas", :regions => [:nl]},
{:mday => 25, :name => "Kerstmis", :regions => [:nl]},
{:mday => 26, :name => "Kerstmis", :regions => [:nl]}],
4 => [{:mday => 30, :name => "Koninginnedag", :regions => [:nl]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
end
end
Holidays.merge_defs(Holidays::NL::DEFINED_REGIONS, Holidays::NL::HOLIDAYS_BY_MONTH)

View file

@ -1,26 +1,26 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/ca.yaml, data/mx.yaml, data/us.yaml, data/common_methods.yaml, data/north_america_informal.yaml
# Definitions loaded: data/ca.yaml, data/common_methods.yaml, data/north_america_informal.yaml, data/mx.yaml, data/us.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/northamerica'
# require 'path/to/north_america'
#
# More definitions are available at http://code.dunae.ca/holidays.
module NorthAmerica # :nodoc:
DEFINED_REGIONS = [:ca, :ca_qc, :mx, :us, :ca_nf, :ca_nt, :ca_nu, :ca_ab, :ca_on, :ca_sk, :ca_mb, :ca_bc, :ca_ns, :ca_yk]
module NORTH_AMERICA # :nodoc:
DEFINED_REGIONS = [:ca, :ca_qc, :us, :mx, :ca_nf, :ca_nt, :ca_nu, :ca_ab, :ca_on, :ca_sk, :ca_mb, :ca_bc, :ca_ns, :ca_yk]
HOLIDAYS_BY_MONTH = {
5 => [{:function => lambda { |year| ca_victoria_day(year) }, :name => "Victoria Day", :regions => [:ca]},
{:function => lambda { |year| ca_victoria_day(year) }, :name => "National Patriotes Day", :regions => [:ca_qc]},
{:wday => 0, :week => 3, :name => "Father's Day", :regions => [:us, :ca]},
{:mday => 1, :name => "D\xC3\xADa del Trabajo", :regions => [:mx]},
{:mday => 5, :name => "La Batalla de Puebla", :regions => [:mx]},
{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]},
{:wday => 0, :week => 3, :name => "Father's Day", :regions => [:us, :ca]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:ca, :mx, :us]},
{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:ca, :us, :mx]},
{:function => lambda { |year| easter(year)+1 }, :name => "Easter Monday", :regions => [:ca_qc]},
{:function => lambda { |year| easter(year)-3 }, :name => "Good Thursday", :regions => [:mx]},
{:function => lambda { |year| easter(year) }, :name => "Easter Sunday", :regions => [:mx]}],
@ -30,7 +30,7 @@ module Holidays
{:mday => 11, :name => "Veterans Day", :regions => [:us]},
{:wday => 4, :week => 4, :name => "Thanksgiving Day", :regions => [:us]}],
6 => [{:mday => 24, :name => "Discovery Day", :regions => [:ca_nf]},
{:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
{:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
{:mday => 21, :name => "National Aboriginal Day", :regions => [:ca_nt]}],
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ca, :mx, :us]},
{:mday => 2, :name => "New Year's", :regions => [:ca_qc]},
@ -46,9 +46,9 @@ module Holidays
{:mday => 4, :name => "Independence Day", :regions => [:us]}],
2 => [{:wday => 1, :week => 3, :name => "Family Day", :regions => [:ca_ab, :ca_on, :ca_sk]},
{:wday => 1, :week => 3, :name => "Louis Riel Day", :regions => [:ca_mb]},
{:wday => 1, :week => 1, :name => "D\xC3\xADa de la Constituci\xC3\xB3n", :regions => [:mx]},
{:mday => 2, :name => "Groundhog Day", :regions => [:us, :ca]},
{:mday => 14, :name => "Valentine's Day", :regions => [:us, :ca]}],
{:mday => 14, :name => "Valentine's Day", :regions => [:us, :ca]},
{:wday => 1, :week => 1, :name => "D\xC3\xADa de la Constituci\xC3\xB3n", :regions => [:mx]}],
8 => [{:wday => 1, :week => 1, :name => "BC Day", :regions => [:ca_bc]},
{:wday => 1, :week => 1, :name => "Saskatchewan Day", :regions => [:ca_sk]},
{:wday => 1, :week => 1, :name => "Heritage Day", :regions => [:ca_ab]},
@ -56,17 +56,17 @@ module Holidays
{:wday => 1, :week => 1, :name => "Civic Holiday", :regions => [:ca_on]},
{:wday => 1, :week => 3, :name => "Discovery Day", :regions => [:ca_yk]}],
3 => [{:mday => 23, :name => "St. George's Day", :regions => [:ca_nf]},
{:mday => 17, :name => "St. Patrick's Day", :regions => [:us, :ca]},
{:wday => 1, :week => 3, :name => "Natalicio de Benito Ju\xC3\xA1rez", :regions => [:mx]},
{:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:us]},
{:mday => 17, :name => "St. Patrick's Day", :regions => [:us, :ca]}],
{:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:us]}],
9 => [{:wday => 1, :week => 1, :name => "Labour Day", :regions => [:ca]},
{:mday => 16, :name => "D\xC3\xADa de Independencia", :regions => [:mx]},
{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:us]}],
4 => [{:mday => 1, :name => "April Fool's Day", :regions => [:us, :ca]},
{:mday => 22, :name => "Earth Day", :regions => [:us, :ca]}],
10 => [{:wday => 1, :week => 2, :name => "Thanksgiving", :regions => [:ca]},
{:wday => 1, :week => 2, :name => "Columbus Day", :regions => [:us]},
{:mday => 31, :name => "Halloween", :regions => [:us, :ca]}]
{:mday => 31, :name => "Halloween", :regions => [:us, :ca]},
{:wday => 1, :week => 2, :name => "Columbus Day", :regions => [:us]}]
}
# Get the date of Easter in a given year.
@ -117,21 +117,4 @@ end
end
end
Holidays.class_eval do
existing_regions = []
if const_defined?(:DEFINED_REGIONS)
existing_regions = const_get(:DEFINED_REGIONS)
remove_const(:DEFINED_REGIONS)
end
const_set(:DEFINED_REGIONS, existing_regions | Holidays::NorthAmerica::DEFINED_REGIONS)
existing_defs = {}
if const_defined?(:HOLIDAYS_BY_MONTH)
existing_defs = const_get(:HOLIDAYS_BY_MONTH)
remove_const(:HOLIDAYS_BY_MONTH)
end
#const_set(:HOLIDAYS_BY_MONTH, existing_defs.merge(Holidays::NorthAmerica::HOLIDAYS_BY_MONTH))
const_set(:HOLIDAYS_BY_MONTH, Holidays::NorthAmerica::HOLIDAYS_BY_MONTH)
include Holidays::NorthAmerica
end
Holidays.merge_defs(Holidays::NORTH_AMERICA::DEFINED_REGIONS, Holidays::NORTH_AMERICA::HOLIDAYS_BY_MONTH)

View file

@ -0,0 +1,24 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/united_nations.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/united_nations'
#
# More definitions are available at http://code.dunae.ca/holidays.
module UNITED_NATIONS # :nodoc:
DEFINED_REGIONS = [:]
HOLIDAYS_BY_MONTH = {
}
end
end
Holidays.merge_defs(Holidays::UNITED_NATIONS::DEFINED_REGIONS, Holidays::UNITED_NATIONS::HOLIDAYS_BY_MONTH)

75
lib/holidays/us.rb Normal file
View file

@ -0,0 +1,75 @@
module Holidays
# This file is generated by the Ruby Holiday gem.
#
# Definitions loaded: data/us.yaml, data/common_methods.yaml, data/north_america_informal.yaml
#
# To use the definitions in the file, load them right after you load the
# Holiday gem:
#
# require 'holidays'
# require 'path/to/us'
#
# More definitions are available at http://code.dunae.ca/holidays.
module US # :nodoc:
DEFINED_REGIONS = [:us, :ca]
HOLIDAYS_BY_MONTH = {
5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]},
{:wday => 0, :week => 3, :name => "Father's Day", :regions => [:us, :ca]}],
0 => [{:function => lambda { |year| easter(year)-2 }, :name => "Good Friday", :regions => [:us]}],
11 => [{:mday => 11, :name => "Veterans Day", :regions => [:us]},
{:wday => 4, :week => 4, :name => "Thanksgiving Day", :regions => [:us]}],
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:us]},
{:wday => 1, :week => 3, :name => "Martin Luther King, Jr. Day", :regions => [:us]},
{:function => lambda { |year| us_inauguration_day(year) }, :name => "Inauguration Day", :regions => [:us]}],
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:us]}],
7 => [{:mday => 4, :name => "Independence Day", :regions => [:us]}],
2 => [{:mday => 2, :name => "Groundhog Day", :regions => [:us, :ca]},
{:mday => 14, :name => "Valentine's Day", :regions => [:us, :ca]}],
3 => [{:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:us]},
{:mday => 17, :name => "St. Patrick's Day", :regions => [:us, :ca]}],
9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:us]}],
4 => [{:mday => 1, :name => "April Fool's Day", :regions => [:us, :ca]},
{:mday => 22, :name => "Earth Day", :regions => [:us, :ca]}],
10 => [{:wday => 1, :week => 2, :name => "Columbus Day", :regions => [:us]},
{:mday => 31, :name => "Halloween", :regions => [:us, :ca]}]
}
# Get the date of Easter in a given year.
#
# +year+ must be a valid Gregorian year.
#
# Returns a Date object.
#--
# from http://snippets.dzone.com/posts/show/765
# TODO: check year to ensure Gregorian
def self.easter(year)
y = year
a = y % 19
b = y / 100
c = y % 100
d = b / 4
e = b % 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) % 30
i = c / 4
k = c % 4
l = (32 + 2 * e + 2 * i - h - k) % 7
m = (a + 11 * h + 22 * l) / 451
month = (h + l - 7 * m + 114) / 31
day = ((h + l - 7 * m + 114) % 31) + 1
Date.civil(year, month, day)
end
# January 20, every fourth year, following Presidential election
def self.us_inauguration_day(year)
year % 4 == 1 ? 20 : nil
end
end
end
Holidays.merge_defs(Holidays::US::DEFINED_REGIONS, Holidays::US::HOLIDAYS_BY_MONTH)

View file

@ -60,21 +60,4 @@ end
end
end
Holidays.class_eval do
existing_regions = []
if const_defined?(:DEFINED_REGIONS)
existing_regions = const_get(:DEFINED_REGIONS)
remove_const(:DEFINED_REGIONS)
end
const_set(:DEFINED_REGIONS, existing_regions | Holidays::ZA::DEFINED_REGIONS)
existing_defs = {}
if const_defined?(:HOLIDAYS_BY_MONTH)
existing_defs = const_get(:HOLIDAYS_BY_MONTH)
remove_const(:HOLIDAYS_BY_MONTH)
end
#const_set(:HOLIDAYS_BY_MONTH, existing_defs.merge(Holidays::ZA::HOLIDAYS_BY_MONTH))
const_set(:HOLIDAYS_BY_MONTH, Holidays::ZA::HOLIDAYS_BY_MONTH)
include Holidays::ZA
end
Holidays.merge_defs(Holidays::ZA::DEFINED_REGIONS, Holidays::ZA::HOLIDAYS_BY_MONTH)

View file

@ -4,7 +4,31 @@ require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'fileutils'
require 'lib/holidays'
require 'csv'
require 'bin/build_defs'
def_list = {
:au => ['data/au.yaml', 'data/common_methods.yaml'],
:ca => ['data/ca.yaml', 'data/common_methods.yaml', 'data/north_america_informal.yaml'],
:dk => ['data/dk.yaml', 'data/common_methods.yaml'],
:de => ['data/de.yaml', 'data/common_methods.yaml'],
:es => ['data/es.yaml', 'data/common_methods.yaml'],
:fr => ['data/fr.yaml', 'data/common_methods.yaml'],
:gb => ['data/gb.yaml', 'data/common_methods.yaml'],
:ie => ['data/ie.yaml', 'data/common_methods.yaml'],
:is => ['data/is.yaml', 'data/common_methods.yaml'],
:it => ['data/it.yaml', 'data/common_methods.yaml'],
:lv => ['data/lv.yaml', 'data/common_methods.yaml'],
:mx => ['data/mx.yaml', 'data/common_methods.yaml', 'data/north_america_informal.yaml'],
:nl => ['data/nl.yaml', 'data/common_methods.yaml'],
:us => ['data/us.yaml', 'data/common_methods.yaml', 'data/north_america_informal.yaml'],
:united_nations => ['data/united_nations.yaml'],
:za => ['data/za.yaml', 'data/common_methods.yaml']
}
def_list[:north_america] = def_list[:ca] | def_list[:mx] | def_list[:us]
def_list[:europe] = def_list[:dk] | def_list[:de] | def_list[:es] | def_list[:fr] | def_list[:gb] | def_list[:ie] | def_list[:is] | def_list[:it] |def_list[:nl] |def_list[:lv]
desc 'Run the unit tests.'
Rake::TestTask.new do |t|
@ -14,9 +38,43 @@ Rake::TestTask.new do |t|
t.verbose = false
end
task :build_defs do
puts ARGV
puts ARGV[1]
namespace 'definitions' do
task :build_all do
def_list.each do |region, files|
puts "Building #{region.to_s.upcase} definition module:"
files.uniq!
parsed = parse_holiday_defs(region.to_s.upcase, files)
File.open("lib/holidays/#{region.to_s}.rb","w") do |file|
file.puts parsed
end
puts "Done.\n\n"
end
end
end
task :manifest do
File.open("MANIFEST","w") do |file|
file.puts <<-EOH
==== Regional definitions
The following definition files are included in the default
installation:
EOH
# def_list.each do |region, includes|
# file.puts('* holidays/' + region.to_s)
# includes.each do |inc|
# file.puts(' * holidays/' + inc.gsub(/^data\/|\.yaml$/, ''))
# end
# end
FileList.new('lib/holidays/*.rb').each do |str|
file.puts('* ' + str.gsub(/^lib\/|\.rb$/, ''))
end
end
end
@ -26,14 +84,13 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.title = 'Ruby Holidays Gem'
rdoc.options << '--all' << '--inline-source' << '--line-numbers'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('MANIFEST')
rdoc.rdoc_files.include('CUSTOM DATES')
rdoc.rdoc_files.include('REFERENCES')
rdoc.rdoc_files.include('LICENSE')
rdoc.rdoc_files.include('lib/*.rb')
rdoc.rdoc_files.include('lib/holidays/*.rb')
end
spec = Gem::Specification.new do |s|
s.name = 'holidays'
s.version = '0.9.0'

View file

@ -1,19 +1,45 @@
require File.dirname(__FILE__) + '/test_helper'
require 'date'
require 'holidays'
require 'holidays/ca'
require 'benchmark'
n = 10000
Benchmark.bm do |x|
x.report('calculate_mday') do
n.times do
Holidays.calculate_mday(2008, 1, 1, 3)
n = 10000
dt = Date.civil(2035,3,23)
Benchmark.bm do |x|
x.report('0001') do
1.times do
r = Holidays.on(dt, :any)
end
end
x.report('calculate_mdaya') do
n.times do
Holidays.calculate_mdaya(:third, 1, 1, 2008)
x.report('0010') do
10.times do
r = Holidays.on(dt, :any)
end
end
x.report('0100') do
100.times do
r = Holidays.on(dt, :any)
end
end
x.report('1000') do
1000.times do
r = Holidays.on(dt, :any)
end
end
x.report('5000') do
5000.times do
r = Holidays.on(dt, :any)
end
end
end

View file

@ -25,8 +25,6 @@ class HolidaysTests < Test::Unit::TestCase
assert_equal 0, holidays.length
end
def test_requires_valid_regions
assert_raises Holidays::UnkownRegionError do
Holidays.on(Date.civil(2008,1,1), :xx)