Skip to content

Instantly share code, notes, and snippets.

@spleenteo
Last active January 20, 2017 15:07
Show Gist options
  • Save spleenteo/2f4fb8c5ca1caf53bb92 to your computer and use it in GitHub Desktop.
Save spleenteo/2f4fb8c5ca1caf53bb92 to your computer and use it in GitHub Desktop.
weekly calendar for a specific year
#!/usr/bin/ruby
require 'date'
year = if ARGV.length > 0
ARGV.first.to_i
else
Time.now.year
end
first_iteration = true
Date.new(year, 01, 01).upto(Date.new(year, 12, 31)) do |day|
if day.cwday == 1
end_day = day + 6
if day.month != end_day.month || day.month != (day - 1).month || first_iteration
puts "W#{day.strftime('%V, %d')} - #{(end_day).strftime('%d %b')}"
else
puts "W#{day.strftime('%V, %d')} - #{end_day.strftime('%d')}"
end
first_iteration = false
end
end
puts "calendar for the year #{year}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment