# coding: utf-8
# -*- coding: utf-8 -*-

puts"★課題管理表★"
puts"只今の時刻は"
x = Time.now
printf("%s \n", x.strftime("%Y年%m月%d日 %H時%M分%S秒"))
hizuke = x.strftime("%Y年%%M月%d日 %H時%M分%S秒")
sleep(1)
puts""
puts"何をしますか?"
puts"1:提出日までは何日?"
puts"2:カレンダーの確認"
puts"3:プログラムの終了"

while true
  puts"答えを入力"
  sentaku = gets.to_i

  if sentaku == 1
    require"date"

    d1 = Date.today
    tosi = Date.today.year
    puts"〰日数計算プログラム〰"
    puts"課題提出日は?"
    puts"何月ですか?\n数字を入力してください"
    tuki = gets.to_i
    puts"何日ですか?\n数字を入力してください"
    niti = gets.to_i
    d2 = Date.new(tosi,tuki,niti)

    puts("課題提出日までの残りの日数は"+(d2-d1).to_s + "日")
    #引用 https://www.javadrive.jp/ruby/date_class/index4.html
elsif sentaku == 2
  require'date'

  require'date'
  head = Date.today.strftime("%B, %Y")
  year = Date.today.year
  mon = Date.today.mon

  firstday_wday = Date.new(year,mon,1).wday
  lastday_date = Date.new(year,mon,-1).day
  week = %w(Su Mo Tu We Th Fr Sa)

  puts head.center(20)
  puts week.join(" ")
  print "   " * firstday_wday
  wday = firstday_wday
  (1..lastday_date).each do |date|
    print date.to_s.rjust(2) + " "
    wday = wday+1
    if wday%7==0
      print "\n"
    end
  end

  #引用 https://qiita.com/sacckey/items/8fc236bb054aff6b74cs
if wday%7!=0
  print "\n"
end
  
elsif sentaku == 3
  puts"プログラムを終了します"
  sleep(2)
  break
  
elsif
  puts"その選択肢は無いよ!"
  redo
end
end
