title: Merging the datetime ranges at the end of the day and start of the next day
body: <p>Here is my input data</p>
  
  <pre><code>case class DateRange(sd:DateTime,ed:DateTime)
  
  val sd1 = DateTime.parse("2016-04-04T20:00:00.000Z")
  val ed1 = DateTime.parse("2016-04-04T23:59:59.999Z")
  
  val sd2 = DateTime.parse("2016-04-05T00:00:00.000Z")
  val ed2 = DateTime.parse("2016-04-05T05:00:00.000Z")
  
  val sd3 = DateTime.parse("2016-04-05T20:00:00.000Z")
  val ed3 = DateTime.parse("2016-04-05T23:59:59.999Z")
  
  val sd4 = DateTime.parse("2016-04-06T00:00:00.000Z")
  val ed4 = DateTime.parse("2016-04-06T05:00:00.000Z")
  
  val sd5 = DateTime.parse("2016-04-07T10:00:00.000Z")
  val ed5 = DateTime.parse("2016-04-07T15:00:00.000Z")
  
  val drList = List(DateRange(sd1,ed1),DateRange(sd2,ed2),DateRange(sd3,ed3),DateRange(sd4,ed4),DateRange(sd5,ed5))
  </code></pre>
  
  <p>The desired output I am looking for is </p>
  
  <pre><code>val res = List(DateRange(sd1,ed2),DateRange(sd3,ed4),DateRange(sd5,ed5))
  </code></pre>
  
  <p>Here the <code>ed1, ed3</code> is the end of the day and <code>sd1, sd3</code> are start of the day for the respective dates. I want to merge that kind of ranges as we can see in the desired output above.</p>
  
  <p>I tried partitioning like this</p>
  
  <pre><code>   val result = drList.partition(x =&gt; x.sd.isEqual(x.sd.withTimeAtStartOfDay()) || x.ed.isEqual(x.ed.withTime(LocalTime.parse("23:59:59")))))
  </code></pre>
  
  <p>But not getting how to merge the result. Thanks in advance.</p>