diff --git a/CHANGELOG b/CHANGELOG index 7c75ecd..56a3ce5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ == 0.9.3 * Added New York Stock Exchange holidays (thank you Alan Larkin). +* Added UPS holidays (thank you Tim Anglade). * Fixed rakefile to force lower case definition file names. == 0.9.2 diff --git a/data/index.yaml b/data/index.yaml index 1ceff4e..6ef2e3c 100644 --- a/data/index.yaml +++ b/data/index.yaml @@ -17,6 +17,7 @@ defs: PT: ['se.yaml'] US: ['us.yaml', 'north_america_informal.yaml'] United_Nations: ['united_nations.yaml'] + UPS: ['ups.yaml'] ZA: ['za.yaml'] North_America: ['ca.yaml', 'mx.yaml', 'us.yaml', 'north_america_informal.yaml'] Europe: ['dk.yaml', 'de.yaml', 'es.yaml', 'fr.yaml', 'gb.yaml', 'ie.yaml', 'is.yaml', 'it.yaml', 'nl.yaml', 'pt.yaml'] diff --git a/data/nyse.yaml b/data/nyse.yaml new file mode 100644 index 0000000..9c40b4d --- /dev/null +++ b/data/nyse.yaml @@ -0,0 +1,63 @@ +# NYSE holiday definitions for the Ruby Holiday gem. +# +# By Alan Larkin +# Source: http://www.nyse.com/about/newsevents/1176373643795.html#earlyclose2008 +# +# Updated 2008-11-19. +--- +months: + 0: + - name: Good Friday + regions: [nyse] + function: easter(year)-2 + 1: + - name: New Year's Day + regions: [nyse] + mday: 1 + - name: Martin Luther King, Jr. Day + week: 3 + regions: [nyse] + wday: 1 + 2: + - name: Presidents' Day + week: 3 + regions: [nyse] + wday: 1 + 5: + - name: Memorial Day + week: -1 + regions: [nyse] + wday: 1 + 7: + - name: Independence Day + regions: [nyse] + mday: 4 + observed: to_weekday_if_weekend + 9: + - name: Labor Day + week: 1 + regions: [nyse] + wday: 1 + 11: + - name: Thanksgiving + week: 4 + regions: [nyse] + wday: 4 + 12: + - name: Christmas Day + regions: [nyse] + mday: 25 + observed: to_weekday_if_weekend +methods: +tests: | + {Date.civil(2008,1,1) => 'New Year\'s Day', + Date.civil(2008,1,21) => 'Martin Luther King, Jr. Day', + Date.civil(2008,2,18) => 'Presidents\' Day', + Date.civil(2008,3,21) => 'Good Friday', + Date.civil(2008,5,26) => 'Memorial Day', + Date.civil(2008,7,4) => 'Independence Day', + Date.civil(2008,9,1) => 'Labor Day', + Date.civil(2008,11,27) => 'Thanksgiving', + Date.civil(2008,12,25) => 'Christmas Day'}.each do |date, name| + assert_equal name, Holidays.on(date, :nyse)[0][:name] + end \ No newline at end of file diff --git a/data/ups.yaml b/data/ups.yaml new file mode 100644 index 0000000..8db4402 --- /dev/null +++ b/data/ups.yaml @@ -0,0 +1,56 @@ +# UPS holiday definitions for the Ruby Holiday gem. +# +# By Tim Anglade +# +# Updated: 2008-09-23. +# Source: http://www.ups.com/content/us/en/resources/ship/imp_exp/operation.html +--- +months: + 1: + - name: New Year's Day + regions: [ups] + mday: 1 + observed: to_weekday_if_weekend + 5: + - name: Memorial Day + week: -1 + regions: [ups] + wday: 1 + 7: + - name: Independence Day + regions: [ups] + mday: 4 + observed: to_weekday_if_weekend + 9: + - name: Labor Day + week: 1 + regions: [ups] + wday: 1 + 11: + - name: Thanksgiving + week: 4 + regions: [ups] + wday: 4 + - name: Day After Thanksgiving + week: 4 + regions: [ups] + wday: 5 + 12: + - name: Christmas Day + regions: [ups] + mday: 25 + observed: to_weekday_if_weekend + - name: New Year's Eve + regions: [ups] + mday: 31 +tests: | + {Date.civil(2008,1,1) => 'New Year\'s Day', + Date.civil(2008,5,26) => 'Memorial Day', + Date.civil(2008,7,4) => 'Independence Day', + Date.civil(2008,9,1) => 'Labor Day', + Date.civil(2008,11,27) => 'Thanksgiving', + Date.civil(2008,11,28) => 'Day After Thanksgiving', + Date.civil(2008,12,25) => 'Christmas Day', + Date.civil(2008,12,31) => 'New Year\'s Eve',}.each do |date, name| + assert_equal name, Holidays.on(date, :ups)[0][:name] + end \ No newline at end of file diff --git a/lib/holidays/MANIFEST b/lib/holidays/MANIFEST index c0aece3..e4556bc 100644 --- a/lib/holidays/MANIFEST +++ b/lib/holidays/MANIFEST @@ -20,5 +20,6 @@ The following definition files are included in this installation: * holidays/scandinavia * holidays/se * holidays/united_nations +* holidays/ups * holidays/us * holidays/za diff --git a/lib/holidays/nyse.rb b/lib/holidays/nyse.rb new file mode 100644 index 0000000..9fb819a --- /dev/null +++ b/lib/holidays/nyse.rb @@ -0,0 +1,32 @@ +module Holidays + # This file is generated by the Ruby Holiday gem. + # + # Definitions loaded: data/nyse.yaml + # + # To use the definitions in this file, load them right after you load the + # Holiday gem: + # + # require 'holidays' + # require 'holidays/nyse' + # + # More definitions are available at http://code.dunae.ca/holidays. + module NYSE # :nodoc: + DEFINED_REGIONS = [:nyse] + + HOLIDAYS_BY_MONTH = { + 5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:nyse]}], + 0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Good Friday", :regions => [:nyse]}], + 11 => [{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:nyse]}], + 1 => [{:mday => 1, :name => "New Year's Day", :regions => [:nyse]}, + {:wday => 1, :week => 3, :name => "Martin Luther King, Jr. Day", :regions => [:nyse]}], + 12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:nyse]}], + 7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:nyse]}], + 2 => [{:wday => 1, :week => 3, :name => "Presidents' Day", :regions => [:nyse]}], + 9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:nyse]}] + } + end + + +end + +Holidays.merge_defs(Holidays::NYSE::DEFINED_REGIONS, Holidays::NYSE::HOLIDAYS_BY_MONTH) diff --git a/lib/holidays/ups.rb b/lib/holidays/ups.rb new file mode 100644 index 0000000..26af100 --- /dev/null +++ b/lib/holidays/ups.rb @@ -0,0 +1,31 @@ +module Holidays + # This file is generated by the Ruby Holiday gem. + # + # Definitions loaded: data/ups.yaml + # + # To use the definitions in this file, load them right after you load the + # Holiday gem: + # + # require 'holidays' + # require 'holidays/ups' + # + # More definitions are available at http://code.dunae.ca/holidays. + module UPS # :nodoc: + DEFINED_REGIONS = [:ups] + + HOLIDAYS_BY_MONTH = { + 5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:ups]}], + 11 => [{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:ups]}, + {:wday => 5, :week => 4, :name => "Day After Thanksgiving", :regions => [:ups]}], + 1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "New Year's Day", :regions => [:ups]}], + 12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:ups]}, + {:mday => 31, :name => "New Year's Eve", :regions => [:ups]}], + 7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:ups]}], + 9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:ups]}] + } + end + + +end + +Holidays.merge_defs(Holidays::UPS::DEFINED_REGIONS, Holidays::UPS::HOLIDAYS_BY_MONTH) diff --git a/rakefile.rb b/rakefile.rb index be141e5..db84d28 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -46,7 +46,7 @@ end spec = Gem::Specification.new do |s| s.name = 'holidays' - s.version = '0.9.2' + s.version = '0.9.3' s.author = 'Alex Dunae' s.homepage = 'http://code.dunae.ca/holidays' s.platform = Gem::Platform::RUBY diff --git a/test/defs/test_defs_nyse.rb b/test/defs/test_defs_nyse.rb new file mode 100644 index 0000000..f7c4157 --- /dev/null +++ b/test/defs/test_defs_nyse.rb @@ -0,0 +1,22 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'holidays/nyse' + +# This file is generated by the Ruby Holiday gem. +# +# Definitions loaded: data/nyse.yaml +class NyseDefinitionTests < Test::Unit::TestCase # :nodoc: + + def test_nyse +{Date.civil(2008,1,1) => 'New Year\'s Day', + Date.civil(2008,1,21) => 'Martin Luther King, Jr. Day', + Date.civil(2008,2,18) => 'Presidents\' Day', + Date.civil(2008,3,21) => 'Good Friday', + Date.civil(2008,5,26) => 'Memorial Day', + Date.civil(2008,7,4) => 'Independence Day', + Date.civil(2008,9,1) => 'Labor Day', + Date.civil(2008,11,27) => 'Thanksgiving', + Date.civil(2008,12,25) => 'Christmas Day'}.each do |date, name| + assert_equal name, Holidays.on(date, :nyse)[0][:name] +end + end +end diff --git a/test/defs/test_defs_ups.rb b/test/defs/test_defs_ups.rb new file mode 100644 index 0000000..0138ca1 --- /dev/null +++ b/test/defs/test_defs_ups.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'holidays/ups' + +# This file is generated by the Ruby Holiday gem. +# +# Definitions loaded: data/ups.yaml +class UpsDefinitionTests < Test::Unit::TestCase # :nodoc: + + def test_ups +{Date.civil(2008,1,1) => 'New Year\'s Day', + Date.civil(2008,5,26) => 'Memorial Day', + Date.civil(2008,7,4) => 'Independence Day', + Date.civil(2008,9,1) => 'Labor Day', + Date.civil(2008,11,27) => 'Thanksgiving', + Date.civil(2008,11,28) => 'Day After Thanksgiving', + Date.civil(2008,12,25) => 'Christmas Day', + Date.civil(2008,12,31) => 'New Year\'s Eve',}.each do |date, name| + assert_equal name, Holidays.on(date, :ups)[0][:name] +end + end +end