add nz holidays
This commit is contained in:
parent
629240e340
commit
a8d5a60b0d
5 changed files with 234 additions and 0 deletions
|
@ -16,6 +16,7 @@ defs:
|
|||
NL: ['nl.yaml']
|
||||
"NO": ['no.yaml']
|
||||
NYSE: ['nyse.yaml']
|
||||
NZ: ['nz.yaml']
|
||||
PT: ['pt.yaml']
|
||||
US: ['us.yaml', 'north_america_informal.yaml']
|
||||
United_Nations: ['united_nations.yaml']
|
||||
|
|
141
data/nz.yaml
Normal file
141
data/nz.yaml
Normal file
|
@ -0,0 +1,141 @@
|
|||
# New Zealand holiday definitions for the Ruby Holiday gem.
|
||||
# Updated: 2010-03-28.
|
||||
# Sources:
|
||||
# - http://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand
|
||||
---
|
||||
months:
|
||||
0:
|
||||
- name: Good Friday
|
||||
regions: [nz]
|
||||
function: easter(year)-2
|
||||
- name: Easter Saturday
|
||||
regions: [nz]
|
||||
function: easter(year)-1
|
||||
- name: Easter Monday
|
||||
regions: [nz]
|
||||
function: easter(year)+1
|
||||
1:
|
||||
- name: New Year's Day
|
||||
regions: [nz]
|
||||
mday: 1
|
||||
observed: to_monday_if_weekend
|
||||
- name: Day after New Year's Day
|
||||
regions: [nz]
|
||||
mday: 2
|
||||
observed: to_weekday_if_boxing_weekend
|
||||
- name: Southland Anniversary Day
|
||||
regions: [nz_sl]
|
||||
mday: 17
|
||||
- name: Wellington Anniversary Day
|
||||
regions: [nz_we]
|
||||
mday: 22
|
||||
observed: closest_monday
|
||||
- name: Auckland Anniversary Day
|
||||
regions: [nz_ak]
|
||||
mday: 29
|
||||
observed: closest_monday
|
||||
- name: Northland Anniversary Day
|
||||
regions: [nz_nl]
|
||||
mday: 29
|
||||
observed: closest_monday
|
||||
2:
|
||||
- name: Nelson Anniversary Day
|
||||
regions: [nz_ak]
|
||||
mday: 1
|
||||
observed: closest_monday
|
||||
- name: Waitangi Day
|
||||
regions: [au]
|
||||
mday: 6
|
||||
3:
|
||||
- name: Otago Anniversary Day
|
||||
regions: [nz_ot]
|
||||
mday: 23
|
||||
observed: closest_monday
|
||||
- name: Taranaki Anniversary Day
|
||||
regions: [nz_ak]
|
||||
week: 2
|
||||
wday: 1
|
||||
4:
|
||||
- name: ANZAC Day
|
||||
regions: [au]
|
||||
mday: 25
|
||||
6:
|
||||
- name: Queen's Birthday
|
||||
regions: [nz]
|
||||
week: 1
|
||||
wday: 1
|
||||
9:
|
||||
- name: Dominion Day
|
||||
regions: [nz_sc]
|
||||
week: 4
|
||||
wday: 1
|
||||
10:
|
||||
- name: Hawke's bay Anniversary Day
|
||||
regions: [nz_hb]
|
||||
week: 1
|
||||
wday: 1
|
||||
observed: previous_friday
|
||||
- name: Labour Day
|
||||
regions: [nz]
|
||||
week: 4
|
||||
wday: 1
|
||||
- name: Marlborough Anniversary Day
|
||||
regions: [nz_mb]
|
||||
week: 4
|
||||
wday: 1
|
||||
observed: next_week
|
||||
11:
|
||||
- name: Canterbury Anniversary Day
|
||||
regions: [nz_ca]
|
||||
week: 2
|
||||
wday: 5
|
||||
- name: Chatham Island Anniversary Day
|
||||
regions: [nz_ch]
|
||||
mday: 30
|
||||
observed: closest_monday
|
||||
12:
|
||||
- name: Westland Anniversary Day
|
||||
regions: [nz_wl]
|
||||
mday: 1
|
||||
observed: closest_monday
|
||||
- name: Christmas Day
|
||||
regions: [nz]
|
||||
mday: 25
|
||||
observed: to_monday_if_weekend
|
||||
- name: Boxing Day
|
||||
regions: [nz]
|
||||
mday: 26
|
||||
observed: to_weekday_if_boxing_weekend
|
||||
tests: |
|
||||
{Date.civil(2007,1,1) => 'New Year\'s Day',
|
||||
Date.civil(2007,1,2) => 'Day after New Year\'s Day',
|
||||
Date.civil(2007,2,6) => 'Waitangi',
|
||||
Date.civil(2007,4,6) => 'Good Friday',
|
||||
Date.civil(2007,4,9) => 'Easter Monday',
|
||||
Date.civil(2007,4,25) => 'ANZAC Day',
|
||||
Date.civil(2007,12,25) => 'Christmas Day',
|
||||
Date.civil(2007,12,26) => 'Boxing Day'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :nz, :informal)[0][:name]
|
||||
end
|
||||
methods:
|
||||
closest_monday: |
|
||||
def self.closest_monday(date)
|
||||
if [1, 2, 3, 4].include?(date.wday)
|
||||
date -= (date.wday - 1)
|
||||
elsif 0 == date.wday
|
||||
date += 1
|
||||
else
|
||||
date += 8 - date.wday
|
||||
end
|
||||
date
|
||||
end
|
||||
|
||||
previous_friday: |
|
||||
def self.previous_friday(date)
|
||||
date - 3
|
||||
end
|
||||
|
||||
next_week: |
|
||||
def self.next_week(date)
|
||||
date + 7
|
||||
end
|
|
@ -17,6 +17,7 @@ The following definition files are included in this installation:
|
|||
* holidays/nl
|
||||
* holidays/north_america
|
||||
* holidays/nyse
|
||||
* holidays/nz
|
||||
* holidays/pt
|
||||
* holidays/scandinavia
|
||||
* holidays/se
|
||||
|
|
69
lib/holidays/nz.rb
Normal file
69
lib/holidays/nz.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
# coding: utf-8
|
||||
module Holidays
|
||||
# This file is generated by the Ruby Holiday gem.
|
||||
#
|
||||
# Definitions loaded: data/nz.yaml
|
||||
#
|
||||
# To use the definitions in this file, load them right after you load the
|
||||
# Holiday gem:
|
||||
#
|
||||
# require 'holidays'
|
||||
# require 'holidays/nz'
|
||||
#
|
||||
# More definitions are available at http://code.dunae.ca/holidays.
|
||||
module NZ # :nodoc:
|
||||
DEFINED_REGIONS = [:nz_ca, :nz_ch, :nz, :nz_wl, :nz_sl, :nz_we, :nz_ak, :nz_nl, :au, :nz_ot, :nz_sc, :nz_hb, :nz_mb]
|
||||
|
||||
HOLIDAYS_BY_MONTH = {
|
||||
0 => [{:function => lambda { |year| Holidays.easter(year)-2 }, :function_id => "easter(year)-2", :name => "Good Friday", :regions => [:nz]},
|
||||
{:function => lambda { |year| Holidays.easter(year)-1 }, :function_id => "easter(year)-1", :name => "Easter Saturday", :regions => [:nz]},
|
||||
{:function => lambda { |year| Holidays.easter(year)+1 }, :function_id => "easter(year)+1", :name => "Easter Monday", :regions => [:nz]}],
|
||||
11 => [{:wday => 5, :week => 2, :name => "Canterbury Anniversary Day", :regions => [:nz_ca]},
|
||||
{:mday => 30, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Chatham Island Anniversary Day", :regions => [:nz_ch]}],
|
||||
6 => [{:wday => 1, :week => 1, :name => "Queen's Birthday", :regions => [:nz]}],
|
||||
1 => [{:mday => 1, :observed => lambda { |date| Holidays.to_monday_if_weekend(date) }, :observed_id => "to_monday_if_weekend", :name => "New Year's Day", :regions => [:nz]},
|
||||
{:mday => 2, :observed => lambda { |date| Holidays.to_weekday_if_boxing_weekend(date) }, :observed_id => "to_weekday_if_boxing_weekend", :name => "Day after New Year's Day", :regions => [:nz]},
|
||||
{:mday => 17, :name => "Southland Anniversary Day", :regions => [:nz_sl]},
|
||||
{:mday => 22, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Wellington Anniversary Day", :regions => [:nz_we]},
|
||||
{:mday => 29, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Auckland Anniversary Day", :regions => [:nz_ak]},
|
||||
{:mday => 29, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Northland Anniversary Day", :regions => [:nz_nl]}],
|
||||
12 => [{:mday => 1, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Westland Anniversary Day", :regions => [:nz_wl]},
|
||||
{:mday => 25, :observed => lambda { |date| Holidays.to_monday_if_weekend(date) }, :observed_id => "to_monday_if_weekend", :name => "Christmas Day", :regions => [:nz]},
|
||||
{:mday => 26, :observed => lambda { |date| Holidays.to_weekday_if_boxing_weekend(date) }, :observed_id => "to_weekday_if_boxing_weekend", :name => "Boxing Day", :regions => [:nz]}],
|
||||
2 => [{:mday => 1, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Nelson Anniversary Day", :regions => [:nz_ak]},
|
||||
{:mday => 6, :name => "Waitangi Day", :regions => [:au]}],
|
||||
3 => [{:mday => 23, :observed => lambda { |date| Holidays.closest_monday(date) }, :observed_id => "closest_monday", :name => "Otago Anniversary Day", :regions => [:nz_ot]},
|
||||
{:wday => 1, :week => 2, :name => "Taranaki Anniversary Day", :regions => [:nz_ak]}],
|
||||
9 => [{:wday => 1, :week => 4, :name => "Dominion Day", :regions => [:nz_sc]}],
|
||||
4 => [{:mday => 25, :name => "ANZAC Day", :regions => [:au]}],
|
||||
10 => [{:wday => 1, :week => 1, :observed => lambda { |date| Holidays.previous_friday(date) }, :observed_id => "previous_friday", :name => "Hawke's bay Anniversary Day", :regions => [:nz_hb]},
|
||||
{:wday => 1, :week => 4, :name => "Labour Day", :regions => [:nz]},
|
||||
{:wday => 1, :week => 4, :observed => lambda { |date| Holidays.next_week(date) }, :observed_id => "next_week", :name => "Marlborough Anniversary Day", :regions => [:nz_mb]}]
|
||||
}
|
||||
end
|
||||
|
||||
def self.closest_monday(date)
|
||||
if [1, 2, 3, 4].include?(date.wday)
|
||||
date -= (date.wday - 1)
|
||||
elsif 0 == date.wday
|
||||
date += 1
|
||||
else
|
||||
date += 8 - date.wday
|
||||
end
|
||||
date
|
||||
end
|
||||
|
||||
|
||||
def self.next_week(date)
|
||||
date + 7
|
||||
end
|
||||
|
||||
def self.previous_friday(date)
|
||||
date - 3
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
Holidays.merge_defs(Holidays::NZ::DEFINED_REGIONS, Holidays::NZ::HOLIDAYS_BY_MONTH)
|
22
test/defs/test_defs_nz.rb
Normal file
22
test/defs/test_defs_nz.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
require 'holidays/nz'
|
||||
|
||||
# This file is generated by the Ruby Holiday gem.
|
||||
#
|
||||
# Definitions loaded: data/nz.yaml
|
||||
class NzDefinitionTests < Test::Unit::TestCase # :nodoc:
|
||||
|
||||
def test_nz
|
||||
{Date.civil(2007,1,1) => 'New Year\'s Day',
|
||||
Date.civil(2007,1,2) => 'Day after New Year\'s Day',
|
||||
Date.civil(2007,2,6) => 'Waitangi',
|
||||
Date.civil(2007,4,6) => 'Good Friday',
|
||||
Date.civil(2007,4,9) => 'Easter Monday',
|
||||
Date.civil(2007,4,25) => 'ANZAC Day',
|
||||
Date.civil(2007,12,25) => 'Christmas Day',
|
||||
Date.civil(2007,12,26) => 'Boxing Day'}.each do |date, name|
|
||||
assert_equal name, Holidays.on(date, :nz, :informal)[0][:name]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue