Class: OpeningHoursConverter::PublicHoliday

Inherits:
Object
  • Object
show all
Defined in:
lib/opening_hours_converter/public_holiday.rb

Class Method Summary collapse

Class Method Details

.armistice(year = Time.now.year) ⇒ Object



62
63
64
# File 'lib/opening_hours_converter/public_holiday.rb', line 62

def self.armistice(year=Time.now.year)
  Time.new(year, 11, 11)
end

.assomption(year = Time.now.year) ⇒ Object



46
47
48
# File 'lib/opening_hours_converter/public_holiday.rb', line 46

def self.assomption(year=Time.now.year)
  Time.new(year, 8, 15)
end

.bastille_day(year = Time.now.year) ⇒ Object



66
67
68
# File 'lib/opening_hours_converter/public_holiday.rb', line 66

def self.bastille_day(year=Time.now.year)
  Time.new(year, 7, 14)
end

.christmas(year = Time.now.year) ⇒ Object



42
43
44
# File 'lib/opening_hours_converter/public_holiday.rb', line 42

def self.christmas(year=Time.now.year)
  Time.new(year, 12, 25)
end

.days(days = 0) ⇒ Object



109
110
111
# File 'lib/opening_hours_converter/public_holiday.rb', line 109

def self.days(days=0)
  days * 24 * 60 * 60
end

.easter(year = Time.now.year) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opening_hours_converter/public_holiday.rb', line 3

def self.easter(year=Time.now.year)
  # code from https://github.com/jrobertson/easter
  golden_number = (year % 19) + 1

  if year <= 1752 then
    # Julian calendar
    dominical_number = (year + (year / 4) + 5) % 7
    paschal_full_moon = (3 - (11 * golden_number) - 7) % 30
  else
    # Gregorian calendar
    dominical_number = (year + (year / 4) - (year / 100) + (year / 400)) % 7
    solar_correction = (year - 1600) / 100 - (year - 1600) / 400
    lunar_correction = (((year - 1400) / 100) * 8) / 25
    paschal_full_moon = (3 - 11 * golden_number + solar_correction - lunar_correction) % 30
  end

  dominical_number += 7 until dominical_number > 0

  paschal_full_moon += 30 until paschal_full_moon > 0
  paschal_full_moon -= 1 if paschal_full_moon == 29 or (paschal_full_moon == 28 and golden_number > 11)

  difference = (4 - paschal_full_moon - dominical_number) % 7
  difference += 7 if difference < 0

  day_easter = paschal_full_moon + difference + 1

  if day_easter < 11 then
    # Easter occurs in March.
    return Time.new(year, 3, day_easter + 21)
  else
    # Easter occurs in April.
    return Time.new(year, 4, day_easter - 10)
  end
end

.easter_monday(year = Time.now.year) ⇒ Object



70
71
72
# File 'lib/opening_hours_converter/public_holiday.rb', line 70

def self.easter_monday(year=Time.now.year)
  easter(year) + days(1)
end

.good_friday(year = Time.now.year) ⇒ Object



74
75
76
# File 'lib/opening_hours_converter/public_holiday.rb', line 74

def self.good_friday(year=Time.now.year)
  easter(year) - days(2)
end

.new_year(year = Time.now.year) ⇒ Object



38
39
40
# File 'lib/opening_hours_converter/public_holiday.rb', line 38

def self.new_year(year=Time.now.year)
  Time.new(year, 1, 1)
end

.pentecote(year = Time.now.year) ⇒ Object



82
83
84
# File 'lib/opening_hours_converter/public_holiday.rb', line 82

def self.pentecote(year=Time.now.year)
  easter(year) + days(49)
end

.pentecote_monday(year = Time.now.year) ⇒ Object



86
87
88
# File 'lib/opening_hours_converter/public_holiday.rb', line 86

def self.pentecote_monday(year=Time.now.year)
  easter(year) + days(50)
end

.ph_for_year(year = Time.now.year) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/opening_hours_converter/public_holiday.rb', line 90

def self.ph_for_year(year=Time.now.year)
  ph = []
  ph << new_year
  ph << good_friday
  ph << easter
  ph << easter_monday
  ph << work_day
  ph << victory
  ph << rise
  ph << pentecote
  ph << pentecote_monday
  ph << bastille_day
  ph << assomption
  ph << toussaint
  ph << armistice
  ph << christmas
  ph.sort
end

.rise(year = Time.now.year) ⇒ Object



78
79
80
# File 'lib/opening_hours_converter/public_holiday.rb', line 78

def self.rise(year=Time.now.year)
  easter(year) + days(39)
end

.toussaint(year = Time.now.year) ⇒ Object



54
55
56
# File 'lib/opening_hours_converter/public_holiday.rb', line 54

def self.toussaint(year=Time.now.year)
  Time.new(year, 11, 1)
end

.victory(year = Time.now.year) ⇒ Object



58
59
60
# File 'lib/opening_hours_converter/public_holiday.rb', line 58

def self.victory(year=Time.now.year)
  Time.new(year, 5, 8)
end

.work_day(year = Time.now.year) ⇒ Object



50
51
52
# File 'lib/opening_hours_converter/public_holiday.rb', line 50

def self.work_day(year=Time.now.year)
  Time.new(year, 5, 1)
end