mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add human-friendly formatting to runtime
This commit is contained in:
parent
d1527d8c0d
commit
196187a98a
1 changed files with 19 additions and 1 deletions
|
@ -64,7 +64,25 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
private def human_time(span : Time::Span)
|
private def human_time(span : Time::Span)
|
||||||
span.to_s
|
millis = span.total_milliseconds
|
||||||
|
return "#{(millis * 1000).round.to_i} microseconds" if millis < 1
|
||||||
|
|
||||||
|
seconds = span.total_seconds
|
||||||
|
return "#{millis.round(2)} milliseconds" if seconds < 1
|
||||||
|
return "#{seconds.round(2)} seconds" if seconds < 60
|
||||||
|
|
||||||
|
int_seconds = seconds.to_i
|
||||||
|
minutes = int_seconds / 60
|
||||||
|
int_seconds %= 60
|
||||||
|
return sprintf("%i:%02i", minutes, int_seconds) if minutes < 60
|
||||||
|
|
||||||
|
hours = minutes / 60
|
||||||
|
minutes %= 60
|
||||||
|
return sprintf("%i:%02i:%02i", hours, minutes, int_seconds) if hours < 24
|
||||||
|
|
||||||
|
days = hours / 24
|
||||||
|
hours %= 24
|
||||||
|
return sprintf("%i days %i:%02i:%02i", days, hours, minutes, int_seconds)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue