diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-18 16:44:10 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-18 16:44:10 +0200 |
commit | dd4f50b1874ac066c7e47be223e98d8a9b317fc7 (patch) | |
tree | 268c37d3711d1eaa0a9eb78687b0f5f15b9d1230 /app/helpers/time_helper.rb | |
parent | 017ae313dc84682e260e960f93fb4a55af0df523 (diff) | |
download | gitlab-ce-dd4f50b1874ac066c7e47be223e98d8a9b317fc7.tar.gz |
Fix build duration when build is not finished yet19937-fix-wrong-build-elapsed-time
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'app/helpers/time_helper.rb')
-rw-r--r-- | app/helpers/time_helper.rb | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb index 8cb82c2d5cc..1926f03af07 100644 --- a/app/helpers/time_helper.rb +++ b/app/helpers/time_helper.rb @@ -1,14 +1,4 @@ module TimeHelper - def duration_in_words(finished_at, started_at) - if finished_at && started_at - interval_in_seconds = finished_at.to_i - started_at.to_i - elsif started_at - interval_in_seconds = Time.now.to_i - started_at.to_i - end - - time_interval_in_words(interval_in_seconds) - end - def time_interval_in_words(interval_in_seconds) minutes = interval_in_seconds / 60 seconds = interval_in_seconds - minutes * 60 @@ -25,9 +15,19 @@ module TimeHelper end def duration_in_numbers(finished_at, started_at) - diff_in_seconds = finished_at.to_i - started_at.to_i - time_format = diff_in_seconds < 1.hour ? "%M:%S" : "%H:%M:%S" + interval = interval_in_seconds(started_at, finished_at) + time_format = interval < 1.hour ? "%M:%S" : "%H:%M:%S" - Time.at(diff_in_seconds).utc.strftime(time_format) + Time.at(interval).utc.strftime(time_format) + end + + private + + def interval_in_seconds(started_at, finished_at = nil) + if started_at && finished_at + finished_at.to_i - started_at.to_i + elsif started_at + Time.now.to_i - started_at.to_i + end end end |