title: Ruby(/Rails) dates - bi-weekly and quarterly DateTime ranges
body: <p>I am trying to do reporting for a specific period, those periods supported being:</p>
  
  <ul>
  <li>"today": <code>start = DateTime.now.beginning_of_day; end = start.end_of_day</code></li>
  <li>"this week": <code>start = DateTime.now.beginning_of_week; end = start.end_of_week</code></li>
  <li>"<strong>this bi-week</strong>" (first half or second half of the month, relative to the current date of <code>DateTime.now</code>)
  
  <ul>
  <li>it is <em>very</em> important to be sure that the month is evenly divided, and <code>cweek</code> is not used; the start of the first bi-week should be the first of the month, and the end of the second bi-week should be the last of the month. The dividing date between the two should be the total number of days in the month divided by 2, rounded up (i.e. if there are 31 days, the second bi-week would start on the 15th, and not the 14th of the month).</li>
  </ul></li>
  <li>"this month": <code>start = DateTime.now.beginning_of_month; end = start.end_of_month</code></li>
  <li>"last month": <code>start = (DateTime.now - 1.month).beginning_of_month; end = start.end_of_month</code></li>
  <li>"<strong>this quarter</strong>": one of each of the four 3-month periods in the year, ie quarters. Ex: from 1/1/1999 to 3/31/1999 or from 10/1/2000 to 12/31/2000.</li>
  <li>"this year" = <code>start = DateTime.now.beginning_of_year --&gt; end = start.end_of_year</code></li>
  </ul>
  
  <p>I'm having trouble calculating the <strong>bold</strong> date ranges based on the current date (assume <code>DateTime.now</code>). </p>
  
  <p>How can I calculate the bi-weekly and quarterly period relative to the current date, <code>DateTime.now</code>?</p>
  
  <h2>Expected output</h2>
  
  <p>For the date May 7th, 2018 (5/7/2018):</p>
  
  <ul>
  <li>"<strong>this bi-week</strong>" should be the period of <code>5/1/2018</code> to <code>5/15/2018</code></li>
  <li>"<strong>this quarter</strong>" should be the period of <code>4/1/2018</code> to <code>6/30/2018</code></li>
  </ul>
  
  <p>For the date February 29th, 2020 (2/29/2020), a leap year:</p>
  
  <ul>
  <li>"<strong>this bi-week</strong>" should be the period of <code>2/15/2018</code> to <code>2/29/2018</code></li>
  <li>"<strong>this quarter</strong>" should be the period of <code>1/1/2018</code> to <code>3/31/2018</code></li>
  </ul>