Skip to content

Instantly share code, notes, and snippets.

@fredoliveira
Created December 18, 2011 16:03
Show Gist options
  • Save fredoliveira/1493778 to your computer and use it in GitHub Desktop.
Save fredoliveira/1493778 to your computer and use it in GitHub Desktop.
Script to calculate the current week for weekly notes
#!/usr/bin/ruby
require 'date'
registration_date = Date.civil(2006,1,13)
this_week = Date.today
# Get the start of the week for each of those dates
if registration_date.wday == 0
# wday of 0 is Sunday, and we want our weeks to start on Monday
registration_date = registration_date - 6
else
registration_date = registration_date - (registration_date.wday - 1)
end
if this_week.wday == 0
this_week = this_week - 6
else
this_week = this_week - (this_week.wday - 1)
end
puts "This is week "+(((this_week - registration_date)/7)+1).to_s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment