module DateAndTime::Calculations

def prev_occurring(day_of_week)

today.prev_occurring(:thursday) # => Thu, 07 Dec 2017
today.prev_occurring(:monday) # => Mon, 11 Dec 2017
today = Date.today # => Thu, 14 Dec 2017

Returns a new date/time representing the previous occurrence of the specified day of week.
def prev_occurring(day_of_week)
  ago = wday - DAYS_INTO_WEEK.fetch(day_of_week)
  ago += 7 unless ago > 0
  advance(days: -ago)
end