Permalink
Browse files

adding NERC holidays

  • Loading branch information...
adamstrickland committed Jan 4, 2013
1 parent 4221ba8 commit a2480fc4e63c749d73eeda170694f88b1a50eb9f
Showing with 127 additions and 24 deletions.
  1. +1 −0 data/index.yaml
  2. +47 −0 data/nerc.yaml
  3. +26 −24 lib/holidays/MANIFEST
  4. +34 −0 lib/holidays/nerc.rb
  5. +19 −0 test/defs/test_defs_nerc.rb
View
@@ -21,6 +21,7 @@ defs:
IT: ['it.yaml']
LI: ['li.yaml']
MX: ['mx.yaml', 'north_america_informal.yaml']
+ NERC: ['nerc.yaml']
NL: ['nl.yaml']
"NO": ['no.yaml']
NYSE: ['nyse.yaml']
View
@@ -0,0 +1,47 @@
+# NERC holiday definitions for the Ruby Holiday gem.
+#
+# By Adam Strickland
+# Source: www.nerc.com/docs/oc/rs/Additional_Off-peak_Days.doc
+#
+# Updated 2013-01-03.
+---
+months:
+ 1:
+ - name: New Year's Day
+ regions: [nerc]
+ mday: 1
+ 5:
+ - name: Memorial Day
+ week: -1
+ regions: [nerc]
+ wday: 1
+ 7:
+ - name: Independence Day
+ regions: [nerc]
+ mday: 4
+ observed: to_weekday_if_weekend
+ 9:
+ - name: Labor Day
+ week: 1
+ regions: [nerc]
+ wday: 1
+ 11:
+ - name: Thanksgiving
+ week: 4
+ regions: [nerc]
+ wday: 4
+ 12:
+ - name: Christmas Day
+ regions: [nerc]
+ mday: 25
+ observed: to_weekday_if_weekend
+methods:
+tests: |
+ {Date.civil(2013,1,1) => 'New Year\'s Day',
+ Date.civil(2013,5,27) => 'Memorial Day',
+ Date.civil(2013,7,4) => 'Independence Day',
+ Date.civil(2013,9,2) => 'Labor Day',
+ Date.civil(2013,11,28) => 'Thanksgiving',
+ Date.civil(2013,12,25) => 'Christmas Day'}.each do |date, name|
+ assert_equal name, (Holidays.on(date, :nyse)[0] || {})[:name]
+ end
View
@@ -1,37 +1,39 @@
==== Regional definitions
The following definition files are included in this installation:
-* holidays/is
-* holidays/nyse
-* holidays/us
-* holidays/nz
-* holidays/united_nations
-* holidays/pl
-* holidays/se
-* holidays/it
* holidays/at
-* holidays/no
-* holidays/fr
-* holidays/cz
-* holidays/el
-* holidays/north_america
-* holidays/europe
-* holidays/jp
* holidays/au
+* holidays/br
* holidays/ca
-* holidays/de
* holidays/ch
-* holidays/hu
-* holidays/ups
-* holidays/fi
+* holidays/cz
+* holidays/de
+* holidays/dk
+* holidays/el
* holidays/es
-* holidays/mx
-* holidays/li
+* holidays/europe
+* holidays/federal_reserve
+* holidays/fi
+* holidays/fr
* holidays/gb
+* holidays/hu
* holidays/ie
+* holidays/is
+* holidays/it
+* holidays/jp
+* holidays/li
+* holidays/mx
+* holidays/nerc
* holidays/nl
-* holidays/scandinavia
+* holidays/no
+* holidays/north_america
+* holidays/nyse
+* holidays/nz
+* holidays/pl
* holidays/pt
+* holidays/scandinavia
+* holidays/se
+* holidays/united_nations
+* holidays/ups
+* holidays/us
* holidays/za
-* holidays/br
-* holidays/dk
View
@@ -0,0 +1,34 @@
+# encoding: utf-8
+module Holidays
+ # This file is generated by the Ruby Holidays gem.
+ #
+ # Definitions loaded: data/nerc.yaml
+ #
+ # To use the definitions in this file, load it right after you load the
+ # Holiday gem:
+ #
+ # require 'holidays'
+ # require 'holidays/nerc'
+ #
+ # All the definitions are available at https://github.com/alexdunae/holidays
+ module NERC # :nodoc:
+ def self.defined_regions
+ [:nerc]
+ end
+
+ def self.holidays_by_month
+ {
+ 1 => [{:mday => 1, :name => "New Year's Day", :regions => [:nerc]}],
+ 5 => [{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:nerc]}],
+ 7 => [{:mday => 4, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Independence Day", :regions => [:nerc]}],
+ 9 => [{:wday => 1, :week => 1, :name => "Labor Day", :regions => [:nerc]}],
+ 11 => [{:wday => 4, :week => 4, :name => "Thanksgiving", :regions => [:nerc]}],
+ 12 => [{:mday => 25, :observed => lambda { |date| Holidays.to_weekday_if_weekend(date) }, :observed_id => "to_weekday_if_weekend", :name => "Christmas Day", :regions => [:nerc]}]
+ }
+ end
+ end
+
+
+end
+
+Holidays.merge_defs(Holidays::NERC.defined_regions, Holidays::NERC.holidays_by_month)
@@ -0,0 +1,19 @@
+# encoding: utf-8
+require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
+
+# This file is generated by the Ruby Holiday gem.
+#
+# Definitions loaded: data/nerc.yaml
+class NercDefinitionTests < Test::Unit::TestCase # :nodoc:
+
+ def test_nerc
+{Date.civil(2013,1,1) => 'New Year\'s Day',
+ Date.civil(2013,5,27) => 'Memorial Day',
+ Date.civil(2013,7,4) => 'Independence Day',
+ Date.civil(2013,9,2) => 'Labor Day',
+ Date.civil(2013,11,28) => 'Thanksgiving',
+ Date.civil(2013,12,25) => 'Christmas Day'}.each do |date, name|
+ assert_equal name, (Holidays.on(date, :nyse)[0] || {})[:name]
+end
+ end
+end

0 comments on commit a2480fc

Please sign in to comment.