Last active
January 18, 2025 12:58
-
-
Save svoboda-jan/fe53b566cac7d252e4a27d1bb6ec445c to your computer and use it in GitHub Desktop.
Example code for a console calendar in Ruby
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
# Console Calendar | |
DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
IS_LEAP_YEAR = Time.now.year % 400 == 0 || ( | |
Time.now.year % 4 == 0 && Time.now.year % 100 != 0 | |
) | |
HIGHLIGHT_CURRENT_DAY = true | |
def days_in_month(month) | |
return 29 if Time.now.month == 2 | |
DAYS_IN_MONTH[month] | |
end | |
year = Time.now.year | |
month = Time.now.month | |
time = Time.new year, month | |
space = time.wday * 3 # pading for weekday start | |
days_in_month = days_in_month(month) | |
puts time.strftime("%B %Y").center 22 | |
puts " Su Mo Tu We Th Fr Sa" | |
print " " * space | |
1.upto(days_in_month) do |day| | |
#print "#{day}".rjust 3, " " | |
if Time.now.day == day && HIGHLIGHT_CURRENT_DAY | |
print " ✅️" | |
else | |
print "#{day}".rjust 3, " " | |
end | |
space += 3 | |
puts if [ 21, 42, 63, 84 ].include? space | |
end; puts |
HIGHLIGHT_CURRENNT_DAY
There's a typo, should be:
HIGHLIGHT_CURRENT_DAY
fixed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a typo, should be: