title: Date at midnight going to previous day in 2015
body: <p>I'm setting a specific date by taking the month start date (ie, 2015-01-01 00:00:00 +0000) and then adding days to that 'base' date to get my required date. I'm repeating this process to build up a 'set' of months n years into the future. here's some code (btw, I'm making use of the super helpful NSDate+Escort category):</p>
  
  <pre><code>self.startDate = [[[self.startDate dateAtStartOfMonth] dateByAddingMonths:1 ] dateAtStartOfDay];
  </code></pre>
  
  <p>this gets my 'base' date ie - 2015-01-01 00:00:00 +0000</p>
  
  <pre><code>self.startDate = [self.startDate dateByAddingDays:20];
  </code></pre>
  
  <p>this add's 20 days (in this example), so my new date will be - 2015-01-21 00:00:00 +0000</p>
  
  <p>FULL CODE</p>
  
  <pre><code>// get to start of next month.
          self.startDate = [[[self.startDate dateAtStartOfMonth] dateByAddingMonths:1 ] dateAtStartOfDay];
  
          // check if month is shorter than start day index (ie february only has 28 days)
          // if it is, then set date to end of month, else set day as normal
          if ([self.startDateDayIndex integerValue] &gt; [self.startDate daysInMonth]) {
              self.startDate = [self.startDate dateAtEndOfMonth];
          }
          else{
              //self.startDate = [self.startDate dateByAddingDays:[self.startDateDayIndex integerValue] - 1];
              self.startDate = [self.startDate dateByAddingDays:5];
          }
  </code></pre>
  
  <p>Everything works fine until I hit February 2015, after which my new date is always 1 day behind, so 20th instead of 21st.</p>
  
  <p>Even stranger is once I get past February 2016, it all behaves normally again. I've been tearing my hair out for hours now trying to find out whats going on. It's not a leap year next year and I am now really struggling to fathom this one.</p>
  
  <p>Has anyone experienced this and can help me fix the problem?</p>
  
  <hr>
  
  <p>I've since done more testing in a fresh project, simply creating a date, storing it in CoreData and incrementally adding 1 month to it using NSCalendar and NSdateComponents. I still get the same problem of losing a day between March 2015 &amp; March 2016.</p>
  
  <p>I've started a new question which is more relavent and stripped of NSDate+Escort in hope that it will be more helpful to other readers. Cheers</p>