title: Cut the date if there is overlapping
body: <p>I have a <code>List&lt;Object[]&gt;</code> with two dates value and I have the 'filterFromDayStart' and <code>filterToDayEnd</code> which presente for example the following date  <code>20.06.17 00:00:00</code> and <code>20.06.17 23:59:59</code></p>
  
  <p>Now I want to cut <code>row[15]</code> or <code>row[16]</code> if there is overlapping with <code>filterFromDayStart</code> and <code>filterToDayEnd</code>; if there is no overlapping because the date/dates outside the area do not cut the dates.</p>
  
  <p>filterToDayEnd: <code>20.06.17 00:00:00</code>  filterToDayEnd: <code>20.06.17 23:59:59</code></p>
  
  <p>date_1_start  : <code>19.06.17 22:00:00</code>  date_1_end: <code>20.06.17 02:00:00</code> </p>
  
  <p>cut to --></p>
  
  <p>date_1_start  : <code>20.06.17 00:00:00</code>  date_1_end: <code>20.06.17 02:00:00</code></p>
  
  <hr>
  
  <p>date_2_start  : <code>19.06.17 22:00:00</code>  date_2_end: <code>19.06.17 22:00:00</code> </p>
  
  <p>do not cut to!</p>
  
  <hr>
  
  <p>date_3_start  : <code>20.06.17 22:00:00</code>  date_3_end: <code>21.06.17 02:00:00</code> </p>
  
  <p>cut to --></p>
  
  <p>date_1_start  : <code>20.06.17 22:00:00</code>  date_1_end: <code>20.06.17 23:59:59</code></p>
  
  <p>besides other cases...</p>
  
  <p>I have tired the code below but some times the date is being cut even if there is no overlapping. How can I manage that?</p>
  
  <pre><code>row[15] = row[15].before(filterFromDayStart) ? filterFromDayStart : row[15];
  row[16] = row[16].after(filterToDayEnd) ? filterToDayEnd : row[16];
  </code></pre>
  
  <p><strong>Edit</strong>
  Here is my example:</p>
  
  <pre><code>import java.text.DateFormat;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Date;
  
  
  public class DateBeforeAfter {
  
      public static void main(String[] args) {
          try {
              DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  
              Date filterFrom = dateFormat.parse("2017-02-20 00:00:00.0");
              Date filterTo = dateFormat.parse("2017-02-20 23:59:59.0");
  
              Date date1 = dateFormat.parse("2017-02-20 16:10:00.0");
              Date date2 = dateFormat.parse("2017-02-21 16:50:00.0");
  
              Date date3 = dateFormat.parse("2017-02-19 19:42:00.0");
              Date date4 = dateFormat.parse("2017-02-20 19:46:00.0");
  
              Date date5 = dateFormat.parse("2017-02-19 19:42:00.0");
              Date date6 = dateFormat.parse("2017-02-19 19:46:00.0");
  
              ArrayList&lt;Object[]&gt; list = new ArrayList&lt;Object[]&gt;();
              Object[] element1 = { date1, date2 };
              list.add(element1);
              Object[] element2 = { date3, date4 };
              list.add(element2);
              Object[] element3 = { date5, date6 };
              list.add(element3);
              for (Object[] row : list) {
                  row[0] = ((Date) row[0]).before(filterFrom) ? filterFrom : row[0];
                  row[1] = ((Date) row[1]).after(filterTo) ? filterTo : row[1];
  
              }
  
              for (Object[] row : list) {
                  System.out.println(Arrays.toString(row));
  
              }
  
          } catch (ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p><strong>result</strong></p>
  
  <pre><code>[Mon Feb 20 16:10:00 CET 2017, Mon Feb 20 23:59:59 CET 2017]
  [Mon Feb 20 00:00:00 CET 2017, Mon Feb 20 19:46:00 CET 2017]
  [Mon Feb 20 00:00:00 CET 2017, Sun Feb 19 19:46:00 CET 2017]
  </code></pre>
  
  <p>How can I make it in the right way so that the third one is not being cut?</p>
  
  <p>The right result would be:</p>
  
  <pre><code>[Mon Feb 20 16:10:00 CET 2017, Mon Feb 20 23:59:59 CET 2017]
  [Mon Feb 20 00:00:00 CET 2017, Mon Feb 20 19:46:00 CET 2017]
  [Sun Feb 19 19:42:00 CET 2017, Sun Feb 19 19:46:00 CET 2017]
  </code></pre>
  
  <p>This part of code works for me:</p>
  
  <pre><code>    for (Object[] row : list) {
          if ((((Date) row[0]).before(filterFrom) &amp;&amp; ((Date) row[1]).before(filterFrom))) {
              System.out.println("The record is before filterFrom: " + Arrays.toString(row));
  
          } else if ((((Date) row[0]).after(filterTo) &amp;&amp; ((Date) row[1]).after(filterTo))) {
              System.out.println("The record is after filterFrom: " + Arrays.toString(row));
  
          } else {
              row[0] = ((Date) row[0]).before(filterFrom) ? filterFrom : row[0];
              row[1] = ((Date) row[1]).after(filterTo) ? filterTo : row[1];
  
          }
  
      }
  </code></pre>