Skip to content

Instantly share code, notes, and snippets.

@basti
Created August 30, 2011 07:29
Show Gist options
  • Save basti/1180385 to your computer and use it in GitHub Desktop.
Save basti/1180385 to your computer and use it in GitHub Desktop.
Calculate start/end dates and next week number for given week number
def week_dates( year, week_no )
week_start = Date.commercial( year, week_no, 1 )
week_end = Date.commercial( year, week_no, 7 )
week_start.strftime( "%d/%m/%y" ) + ' - ' + week_end.strftime( "%d/%m/%y" )
end
def next_week_no(year, week_no)
week_start = Date.commercial( year, week_no, 1 )
week_start.advance(:weeks => 1).cweek
end
# example
next_week_no(2008, 52)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment