Skip to content

Instantly share code, notes, and snippets.

View nhance's full-sized avatar
💭
⛑ Software Rescueman

Nick Hance nhance

💭
⛑ Software Rescueman
View GitHub Profile
@codenamev
codenamev / nearest_date.rb
Created December 3, 2013 21:20
Find the nearest Monday
# credit: http://stackoverflow.com/questions/4514988/rails-is-there-away-to-get-the-date-object-that-is-the-closest-monday-to-today
# docs: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-commercial
# Find the next Monday
Date.commercial(Date.today.year, 1+Date.today.cweek, 1)
# Find the nearest Monday
Date.commercial(Date.today.year, Date.today.cwday.modulo(4)+Date.today.cweek, 1)
# Date of writing was: 2013-12-03