title: Groovy : Find the date of the previous Monday
body: <p>In the following code, i want to find the date of the last Monday.
  For that, i have two variable : </p>
  
  <ul>
  <li>startDay = today - 7 days</li>
  <li>stopDay = today - 1 day (yesterday)</li>
  </ul>
  
  <p>And i have a function that list all dates between "startDay" and "stopDay", and search in these dates, which one corresponds to Monday.</p>
  
  <p>It works well when i have two dates in the same ten :</p>
  
  <ul>
  <li>startDay = 2014-07-20</li>
  <li>stopDay = 2014-07-29</li>
  </ul>
  
  <p>But, when one of both change decade, the code end with an error:</p>
  
  <ul>
  <li>startDay = 2014-07-29</li>
  <li>stopDay = 2014-07-30</li>
  </ul>
  
  <p>ERROR:</p>
  
  <p><strong>java.lang.IllegalArgumentException: Incompatible Strings for Range: String#next() will not reach the expected value</strong></p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>def searchDay = { start, stop -&gt; (start..stop).findAll { Date.parse("yyyy-MM-dd", "${it}").format("u") == "1" } }
  def startDay = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date()-7)
  def stopDay = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date()-1)
  
  def dateOfTheDay = searchDay(startDay, stopDay);
  def dateOfTheDayWithoutSquare = dateOfTheDay.join(", ")
  
  
  return dateOfTheDayWithoutSquare 
  </code></pre>