Permalink
Browse files

Add ECB TARGET definitions

  • Loading branch information...
1 parent 8e73931 commit 4d3a5ee0b9f47936c6540e02b32a3fb7fcbd096a @alexdunae alexdunae committed Jan 5, 2014
Showing with 104 additions and 0 deletions.
  1. +3 −0 CHANGELOG.rdoc
  2. +42 −0 data/ecb_target.yaml
  3. +1 −0 data/index.yaml
  4. +1 −0 lib/holidays/MANIFEST
  5. +34 −0 lib/holidays/ecb_target.rb
  6. +23 −0 test/defs/test_defs_ecb_target.rb
View
@@ -1,5 +1,8 @@
= Ruby Holidays Gem CHANGELOG
+== 1.0.7.pre
+* Added European Central Bank TARGET definitions (Toby Bryans, NLX)
+
== 1.0.6
* Added `Holidays.regions` method (@sonnym)
* Added Slovakian definitions (@mirelon)
View
@@ -0,0 +1,42 @@
+# ECB TARGET Closing Days
+#
+# Updated: 2014-01-04.
+# Sources:
+# - http://www.ecb.europa.eu/home/html/holidays.en.html
+# - http://www.ecb.europa.eu/press/pr/date/2000/html/pr001214_4.en.html
+---
+months:
+ 0:
+ - name: Good Friday
+ regions: [ecb_target]
+ function: easter(year)-2
+ - name: Easter Monday
+ regions: [ecb_target]
+ function: easter(year)+1
+ 1:
+ - name: New Year's Day
+ regions: [ecb_target]
+ mday: 1
+ 5:
+ - name: Labour Day
+ regions: [ecb_target]
+ mday: 1
+ 12:
+ - name: Christmas Day
+ regions: [ecb_target]
+ mday: 25
+ - name: Christmas Holiday
+ regions: [ecb_target]
+ mday: 26
+tests: |
+ {Date.civil(2013,1,1) => 'New Year\'s Day',
+ Date.civil(2013,5,1) => 'Labour Day',
+ Date.civil(2013,3,29) => 'Good Friday',
+ Date.civil(2013,4,1) => 'Easter Monday',
+ Date.civil(2013,12,25) => 'Christmas Day',
+ Date.civil(2013,12,26) => 'Christmas Holiday'}.each do |date, name|
+ assert_equal name, (Holidays.on(date, :ecb_target)[0] || {})[:name]
+ end
+
+ assert_equal 'Good Friday', Date.civil(2013,3,29).holidays(:ecb_target)[0][:name]
+ assert_equal 'Easter Monday', Date.civil(2013,4,1).holidays(:ecb_target)[0][:name]
View
@@ -11,6 +11,7 @@ defs:
CZ: ['cz.yaml']
DK: ['dk.yaml']
DE: ['de.yaml']
+ ECB_TARGET: ['ecb_target.yaml']
EL: ['el.yaml']
ES: ['es.yaml']
Federal_Reserve: ['federal_reserve.yaml']
View
@@ -11,6 +11,7 @@ The following definition files are included in this installation:
* holidays/cz
* holidays/de
* holidays/dk
+* holidays/ecb_target
* holidays/el
* holidays/es
* holidays/europe
View
@@ -0,0 +1,34 @@
+# encoding: utf-8
+module Holidays
+ # This file is generated by the Ruby Holidays gem.
+ #
+ # Definitions loaded: data/ecb_target.yaml
+ #
+ # To use the definitions in this file, load it right after you load the
+ # Holiday gem:
+ #
+ # require 'holidays'
+ # require 'holidays/ecb_target'
+ #
+ # All the definitions are available at https://github.com/alexdunae/holidays
+ module ECB_TARGET # :nodoc:
+ def self.defined_regions
+ [:ecb_target]
+ end
+
+ def self.holidays_by_month
+ {
+ 0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Good Friday", :regions => [:ecb_target]},
+ {:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :name => "Easter Monday", :regions => [:ecb_target]}],
+ 1 => [{:mday => 1, :name => "New Year's Day", :regions => [:ecb_target]}],
+ 5 => [{:mday => 1, :name => "Labour Day", :regions => [:ecb_target]}],
+ 12 => [{:mday => 25, :name => "Christmas Day", :regions => [:ecb_target]},
+ {:mday => 26, :name => "Christmas Holiday", :regions => [:ecb_target]}]
+ }
+ end
+ end
+
+
+end
+
+Holidays.merge_defs(Holidays::ECB_TARGET.defined_regions, Holidays::ECB_TARGET.holidays_by_month)
@@ -0,0 +1,23 @@
+# encoding: utf-8
+require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
+
+# This file is generated by the Ruby Holiday gem.
+#
+# Definitions loaded: data/ecb_target.yaml
+class Ecb_targetDefinitionTests < Test::Unit::TestCase # :nodoc:
+
+ def test_ecb_target
+{Date.civil(2013,1,1) => 'New Year\'s Day',
+ Date.civil(2013,5,1) => 'Labour Day',
+ Date.civil(2013,3,29) => 'Good Friday',
+ Date.civil(2013,4,1) => 'Easter Monday',
+ Date.civil(2013,12,25) => 'Christmas Day',
+ Date.civil(2013,12,26) => 'Christmas Holiday'}.each do |date, name|
+ assert_equal name, (Holidays.on(date, :ecb_target)[0] || {})[:name]
+end
+
+assert_equal 'Good Friday', Date.civil(2013,3,29).holidays(:ecb_target)[0][:name]
+assert_equal 'Easter Monday', Date.civil(2013,4,1).holidays(:ecb_target)[0][:name]
+
+ end
+end

0 comments on commit 4d3a5ee

Please sign in to comment.