Created
October 29, 2013 22:02
-
-
Save thomasklemm/7223441 to your computer and use it in GitHub Desktop.
Calendar week calculations
This file contains hidden or 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
require 'active_support/core_ext' | |
def calendar_week(week) | |
now = Date.current | |
year = now.cweek < week ? now.year : now.year + 1 | |
Date.commercial(year, week, 1) | |
end | |
p calendar_week(49) | |
# => Mon, 02 Dec 2013 | |
p calendar_week(1) | |
# => Mon, 30 Dec 2013 # don't know if that's the way calendar weeks are counted | |
p calendar_week(27) | |
# => Mon, 30 Jun 2014 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment