Commit 347ae925 authored by Harsh Chouraria's avatar Harsh Chouraria

Force use of UTC in formatting seconds into MM:SS

The job trace logs section parser computes section
durations for the UIs by computing differences in
epoch timestamps between the sections.

However, when building the string represntation of
the duration in MM:SS, its reliance on the Time
library and the epoch time
(0 seconds -> 00:00, extracted from 1970-01-01 00:00:00)
means that it can be influenced by the timezone of the
install host.

When timezone of the host uses non-UTC types and involves
an offset, such as +0530 (India Standard Time) then the
UI displayed section durations of 00:NN as 30:NN.

This change forces a UTC conversion of the computed
epoch time from the seconds, which should help with
showing the right duration values regardless of local
timezone.

Closes issue: https://gitlab.com/gitlab-org/gitlab/-/issues/332296

Changelog: fixed
parent 83ecd3c1
......@@ -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,25 @@ 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)
expect(subject.section_duration).to eq('01:15')
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')
end
end
context 'with default timezone' do
it_behaves_like 'set_section_duration'
end
context 'with a timezone carrying minutes offset' do
before do
allow(Time).to receive(:at).with(75).and_return(Time.at(75, in: '+05:30'))
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