title: Using momentjs with recurring dates
body: <p>I have a date which flagged as recurring date (occurs every year), this date is 1st April, 2014, and starting form 2014 this event will occur yearly.</p>
  
  <p>I have a job which run weekly, in this job I insert in the DB events that will occur in the coming 180 days only starting from today, other events will be discarded.</p>
  
  <p>now when in my check, 1st April 2016 is past....so it's discarded (while 1st April 2015 should be added as it's in the range).</p>
  
  <p>I am using momentjs but am not able to find the correct logic for it.</p>
  
  <p>below is my code ....</p>
  
  <pre><code>//desiredDate = today + 180 days
  
  if (isYearlyRecur) {
      var year = eventeDate.getFullYear();
      if (year &lt; currentYear) {
          if (moment(eventeDate).unix() &lt; moment(todayDate).unix()) {
              eventeDate = moment(eventeDate).set('year', currentYear + 1);
          }
          else if (moment(eventeDate).unix() &gt; moment(desiredDate).unix()) {
              eventeDate = moment(eventeDate).set('year', currentYear);
          }
      }
  }
  </code></pre>
  
  <p>what is the correct way to do it and cover if the date comes in next year ...etc</p>