Skip to content

Instantly share code, notes, and snippets.

@iGEL
Created July 18, 2012 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iGEL/3137210 to your computer and use it in GitHub Desktop.
Save iGEL/3137210 to your computer and use it in GitHub Desktop.
Get a Date (the Monday) of a given ISO 8601 week by it's week number in Ruby
class Date
# Returns the monday of the given week number
def self.by_iso_weekno(year, weekno)
# January 4th is always in the first week according to ISO 8601
date = Date.civil(year, 1, 4) + (weekno - 1) * 7
date - (date.wday != 0 ? date.wday - 1 : 6) % 7
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment