Created
July 18, 2012 16:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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