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 ...@@ -115,10 +115,10 @@ module Gitlab
return periods if periods.empty? return periods if periods.empty?
periods.drop(1).inject([periods.first]) do |result, current| periods.drop(1).inject([periods.first]) do |result, current|
merged = try_merge_period(result.last, current) previous = result.last
if merged if overlap?(previous, current)
result[-1] = merged result[-1] = merge(previous, current)
result result
else else
result << current result << current
...@@ -126,10 +126,12 @@ module Gitlab ...@@ -126,10 +126,12 @@ module Gitlab
end end
end end
def try_merge_period(previous, current) def overlap?(previous, current)
if current.first <= previous.last current.first <= previous.last
Period.new(previous.first, [previous.last, current.last].max)
end end
def merge(previous, current)
Period.new(previous.first, [previous.last, current.last].max)
end end
def process_duration(periods) 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