Skip to content

Instantly share code, notes, and snippets.

@thomasklemm
Created October 29, 2013 22:02
Show Gist options
  • Save thomasklemm/7223441 to your computer and use it in GitHub Desktop.
Save thomasklemm/7223441 to your computer and use it in GitHub Desktop.
Calendar week calculations
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