Module: CalendariumRomanum::Temporale::Dates

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

Overview

Provides methods computing dates of movable feasts and utilities for common computations of relative dates

Constant Summary collapse

WEEKDAYS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w(sunday monday tuesday wednesday thursday friday saturday).freeze

Class Method Summary collapse

Class Method Details

.ascension(year, sunday: false) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

  • sunday (Boolean) (defaults to: false)

    transfer to Sunday?

Returns:

  • (Date)

104
105
106
107
108
109
110
111
# File 'lib/calendarium-romanum/temporale/dates.rb', line 104

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) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

57
58
59
# File 'lib/calendarium-romanum/temporale/dates.rb', line 57

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

.baptism_of_lord(year, epiphany_on_sunday: false) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

  • epiphany_on_sunday (Boolean) (defaults to: false)

    was Epiphany transferred to Sunday?

Returns:

  • (Date)

47
48
49
50
51
52
53
54
# File 'lib/calendarium-romanum/temporale/dates.rb', line 47

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) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

149
150
151
# File 'lib/calendarium-romanum/temporale/dates.rb', line 149

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

.corpus_christi(year, sunday: false) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

  • sunday (Boolean) (defaults to: false)

    transfer to Sunday?

Returns:

  • (Date)

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

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) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/calendarium-romanum/temporale/dates.rb', line 62

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) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

  • sunday (Boolean) (defaults to: false)

    transfer to Sunday?

Returns:

  • (Date)

35
36
37
38
39
40
41
42
# File 'lib/calendarium-romanum/temporale/dates.rb', line 35

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) ⇒ Date

Returns:

  • (Date)

7
8
9
# File 'lib/calendarium-romanum/temporale/dates.rb', line 7

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

.friday_after(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.friday_before(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.good_friday(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

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

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

.holy_family(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

18
19
20
21
22
23
24
25
# File 'lib/calendarium-romanum/temporale/dates.rb', line 18

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) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

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

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

.holy_trinity(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

119
120
121
# File 'lib/calendarium-romanum/temporale/dates.rb', line 119

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

.immaculate_heart(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

144
145
146
# File 'lib/calendarium-romanum/temporale/dates.rb', line 144

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

.monday_after(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.monday_before(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.mother_of_church(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

139
140
141
# File 'lib/calendarium-romanum/temporale/dates.rb', line 139

def self.mother_of_church(year)
  pentecost(year) + 1
end

.mother_of_god(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

28
29
30
# File 'lib/calendarium-romanum/temporale/dates.rb', line 28

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

.nativity(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

13
14
15
# File 'lib/calendarium-romanum/temporale/dates.rb', line 13

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

.octave_of(date) ⇒ Date

Parameters:

  • date (Date)

Returns:

  • (Date)

181
182
183
# File 'lib/calendarium-romanum/temporale/dates.rb', line 181

def self.octave_of(date)
  date + WEEK
end

.palm_sunday(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

89
90
91
# File 'lib/calendarium-romanum/temporale/dates.rb', line 89

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

.pentecost(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

114
115
116
# File 'lib/calendarium-romanum/temporale/dates.rb', line 114

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

.sacred_heart(year) ⇒ Date

Parameters:

  • year (Fixnum)

    liturgical year

Returns:

  • (Date)

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

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

.saturday_after(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.saturday_before(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.sunday_after(date) ⇒ Date

Parameters:

  • date (Date)

Returns:

  • (Date)

# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.sunday_before(date) ⇒ Date

Parameters:

  • date (Date)

Returns:

  • (Date)

# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.thursday_after(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.thursday_before(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.tuesday_after(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.tuesday_before(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.wednesday_after(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 202

.wednesday_before(date) ⇒ Object


# File 'lib/calendarium-romanum/temporale/dates.rb', line 186

.weekday_after(weekday, date) ⇒ Date

Parameters:

  • weekday (Fixnum)
  • date (Date)

Returns:

  • (Date)

169
170
171
172
173
174
175
176
177
# File 'lib/calendarium-romanum/temporale/dates.rb', line 169

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) ⇒ Date

Parameters:

  • weekday (Fixnum)
  • date (Date)

Returns:

  • (Date)

158
159
160
161
162
163
164
165
166
# File 'lib/calendarium-romanum/temporale/dates.rb', line 158

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