Module: CalendariumRomanum::Temporale::Dates

Defined in:
lib/calendarium-romanum/temporale/dates.rb

Overview

dates of movable feasts

Constant Summary collapse

WEEKDAYS =
%w{sunday monday tuesday wednesday thursday friday saturday}

Class Method Summary collapse

Class Method Details

.ascension(year) ⇒ Object



83
84
85
# File 'lib/calendarium-romanum/temporale/dates.rb', line 83

def self.ascension(year)
  pentecost(year) - 10
end

.ash_wednesday(year) ⇒ Object



34
35
36
# File 'lib/calendarium-romanum/temporale/dates.rb', line 34

def self.ash_wednesday(year)
  easter_sunday(year) - (6 * Temporale::WEEK + 4)
end

.baptism_of_lord(year) ⇒ Object



30
31
32
# File 'lib/calendarium-romanum/temporale/dates.rb', line 30

def self.baptism_of_lord(year)
  sunday_after epiphany(year)
end

.body_blood(year) ⇒ Object



95
96
97
# File 'lib/calendarium-romanum/temporale/dates.rb', line 95

def self.body_blood(year)
  holy_trinity(year) + 4
end

.christ_king(year) ⇒ Object



107
108
109
# File 'lib/calendarium-romanum/temporale/dates.rb', line 107

def self.christ_king(year)
  first_advent_sunday(year + 1) - 7
end

.easter_sunday(year) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/calendarium-romanum/temporale/dates.rb', line 38

def self.easter_sunday(year)
  year += 1

  # algorithm below taken from the 'easter' gem:
  # 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 Date.new(y=year, m=3, d=day_easter + 21)
  else
    # Easter occurs in April.
    return Date.new(y=year, m=4, d=day_easter - 10)
  end
end

.epiphany(year) ⇒ Object



26
27
28
# File 'lib/calendarium-romanum/temporale/dates.rb', line 26

def self.epiphany(year)
  Date.new(year+1, 1, 6)
end

.first_advent_sunday(year) ⇒ Object



5
6
7
# File 'lib/calendarium-romanum/temporale/dates.rb', line 5

def self.first_advent_sunday(year)
  sunday_before(nativity(year)) - 3 * Temporale::WEEK
end

.good_friday(year) ⇒ Object



75
76
77
# File 'lib/calendarium-romanum/temporale/dates.rb', line 75

def self.good_friday(year)
  easter_sunday(year) - 2
end

.holy_family(year) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/calendarium-romanum/temporale/dates.rb', line 13

def self.holy_family(year)
  xmas = nativity(year)
  if xmas.sunday?
    return Date.new(year, 12, 30)
  else
    sunday_after(xmas)
  end
end

.holy_saturday(year) ⇒ Object



79
80
81
# File 'lib/calendarium-romanum/temporale/dates.rb', line 79

def self.holy_saturday(year)
  easter_sunday(year) - 1
end

.holy_trinity(year) ⇒ Object



91
92
93
# File 'lib/calendarium-romanum/temporale/dates.rb', line 91

def self.holy_trinity(year)
  octave_of(pentecost(year))
end

.immaculate_heart(year) ⇒ Object



103
104
105
# File 'lib/calendarium-romanum/temporale/dates.rb', line 103

def self.immaculate_heart(year)
  pentecost(year) + 20
end

.mother_of_god(year) ⇒ Object



22
23
24
# File 'lib/calendarium-romanum/temporale/dates.rb', line 22

def self.mother_of_god(year)
  octave_of(nativity(year))
end

.nativity(year) ⇒ Object



9
10
11
# File 'lib/calendarium-romanum/temporale/dates.rb', line 9

def self.nativity(year)
  Date.new(year, 12, 25)
end

.octave_of(date) ⇒ Object



133
134
135
# File 'lib/calendarium-romanum/temporale/dates.rb', line 133

def self.octave_of(date)
  date + Temporale::WEEK
end

.palm_sunday(year) ⇒ Object



71
72
73
# File 'lib/calendarium-romanum/temporale/dates.rb', line 71

def self.palm_sunday(year)
  easter_sunday(year) - 7
end

.pentecost(year) ⇒ Object



87
88
89
# File 'lib/calendarium-romanum/temporale/dates.rb', line 87

def self.pentecost(year)
  easter_sunday(year) + 7 * Temporale::WEEK
end

.sacred_heart(year) ⇒ Object



99
100
101
# File 'lib/calendarium-romanum/temporale/dates.rb', line 99

def self.sacred_heart(year)
  body_blood(year) + 8
end

.weekday_after(weekday, date) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/calendarium-romanum/temporale/dates.rb', line 123

def self.weekday_after(weekday, date)
  if date.wday == weekday then
    return date + Temporale::WEEK
  elsif weekday > date.wday
    return date + (weekday - date.wday)
  else
    return date + (Temporale::WEEK - date.wday + weekday)
  end
end

.weekday_before(weekday, date) ⇒ Object

utility methods



113
114
115
116
117
118
119
120
121
# File 'lib/calendarium-romanum/temporale/dates.rb', line 113

def self.weekday_before(weekday, date)
  if date.wday == weekday then
    return date - Temporale::WEEK
  elsif weekday < date.wday
    return date - (date.wday - weekday)
  else
    return date - (date.wday + Temporale::WEEK - weekday)
  end
end