title: Filter date with Java
body: <p>I am trying filters with Java, I can't use "Select ..." for find results.</p>
  
  <p>The problem is that my object always join in my array.</p>
  
  <p>My datas are -></p>
  
  <pre><code>Registro 1-&gt; Fecha Inicio "2018-09-01" , Fecha Fin -&gt; "2018-09-30"
  Registro 2-&gt; Fecha inicio "2018-10-01" , Fecha Fin -&gt; "2018-10-05"
  Registro 3-&gt; Fecha inicio "2017-12-31" , Fecha Fin -&gt; "2018-11-30"
  Registro 4-&gt; Fecha inicio "2018-12-01" , Fecha Fin -&gt; "2019-10-01"
  Registro 5-&gt; Fecha inicio "2018-12-30" , Fecha Fin -&gt; "2018-12-31"
  Registro 6-&gt; Fecha inicio "2018-11-30" , Fecha Fin -&gt; "2018-12-01"
  </code></pre>
  
  <p>The user insert -> <code>"2018-12-01" hasta el "9999-31-12"</code> for filter.</p>
  
  <p>Register 4 should be insert to array because my user insert "2018-12-01" and my register have the same Date Start.</p>
  
  <p>Register 5º should be insert to array because my user insert "<code>2018-12-01" and finish year-&gt;9999</code> THEN how my register is between, It should insert to array.</p>
  
  <p>Register 6º -> shold be insert to array because the date End because its end date corresponds to the period of time between the start date and the end date of the user, that is, the user wants between "2018-12-01" until "9999-31-12" and the date End of registration is "2018-12-01"</p>
  
  <pre><code>public List&lt;Article&gt; filterResult(String paramSelect, String dateStart, String dateEnd) {
      List&lt;Article&gt; list = Collections.emptyList();
  
      try {
          // Sino me ponen fecha de fin, la establezco al máximo.
          if(dateStart != null &amp;&amp; dateEnd == null) {
              dateEnd ="9999-31-12";
              list = (List&lt;Article&gt;) this.pgRepository.findAll();
              list =  this.getStart(list, dateStart, dateEnd);
          }
       } catch (Exception e) {
           LOGGER.error(e.getMessage());
       }
  
       return list;
  }
  
  private List&lt;Article&gt; getStart(List&lt;Article&gt; list, String dateStart, String dateEnd) throws ParseException {
      DateFomrat df = new SimpleDateFormat("yyyy-MM-dd"); 
      Date userDate = df.parse(dateStart);
      Date userEnd = df.parse(dateEnd);
  
      List&lt;Article&gt; filter = new ArrayList&lt;Article&gt;();
  
      for(Article param : list) {
          Date paramStart = df.parse(param.getStartdatevalidity());
          Date paramEnd = df.parse(param.getEnddatevalidity());
  
          if(paramStart.after(userDate) || paramEnd.before(userDate) &amp;&amp; paramStart.after(userEnd) ||  paramEnd.before(userEnd)) {
              filter.add(param);
          }
      }
  
      return filter;
  }
  </code></pre>
  
  <p>I have two problems ->
  1º My object always is guarded in my array. 2º I don't know if my logic is correct...</p>
  
  <p>Thanks and sorry for my English.</p>