puzzle-scoreboard/app/controllers/concerns/completions_concern.rb
sto 2969a24cb0
All checks were successful
CI / scan_ruby (push) Successful in 15s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 11s
CI / test (push) Successful in 26s
Fix display_time
2025-06-21 10:54:20 +02:00

33 lines
903 B
Ruby

module CompletionsConcern
extend ActiveSupport::Concern
def pad(n)
if n > 9
return n.to_s
end
"0" + n.to_s
end
def display_time(time)
h = time / 3600
m = (time % 3600) / 60
s = (time % 3600) % 60
if h > 0
return h.to_s + ":" + pad(m) + ":" + pad(s)
elsif m > 0
return m.to_s + ":" + pad(s)
end
s.to_s
end
def extend_completions!(contestant)
current_time_from_start = 0
contestant.completions.order(:time_seconds).each do |completion|
completion.update(display_time_from_start: display_time(completion.time_seconds),
display_relative_time: display_time(completion.time_seconds - current_time_from_start))
current_time_from_start = completion.time_seconds
end
contestant.update(display_time: display_time(current_time_from_start), time_seconds: current_time_from_start)
end
end