Skip to content

Instantly share code, notes, and snippets.

@ox
Created November 12, 2012 04:18
Show Gist options
  • Save ox/4057490 to your computer and use it in GitHub Desktop.
Save ox/4057490 to your computer and use it in GitHub Desktop.
A calendar drawer for the current month in the terminal
require 'date'
time = Date.today
# print month, year header
puts time.strftime("%B %Y").center(20)
# print th days of the week
puts "Su Mo Tu We Th Fr Sa"
sday = Date.new(time.year, time.month, 1)
days_in_month = (Date.new(time.year, 12, 31) << (12-time.month)).day
print " " * sday.wday
(1..days_in_month).each do |n|
print n.to_s.rjust(2)
sday = sday + 1
sday.wday == 0 ? print("\n") : print(" ")
end
puts "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment