Exemple #1
0
 /**
  * Gets the week range from the week of month.
  * 
  * @param int $weekOfMonth The week of the month
  * @param \DateTime $month Any date time within the month you want
  * @param int $weekStart ISO-8601 numeric representation of the day of the 
  *                       week (1 = Monday,..., 7 = Sunday)
  * @return \Mce\Date\Range\Inclusive
  */
 public static function getRangeFromNumber($weekOfMonth, \DateTime $month, $weekStart = 1)
 {
     // find the week day of the first of the month and add $weekOfMonth - 1 weeks to it
     try {
         $start = Month::getNWeekday($weekOfMonth, $weekStart, $month);
     } catch (\RangeException $e) {
         throw new \RangeException("{$month->format('F Y')} does not have {$weekOfMonth} weeks (week start = {$weekStart}");
     }
     $end = clone $start;
     $end->add(new \DateInterval("P6D"));
     $end->setTime(23, 59, 59);
     return new InclusiveRange($start, $end);
 }
Exemple #2
0
 /**
  * @covers Mce\Date\Math\Month::getNWeekday
  */
 public function testGetNWeekday()
 {
     // test the basic functionality
     $n = 3;
     $weekday = 3;
     $month = new DateTime('2013-04-01');
     $expected = new DateTime('2013-04-17');
     $actual = Month::getNWeekday($n, $weekday, $month);
     $this->assertEquals($actual, $expected);
     // out of bounds
     $n = 5;
     $this->setExpectedException('\\RangeException');
     Month::getNWeekday(5, $weekday, $month);
 }