Commit 4c16fe34 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'hchouraria-ci-log-section-duration-format-tz' into 'master'

Force use of UTC in formatting seconds into MM:SS

See merge request gitlab-org/gitlab!62873
parents e94e3137 ac1cd2be
......@@ -77,7 +77,7 @@ module Gitlab
end
def set_section_duration(duration)
@section_duration = Time.at(duration.to_i).strftime('%M:%S')
@section_duration = Time.at(duration.to_i).utc.strftime('%M:%S')
end
def flush_current_segment!
......
......@@ -76,10 +76,30 @@ RSpec.describe Gitlab::Ci::Ansi2json::Line do
end
describe '#set_section_duration' do
it 'sets and formats the section_duration' do
subject.set_section_duration(75)
shared_examples 'set_section_duration' do
it 'sets and formats the section_duration' do
subject.set_section_duration(75)
expect(subject.section_duration).to eq('01:15')
expect(subject.section_duration).to eq('01:15')
end
end
context 'with default timezone' do
it_behaves_like 'set_section_duration'
end
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
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