68 lines
2.6 KiB
Ruby
68 lines
2.6 KiB
Ruby
module Holidays
|
|
# This file is generated by the Ruby Holiday gem.
|
|
#
|
|
# Definitions loaded: data/gb.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/gb'
|
|
#
|
|
# More definitions are available at http://code.dunae.ca/holidays.
|
|
module GB # :nodoc:
|
|
DEFINED_REGIONS = [:gb, :je, :gb_jsy, :gg, :gb_gsy, :gb_eng, :gb_wls, :gb_eaw, :gb_nir, :gb_sct, :im, :gb_iom, :gb_con]
|
|
|
|
HOLIDAYS_BY_MONTH = {
|
|
5 => [{:wday => 1, :week => 1, :name => "May Day", :regions => [:gb]},
|
|
{:mday => 9, :name => "Liberation Day", :regions => [:je, :gb_jsy, :gg, :gb_gsy]},
|
|
{:wday => 1, :week => -1, :name => "Bank Holiday", :regions => [:gb]}],
|
|
0 => [{: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]}],
|
|
1 => [{:mday => 1, :name => "New Year's Day", :regions => [:gb]},
|
|
{:mday => 2, :name => "New Year's", :regions => [:gb_sct]}],
|
|
12 => [{:mday => 25, :name => "Christmas Day", :regions => [:gb]},
|
|
{:mday => 26, :name => "Boxing Day", :regions => [:gb]}],
|
|
7 => [{:mday => 5, :name => "Tynwald Day", :regions => [:im, :gb_iom]},
|
|
{:mday => 12, :name => "Battle of the Boyne", :regions => [:gb_nir]}],
|
|
8 => [{:wday => 1, :week => 1, :name => "Bank Holiday", :regions => [:gb_sct]},
|
|
{:wday => 1, :week => -1, :name => "Bank Holiday", :regions => [:gb_eng, :gb_wls, :gb_eaw]}],
|
|
3 => [{:mday => 5, :name => "St. Piran's Day", :regions => [:gb_con]},
|
|
{:mday => 17, :name => "St. Patrick's Day", :regions => [:gb_nir]}]
|
|
}
|
|
|
|
# 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::GB::DEFINED_REGIONS, Holidays::GB::HOLIDAYS_BY_MONTH)
|