Commit e374783c authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '329179-fix-pipeline-elapsed-time-format' into 'master'

Include hours into elapsed time in jobs

See merge request gitlab-org/gitlab!64721
parents 1a71a1ee 280ab3a2
......@@ -76,8 +76,14 @@ module Gitlab
@section_header = true
end
def set_section_duration(duration)
@section_duration = Time.at(duration.to_i).utc.strftime('%M:%S')
def set_section_duration(duration_in_seconds)
duration = ActiveSupport::Duration.build(duration_in_seconds.to_i)
hours = duration.in_hours.floor
hours = hours > 0 ? "%02d" % hours : nil
minutes = "%02d" % duration.parts[:minutes].to_i
seconds = "%02d" % duration.parts[:seconds].to_i
@section_duration = [hours, minutes, seconds].compact.join(':')
end
def flush_current_segment!
......
......@@ -76,30 +76,25 @@ RSpec.describe Gitlab::Ci::Ansi2json::Line do
end
describe '#set_section_duration' do
shared_examples 'set_section_duration' do
it 'sets and formats the section_duration' do
subject.set_section_duration(75)
using RSpec::Parameterized::TableSyntax
expect(subject.section_duration).to eq('01:15')
end
where(:duration, :result) do
nil | '00:00'
'string' | '00:00'
0.seconds | '00:00'
7.seconds | '00:07'
75 | '01:15'
1.minute + 15.seconds | '01:15'
13.hours + 14.minutes + 15.seconds | '13:14:15'
1.day + 13.hours + 14.minutes + 15.seconds | '37:14:15'
end
context 'with default timezone' do
it_behaves_like 'set_section_duration'
end
with_them do
it do
subject.set_section_duration(duration)
context 'with a timezone carrying minutes offset' do
before do
# The actual call by does use Time.at(...).utc that the following
# rubocop rule (Rails/TimeZone) suggests, but for this specific
# test's purposes we needed to mock at the Time.at call point.
# rubocop:disable Rails/TimeZone
allow(Time).to receive(:at).with(75).and_return(Time.at(75, in: '+05:30'))
# rubocop:enable Rails/TimeZone
expect(subject.section_duration).to eq(result)
end
it_behaves_like 'set_section_duration'
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment