module BBC::Week::ClassMethods

Public Instance Methods

bbc_week(year, week, day) click to toggle source

Create a date object from a BBC week date

# File lib/bbc/week.rb, line 12
def bbc_week(year, week, day)
  # The week that contains Jan 4 is the first week with the majority
  # of days in that year (regardless of what day of week is start of week)
  jan4 = Date.new(year, 1, 4)

  # Next calculate the first day of the first week of that year
  first = jan4 - ((jan4.wday + 1) % 7)

  # Then add on the days and weeks
  first + ((week - 1) * 7) + day - 1
end