Module: CalendariumRomanum::Temporale::DateHelper

Extended by:
DateHelper
Included in:
DateHelper, Dates
Defined in:
lib/calendarium-romanum/temporale/date_helper.rb

Overview

Provides utility methods for date arithmetics, available both as mixin instance methods and module methods.

Since:

  • 0.9.0

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.

Since:

  • 0.9.0

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

Instance Method Summary collapse

Instance Method Details

#friday_after(date) ⇒ Object



# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#friday_before(date) ⇒ Object



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

#monday_after(date) ⇒ Object



# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#monday_before(date) ⇒ Object



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

#octave_of(date) ⇒ Date

Parameters:

  • date (Date)

Returns:

  • (Date)

Since:

  • 0.9.0



36
37
38
# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 36

def octave_of(date)
  date + WEEK
end

#saturday_after(date) ⇒ Object



# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#saturday_before(date) ⇒ Object



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

#sunday_after(date) ⇒ Date

Parameters:

  • date (Date)

Returns:

  • (Date)


# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#sunday_before(date) ⇒ Date

Parameters:

  • date (Date)

Returns:

  • (Date)


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

#thursday_after(date) ⇒ Object



# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#thursday_before(date) ⇒ Object



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

#tuesday_after(date) ⇒ Object



# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#tuesday_before(date) ⇒ Object



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

#wednesday_after(date) ⇒ Object



# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 56

#wednesday_before(date) ⇒ Object



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

#weekday_after(weekday, date) ⇒ Date

Parameters:

  • weekday (Integer)
  • date (Date)

Returns:

  • (Date)

Since:

  • 0.9.0



24
25
26
27
28
29
30
31
32
# File 'lib/calendarium-romanum/temporale/date_helper.rb', line 24

def 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 (Integer)
  • date (Date)

Returns:

  • (Date)

Since:

  • 0.9.0



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

def 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