Skip to content

Instantly share code, notes, and snippets.

@svoboda-jan
Created January 18, 2025 20:48
Show Gist options
  • Save svoboda-jan/6bf0f53289c107c5881210f5289aeaf2 to your computer and use it in GitHub Desktop.
Save svoboda-jan/6bf0f53289c107c5881210f5289aeaf2 to your computer and use it in GitHub Desktop.
Console calendar in Opal
# https://opalrb.com/try/
# Console Calendar
DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
CURRENT_DAY_HIGHLIGHTER = " ✅"
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|
if Time.now.day == day && HIGHLIGHT_CURRENT_DAY
print CURRENT_DAY_HIGHLIGHTER
else
print "#{day}".rjust 3, " "
end
space += 3
puts if [ 21, 42, 63, 84 ].include? space
end; puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment