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).freeze
Class Method Summary collapse
- .ascension(year, sunday: false) ⇒ Object
- .ash_wednesday(year) ⇒ Object
- .baptism_of_lord(year, epiphany_on_sunday: false) ⇒ Object
- .christ_king(year) ⇒ Object
- .corpus_christi(year, sunday: false) ⇒ Object
- .easter_sunday(year) ⇒ Object
- .epiphany(year, sunday: false) ⇒ Object
- .first_advent_sunday(year) ⇒ Object
- .good_friday(year) ⇒ Object
- .holy_family(year) ⇒ Object
- .holy_saturday(year) ⇒ Object
- .holy_trinity(year) ⇒ Object
- .immaculate_heart(year) ⇒ Object
- .mother_of_church(year) ⇒ Object
- .mother_of_god(year) ⇒ Object
- .nativity(year) ⇒ Object
- .octave_of(date) ⇒ Object
- .palm_sunday(year) ⇒ Object
- .pentecost(year) ⇒ Object
- .sacred_heart(year) ⇒ Object
- .weekday_after(weekday, date) ⇒ Object
-
.weekday_before(weekday, date) ⇒ Object
utility methods.
Class Method Details
.ascension(year, sunday: false) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 86 def self.ascension(year, sunday: false) if sunday # GNLYC 7 b) return easter_sunday(year) + 6 * WEEK end pentecost(year) - 10 end |
.ash_wednesday(year) ⇒ Object
44 45 46 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 44 def self.ash_wednesday(year) easter_sunday(year) - (6 * WEEK + 4) end |
.baptism_of_lord(year, epiphany_on_sunday: false) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 35 def self.baptism_of_lord(year, epiphany_on_sunday: false) e = epiphany(year, sunday: epiphany_on_sunday) if epiphany_on_sunday e + 1 else sunday_after e end end |
.christ_king(year) ⇒ Object
124 125 126 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 124 def self.christ_king(year) first_advent_sunday(year + 1) - 7 end |
.corpus_christi(year, sunday: false) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 103 def self.corpus_christi(year, sunday: false) if sunday # GNLYC 7 c) return holy_trinity(year) + WEEK end holy_trinity(year) + 4 end |
.easter_sunday(year) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 48 def self.easter_sunday(year) year += 1 # algorithm below taken from the 'easter' gem: # https://github.com/jrobertson/easter golden_number = (year % 19) + 1 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 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) || ((paschal_full_moon == 28) && 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 # Easter occurs in March. return Date.new(year, 3, day_easter + 21) else # Easter occurs in April. return Date.new(year, 4, day_easter - 10) end end |
.epiphany(year, sunday: false) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 26 def self.epiphany(year, sunday: false) if sunday # GNLYC 7 a) return sunday_after(Date.new(year + 1, 1, 1)) end 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 * WEEK end |
.good_friday(year) ⇒ Object
78 79 80 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 78 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
82 83 84 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 82 def self.holy_saturday(year) easter_sunday(year) - 1 end |
.holy_trinity(year) ⇒ Object
99 100 101 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 99 def self.holy_trinity(year) octave_of(pentecost(year)) end |
.immaculate_heart(year) ⇒ Object
120 121 122 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 120 def self.immaculate_heart(year) pentecost(year) + 20 end |
.mother_of_church(year) ⇒ Object
116 117 118 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 116 def self.mother_of_church(year) pentecost(year) + 1 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
150 151 152 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 150 def self.octave_of(date) date + WEEK end |
.palm_sunday(year) ⇒ Object
74 75 76 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 74 def self.palm_sunday(year) easter_sunday(year) - 7 end |
.pentecost(year) ⇒ Object
95 96 97 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 95 def self.pentecost(year) easter_sunday(year) + 7 * WEEK end |
.sacred_heart(year) ⇒ Object
112 113 114 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 112 def self.sacred_heart(year) corpus_christi(year) + 8 end |
.weekday_after(weekday, date) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 140 def self.weekday_after(weekday, date) if date.wday == weekday date + WEEK elsif weekday > date.wday date + (weekday - date.wday) else date + (WEEK - date.wday + weekday) end end |
.weekday_before(weekday, date) ⇒ Object
utility methods
130 131 132 133 134 135 136 137 138 |
# File 'lib/calendarium-romanum/temporale/dates.rb', line 130 def self.weekday_before(weekday, date) if date.wday == weekday date - WEEK elsif weekday < date.wday date - (date.wday - weekday) else date - (date.wday + WEEK - weekday) end end |