Class: CalendariumRomanum::Temporale

Inherits:
Object
  • Object
show all
Defined in:
lib/calendarium-romanum/temporale.rb

Overview

determine seasons and dates of the Temporale feasts of the given year

Constant Summary collapse

WEEK =
7
SEASON_COLOUR =
{
 Seasons::ADVENT => Colours::VIOLET,
 Seasons::CHRISTMAS => Colours::WHITE,
 Seasons::ORDINARY => Colours::GREEN,
 Seasons::LENT => Colours::VIOLET,
 Seasons::EASTER => Colours::WHITE,
}
WEEKDAYS =
%w{sunday monday tuesday wednesday thursday friday saturday}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year = nil) ⇒ Temporale

year is Integer - the civil year when the liturgical year begins



19
20
21
22
# File 'lib/calendarium-romanum/temporale.rb', line 19

def initialize(year=nil)
  @year = year
  prepare_solemnities unless @year.nil?
end

Class Method Details

.for_day(date) ⇒ Object

creates a Calendar for the liturgical year including given date



39
40
41
# File 'lib/calendarium-romanum/temporale.rb', line 39

def for_day(date)
  return new(liturgical_year(date))
end

.liturgical_year(date) ⇒ Object

Determines liturgical year for the given date



26
27
28
29
30
31
32
33
34
35
# File 'lib/calendarium-romanum/temporale.rb', line 26

def liturgical_year(date)
  year = date.year
  temporale = Temporale.new year

  if date < temporale.first_advent_sunday
    return year - 1
  end

  return year
end

Instance Method Details

#advent_sunday(num, year = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/calendarium-romanum/temporale.rb', line 119

def advent_sunday(num, year=nil)
  advent_sundays_total = 4
  unless (1..advent_sundays_total).include? num
    raise ArgumentError.new "Invalid Advent Sunday #{num}"
  end

  year ||= @year
  return sunday_before(nativity(year)) - ((advent_sundays_total - num) * WEEK)
end

#ascension(year = nil) ⇒ Object



209
210
211
# File 'lib/calendarium-romanum/temporale.rb', line 209

def ascension(year=nil)
  return pentecost(year) - 10
end

#ash_wednesday(year = nil) ⇒ Object



158
159
160
161
# File 'lib/calendarium-romanum/temporale.rb', line 158

def ash_wednesday(year=nil)
  year ||= @year
  return easter_sunday(year) - (6 * WEEK + 4)
end

#baptism_of_lord(year = nil) ⇒ Object



153
154
155
156
# File 'lib/calendarium-romanum/temporale.rb', line 153

def baptism_of_lord(year=nil)
  year ||= @year
  return sunday_after epiphany(year)
end

#body_blood(year = nil) ⇒ Object



222
223
224
# File 'lib/calendarium-romanum/temporale.rb', line 222

def body_blood(year=nil)
  thursday_after(holy_trinity(year))
end

#christ_king(year = nil) ⇒ Object



230
231
232
233
# File 'lib/calendarium-romanum/temporale.rb', line 230

def christ_king(year=nil)
  year ||= @year
  sunday_before(first_advent_sunday(year + 1))
end

#concretize_abstract_date(abstract_date) ⇒ Object

converts an AbstractDate to a Date in the given liturgical year



68
69
70
71
72
73
74
75
# File 'lib/calendarium-romanum/temporale.rb', line 68

def concretize_abstract_date(abstract_date)
  d = abstract_date.concretize(@year + 1)
  if date_range.include? d
    d
  else
    abstract_date.concretize(@year)
  end
end

#date_range(year = nil) ⇒ Object



53
54
55
# File 'lib/calendarium-romanum/temporale.rb', line 53

def date_range(year=nil)
  start_date(year) .. end_date(year)
end

#easter_sunday(year = nil) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/calendarium-romanum/temporale.rb', line 163

def easter_sunday(year=nil)
  year ||= @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

#end_date(year = nil) ⇒ Object



48
49
50
51
# File 'lib/calendarium-romanum/temporale.rb', line 48

def end_date(year=nil)
  year ||= @year
  first_advent_sunday(year+1) - 1
end

#epiphany(year = nil) ⇒ Object



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

def epiphany(year=nil)
  year ||= @year
  return Date.new(year+1, 1, 6)
end

#get(*args) ⇒ Object

returns a Celebration scheduled for the given day

expected arguments: Date or two Integers (month, day)



302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/calendarium-romanum/temporale.rb', line 302

def get(*args)
  if args.size == 1 && args[0].is_a?(Date)
    date = args[0]
  else
    month, day = args
    date = Date.new @year, month, day
    unless date_range.include? date
      date = Date.new @year + 1, month, day
    end
  end

  return solemnity(date) || sunday(date) || ferial(date)
end

#good_friday(year = nil) ⇒ Object



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

def good_friday(year=nil)
  return easter_sunday(year) - 2
end

#holy_family(year = nil) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/calendarium-romanum/temporale.rb', line 134

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

#holy_saturday(year = nil) ⇒ Object



205
206
207
# File 'lib/calendarium-romanum/temporale.rb', line 205

def holy_saturday(year=nil)
  return easter_sunday(year) - 1
end

#holy_trinity(year = nil) ⇒ Object



218
219
220
# File 'lib/calendarium-romanum/temporale.rb', line 218

def holy_trinity(year=nil)
  sunday_after(pentecost(year))
end

#mother_of_god(year = nil) ⇒ Object



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

def mother_of_god(year=nil)
  octave_of(nativity(year))
end

#nativity(year = nil) ⇒ Object



129
130
131
132
# File 'lib/calendarium-romanum/temporale.rb', line 129

def nativity(year=nil)
  year ||= @year
  return Date.new(year, 12, 25)
end

#octave_of(date) ⇒ Object



97
98
99
# File 'lib/calendarium-romanum/temporale.rb', line 97

def octave_of(date)
  date + WEEK
end

#palm_sunday(year = nil) ⇒ Object



197
198
199
# File 'lib/calendarium-romanum/temporale.rb', line 197

def palm_sunday(year=nil)
  return easter_sunday(year) - 7
end

#pentecost(year = nil) ⇒ Object



213
214
215
216
# File 'lib/calendarium-romanum/temporale.rb', line 213

def pentecost(year=nil)
  year ||= @year
  return easter_sunday(year) + 7 * WEEK
end

#range_check(date) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/calendarium-romanum/temporale.rb', line 57

def range_check(date)
  # necessary in order to handle Date correctly
  date = date.to_date if date.class != Date

  unless date_range.include? date
    raise RangeError.new "Date out of range #{date}"
  end
end

#sacred_heart(year = nil) ⇒ Object



226
227
228
# File 'lib/calendarium-romanum/temporale.rb', line 226

def sacred_heart(year=nil)
  friday_after(sunday_after(body_blood(year)))
end

#season(date) ⇒ Object

which liturgical season is it?



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/calendarium-romanum/temporale.rb', line 236

def season(date)
  range_check date

  if first_advent_sunday <= date and
      nativity > date then
    Seasons::ADVENT

  elsif nativity <= date and
      baptism_of_lord >= date then
    Seasons::CHRISTMAS

  elsif ash_wednesday <= date and
      easter_sunday > date then
    Seasons::LENT

  elsif easter_sunday <= date and
      pentecost >= date then
    Seasons::EASTER

  else
    Seasons::ORDINARY
  end
end

#season_beginning(s) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/calendarium-romanum/temporale.rb', line 260

def season_beginning(s)
  case s
  when Seasons::ADVENT
    first_advent_sunday
  when Seasons::CHRISTMAS
    nativity
  when Seasons::LENT
    ash_wednesday
  when Seasons::EASTER
    easter_sunday
  else # ordinary time
    monday_after(baptism_of_lord)
  end
end

#season_week(seasonn, date) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/calendarium-romanum/temporale.rb', line 275

def season_week(seasonn, date)
  week1_beginning = season_beginning = season_beginning(seasonn)
  unless season_beginning.sunday?
    week1_beginning = sunday_after(season_beginning)
  end

  week = date_difference(date, week1_beginning) / Temporale::WEEK + 1

  if seasonn == Seasons::ORDINARY
    # ordinary time does not begin with Sunday, but the first week
    # is week 1, not 0
    week += 1

    if date > pentecost
      weeks_after_date = date_difference(first_advent_sunday(@year + 1), date) / 7
      week = 34 - weeks_after_date
      week += 1 if date.sunday?
    end
  end

  return week
end

#start_date(year = nil) ⇒ Object



44
45
46
# File 'lib/calendarium-romanum/temporale.rb', line 44

def start_date(year=nil)
  first_advent_sunday(year)
end

#weekday_after(weekday, date) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/calendarium-romanum/temporale.rb', line 87

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

#weekday_before(weekday, date) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/calendarium-romanum/temporale.rb', line 77

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