Module: Holidays::Definition::CustomMethods::JP

Defined in:
lib/holidays/definition/custom_methods/jp.rb

Overview

jp custom holiday calculations, ported verbatim from the methods: block in definitions/jp.yaml.

Class Method Summary collapse

Class Method Details

.jp_citizens_holiday(year) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/holidays/definition/custom_methods/jp.rb', line 66

def jp_citizens_holiday(year)
  ncd = Holidays::Factory::Definition.custom_methods_repository.find("jp_national_culture_day(year)").call(year)
  if ncd.wday == 3
    ncd - 1
  else
    nil
  end
end

.jp_health_sports_day_substitute(year) ⇒ Object



10
11
12
# File 'lib/holidays/definition/custom_methods/jp.rb', line 10

def jp_health_sports_day_substitute(year)
  Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 10, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 10, 2, 1))
end

.jp_marine_day_substitute(year) ⇒ Object



38
39
40
# File 'lib/holidays/definition/custom_methods/jp.rb', line 38

def jp_marine_day_substitute(year)
  Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 7, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 7, 3, 1))
end

.jp_mountain_holiday(year) ⇒ Object



75
76
77
# File 'lib/holidays/definition/custom_methods/jp.rb', line 75

def jp_mountain_holiday(year)
  Date.civil(year, 8, 11)
end

.jp_mountain_holiday_substitute(year) ⇒ Object



79
80
81
82
# File 'lib/holidays/definition/custom_methods/jp.rb', line 79

def jp_mountain_holiday_substitute(year)
  date = Holidays::Factory::Definition.custom_methods_repository.find("jp_mountain_holiday(year)").call(year)
  Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
end

.jp_national_culture_day(year) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/holidays/definition/custom_methods/jp.rb', line 42

def 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_national_culture_day_substitute(year) ⇒ Object



61
62
63
64
# File 'lib/holidays/definition/custom_methods/jp.rb', line 61

def jp_national_culture_day_substitute(year)
  date = Holidays::Factory::Definition.custom_methods_repository.find("jp_national_culture_day(year)").call(year)
  Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
end

.jp_next_weekday(date) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/holidays/definition/custom_methods/jp.rb', line 93

def jp_next_weekday(date)
  # This suuuucks. I have no idea how to make this not reach into our interal ruby API to do this.
  # I'm punting, I'll come back to this.
  is_holiday = Holidays::JP.holidays_by_month[date.month].any? do |holiday|
    next false unless holiday[:mday] == date.day
    next true unless holiday[:year_ranges]
    Holidays::Finder::Rules::YearRange.call(date.year, holiday[:year_ranges])
  end
  date.wday == 0 || is_holiday ? (Holidays::Factory::Definition.custom_methods_repository.find("jp_next_weekday(date)").call(date+1)) : date
end

.jp_respect_for_aged_holiday_substitute(year) ⇒ Object



84
85
86
# File 'lib/holidays/definition/custom_methods/jp.rb', line 84

def jp_respect_for_aged_holiday_substitute(year)
  Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, 9, Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 9, 3, 1))
end

.jp_substitute_holiday(year, month, day) ⇒ Object



88
89
90
91
# File 'lib/holidays/definition/custom_methods/jp.rb', line 88

def jp_substitute_holiday(year, month, day)
  date = Date.civil(year, month, day)
  date.wday == 0 ? (Holidays::Factory::Definition.custom_methods_repository.find("jp_next_weekday(date)").call(date+1)) : nil
end

.jp_vernal_equinox_day(year) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/holidays/definition/custom_methods/jp.rb', line 14

def 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_vernal_equinox_day_substitute(year) ⇒ Object



33
34
35
36
# File 'lib/holidays/definition/custom_methods/jp.rb', line 33

def jp_vernal_equinox_day_substitute(year)
  date = Holidays::Factory::Definition.custom_methods_repository.find("jp_vernal_equinox_day(year)").call(year)
  Holidays::Factory::Definition.custom_methods_repository.find("jp_substitute_holiday(year, month, day)").call(year, date.month, date.mday)
end