203 lines
5.5 KiB
YAML
203 lines
5.5 KiB
YAML
# Japanese holiday definitions for Ruby Holiday gem.
|
|
# Reference: http://www.h3.dion.ne.jp/~sakatsu/holiday_topic.htm
|
|
#
|
|
# This definition can calculate current Japanese holidays,
|
|
# don't compat with past changes of Japan Holiday Act.
|
|
#
|
|
# CHANGES:
|
|
# 2010-12-25: Initial version by Tatsuki Sugiura <sugi@nemui.org>
|
|
#
|
|
---
|
|
months:
|
|
1:
|
|
- name: 元日
|
|
regions: [jp]
|
|
mday: 1
|
|
- name: 成人の日
|
|
regions: [jp]
|
|
wday: 1
|
|
week: 2
|
|
2:
|
|
- name: 建国記念日
|
|
regions: [jp]
|
|
mday: 11
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 2, 11)
|
|
3:
|
|
- name: 春分の日
|
|
regions: [jp]
|
|
function: jp_vernal_equinox_day(year)
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(Holidays.jp_vernal_equinox_day(year))
|
|
4:
|
|
- name: 昭和の日
|
|
regions: [jp]
|
|
mday: 29
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 4, 29)
|
|
5:
|
|
- name: 憲法記念日
|
|
regions: [jp]
|
|
mday: 3
|
|
- name: みどりの日
|
|
regions: [jp]
|
|
mday: 4
|
|
- name: こどもの日
|
|
regions: [jp]
|
|
mday: 5
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 5, 3)
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 5, 5)
|
|
7:
|
|
- name: 海の日
|
|
regions: [jp]
|
|
wday: 1
|
|
week: 3
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 7, Date.calculate_mday(year, 7, 3, 1))
|
|
9:
|
|
- name: 敬老の日
|
|
regions: [jp]
|
|
wday: 1
|
|
week: 3
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 9, Date.calculate_mday(year, 9, 3, 1))
|
|
- name: 国民の休日
|
|
regions: [jp]
|
|
function: jp_citizons_holiday(year)
|
|
- name: 秋分の日
|
|
regions: [jp]
|
|
function: jp_national_culture_day(year)
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(Holidays.jp_national_culture_day(year))
|
|
10:
|
|
- name: 体育の日
|
|
regions: [jp]
|
|
wday: 1
|
|
week: 2
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 10, Date.calculate_mday(year, 10, 2, 1))
|
|
11:
|
|
- name: 文化の日
|
|
regions: [jp]
|
|
mday: 3
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 11, 3)
|
|
- name: 勤労感謝の日
|
|
regions: [jp]
|
|
mday: 23
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 11, 23)
|
|
12:
|
|
- name: 天皇誕生日
|
|
regions: [jp]
|
|
mday: 23
|
|
- name: 振替休日
|
|
regions: [jp]
|
|
function: jp_substitute_holiday(year, 12, 23)
|
|
methods:
|
|
jp_vernal_equinox_day: |
|
|
def self.jp_vernal_equinox_day(year)
|
|
day =
|
|
case year
|
|
when 1851..1899
|
|
19.8277
|
|
when 1900..1979
|
|
20.8357
|
|
when 1980..2099
|
|
20.8431
|
|
when 2100..2150
|
|
21.8510
|
|
else
|
|
raise IndexError.new("Out of range")
|
|
end
|
|
day += 0.242194 * (year - 1980) - ((year - 1980)/4).floor
|
|
day = day.floor
|
|
Date.civil(year, 3, day)
|
|
end
|
|
jp_national_culture_day: |
|
|
def self.jp_national_culture_day(year)
|
|
day =
|
|
case year
|
|
when 1851..1899
|
|
22.2588
|
|
when 1900..1979
|
|
23.2588
|
|
when 1980..2099
|
|
23.2488
|
|
when 2100..2150
|
|
24.2488
|
|
else
|
|
raise IndexError.new("Out of range")
|
|
end
|
|
day += 0.242194 * (year - 1980) - ((year - 1980)/4).floor
|
|
day = day.floor
|
|
Date.civil(year, 9, day)
|
|
end
|
|
jp_citizons_holiday: |
|
|
def self.jp_citizons_holiday(year)
|
|
year < 2003 and return nil
|
|
ncd = Holidays.jp_national_culture_day(year)
|
|
if ncd.wday == 3
|
|
ncd - 1
|
|
else
|
|
nil
|
|
end
|
|
end
|
|
jp_substitute_holiday: |
|
|
def self.jp_substitute_holiday(*date)
|
|
date = date[0].kind_of?(Date) ? date.first : Date.civil(*date)
|
|
date.wday == 0 ? date+1 : nil
|
|
end
|
|
tests: |
|
|
{Date.civil(2008,1,1) => '元日',
|
|
Date.civil(2010,1,11) => '成人の日',
|
|
Date.civil(2008,2,11) => '建国記念日',
|
|
Date.civil(2008,4,29) => '昭和の日',
|
|
Date.civil(2008,5,3) => '憲法記念日',
|
|
Date.civil(2008,5,5) => 'こどもの日',
|
|
Date.civil(2010,7,19) => '海の日',
|
|
Date.civil(2010,9,20) => '敬老の日',
|
|
Date.civil(2010,10,11) => '体育の日',
|
|
Date.civil(2008,11,3) => '文化の日',
|
|
Date.civil(2008,11,23) => '勤労感謝の日',
|
|
Date.civil(2008,12,23) => '天皇誕生日',
|
|
Date.civil(2010,3,22) => '振替休日',
|
|
Date.civil(2008,11,24) => '振替休日',
|
|
}.each do |date, name|
|
|
assert_equal name, (Holidays.on(date, :jp, :informal)[0] || {})[:name]
|
|
end
|
|
|
|
# vernal equinox day
|
|
[Date.civil(2004,3,20), Date.civil(2005,3,20), Date.civil(2006,3,21),
|
|
Date.civil(2007,3,21), Date.civil(2008,3,20), Date.civil(2009,3,20),
|
|
Date.civil(2010,3,21)].each do |date|
|
|
assert_equal '春分の日', Holidays.on(date, :jp)[0][:name]
|
|
end
|
|
|
|
# national culture day
|
|
[Date.civil(2004,9,23), Date.civil(2005,9,23), Date.civil(2006,9,23),
|
|
Date.civil(2007,9,23), Date.civil(2008,9,23), Date.civil(2009,9,23),
|
|
Date.civil(2010,9,23), Date.civil(2011,9,23), Date.civil(2012,9,22),
|
|
Date.civil(2013,9,23)].each do |date|
|
|
assert_equal '秋分の日', Holidays.on(date, :jp)[0][:name]
|
|
end
|
|
|
|
# citizens holiday
|
|
[Date.civil(2032,9,21), Date.civil(2049,9,21), Date.civil(2009,9,22),
|
|
Date.civil(2015,9,22), Date.civil(2026,9,22)].each do |date|
|
|
assert_equal '国民の休日', Holidays.on(date, :jp)[0][:name]
|
|
end
|