Commit 1eac4bbb authored by Hariom Verma's avatar Hariom Verma

TimeTrackingFormatter supports negative time

parent a237a266
...@@ -24,6 +24,12 @@ module Gitlab ...@@ -24,6 +24,12 @@ module Gitlab
end end
def output(seconds) def output(seconds)
seconds.to_i < 0 ? negative_output(seconds) : positive_output(seconds)
end
private
def positive_output(seconds)
ChronicDuration.output( ChronicDuration.output(
seconds, seconds,
CUSTOM_DAY_AND_MONTH_LENGTH.merge( CUSTOM_DAY_AND_MONTH_LENGTH.merge(
...@@ -34,7 +40,9 @@ module Gitlab ...@@ -34,7 +40,9 @@ module Gitlab
nil nil
end end
private def negative_output(seconds)
"-" + positive_output(seconds.abs)
end
def limit_to_hours_setting def limit_to_hours_setting
Gitlab::CurrentSettings.time_tracking_limit_to_hours Gitlab::CurrentSettings.time_tracking_limit_to_hours
......
...@@ -47,5 +47,11 @@ RSpec.describe Gitlab::TimeTrackingFormatter do ...@@ -47,5 +47,11 @@ RSpec.describe Gitlab::TimeTrackingFormatter do
it { expect(subject).to eq('1w 1d 1h 40m') } it { expect(subject).to eq('1w 1d 1h 40m') }
end end
context 'handles negative time input' do
let(:num_seconds) { -178_800 }
it { expect(subject).to eq('-1w 1d 1h 40m') }
end
end end
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