require 'time'

pomo = ARGV[0].to_i # 1 pomodoro durations
interval = ARGV[1].to_i # rest durations
long_rest = ARGV[2].to_i # long rest durations

one_set = pomo*4 + interval*3 + long_rest # min
puts one_set # min

tempotime_0 = Time.new
tempotime = Time.new
mission_finish_time = tempotime_0 + one_set*60 # sec
#puts tempotime_0
#puts mission_finish_time
#minutes = (mission_finish_time - tempotime_0).to_i.div(60) 
#puts "#{minutes/60}:#{minutes%60}"
#exit
fh = mission_finish_time.hour.to_s

fm = mission_finish_time.min

if fm < 10
  fm = "0" + fm.to_s
end

fs = mission_finish_time.sec

if fs < 10
  fs = "0" + fs.to_s
end

count_i = 0
ii = 0
rest = false

pomodoro = 1
resttimes = interval

while count_i < one_set do
  now = Time.new
  if now > mission_finish_time
    now = nil
    break
  end
  now = nil
  seconds = 0

  if pomodoro < 4
    if ii == pomo && rest == false # 25min work , 5min rest
      rest = true
      ii = 0
    elsif rest == true && ii > interval - 1 # 5min rest
      pomodoro += 1
      ii = 0 # reset 
      rest = false
    end
  elsif pomodoro > 3
    if ii == pomo
      rest = true # 10min long rest
      resttimes = long_rest
    end
  end

  while seconds < 60 do
    t = Time.new

    if ((t - tempotime).to_i > 0)

      system("clear")
      puts t
      puts tempotime
      tempotime = t
      seconds += 1

      puts "end time #{fh}:#{fm}:#{fs}"

      puts

      puts "one_set:#{one_set}"
      puts "count_i:#{count_i}"

      puts "1 pomodoro = #{pomo} min, rest = #{interval} min"
      puts "long rest = #{long_rest} min"
      puts
      puts " 1 pomodoro #{pomo} min -> rest #{interval} min -> 1 pomodoro #{pomo} min -> rest #{interval} min"
      puts " 1 pomodoro #{pomo} min -> rest #{interval} min -> 1 pomodoro #{pomo} min -> long rest #{long_rest} min"
      puts
      puts "total #{one_set} min"
      puts

      if rest == true
        puts "rest: #{pomodoro}"
      else
        puts "pomodoro: #{pomodoro}"
      end

      puts "total time: " + count_i.to_s + " min"
      if rest == true
#        puts "remain: #{(resttimes - ii)} min"
        puts "remain: #{((tempotime_0 + pomo*60*pomodoro + resttimes*60*(pomodoro)) - t).to_i.div(60)} min #{(((tempotime_0 + pomo*60*pomodoro + resttimes*60*(pomodoro - 1)) - t).to_i).modulo(60)} sec"
      else
#        puts "remain: #{(pomo - ii)} min"
        puts "remain: #{((tempotime_0 + pomo*60*pomodoro + resttimes*60*(pomodoro - 1)) - t).to_i.div(60)} min #{(((tempotime_0 + pomo*60*pomodoro + resttimes*60*(pomodoro - 1)) - t).to_i).modulo(60)} sec"
      end

      h = t.hour
      m = t.min
      s = t.sec

      if m < 10
        m = "0" + m.to_s
      end
      if s < 10
        s = "0" + s.to_s
      end

      puts
      puts("#{h}:#{m}:#{s}")
    end
    t = nil
  end
  ii += 1
  count_i += 1
end

puts "4 pomodoro completed."
Edit Report
Pub: 28 Nov 2022 01:32 UTC
Views: 111