Created
November 12, 2012 04:18
-
-
Save ox/4057490 to your computer and use it in GitHub Desktop.
A calendar drawer for the current month in the terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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