Commit 27a3f118 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Split try_merge_period into overlap? and merge:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6084#note_15083507
parent 7b754766
......@@ -115,10 +115,10 @@ module Gitlab
return periods if periods.empty?
periods.drop(1).inject([periods.first]) do |result, current|
merged = try_merge_period(result.last, current)
previous = result.last
if merged
result[-1] = merged
if overlap?(previous, current)
result[-1] = merge(previous, current)
result
else
result << current
......@@ -126,10 +126,12 @@ module Gitlab
end
end
def try_merge_period(previous, current)
if current.first <= previous.last
Period.new(previous.first, [previous.last, current.last].max)
end
def overlap?(previous, current)
current.first <= previous.last
end
def merge(previous, current)
Period.new(previous.first, [previous.last, current.last].max)
end
def process_duration(periods)
......
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