Exemple #1
0
 /**
  * Determine which kind of period is best to use.
  * See Range.test.php
  *
  * @param Date $startDate
  * @param Date $endDate
  */
 protected function processOptimalSubperiods($startDate, $endDate)
 {
     while ($startDate->isEarlier($endDate) || $startDate == $endDate) {
         $week = new Week($startDate);
         $startOfWeek = $week->getDateStart();
         $endOfWeek = $week->getDateEnd();
         if ($endOfWeek->isLater($endDate)) {
             $this->fillDayPeriods($startDate, $endDate);
         } elseif ($startOfWeek == $startDate) {
             $this->addSubperiod($week);
         } else {
             $this->fillDayPeriods($startDate, $endOfWeek);
         }
         $startDate = $endOfWeek->addDay(1);
     }
 }
Exemple #2
0
 public function testGetLabel()
 {
     $period = new Day(Date::today());
     $label = $period->getLabel();
     $this->assertInternalType('string', $label);
     $this->assertNotEmpty($label);
     $period = new Week(Date::today());
     $label = $period->getLabel();
     $this->assertInternalType('string', $label);
     $this->assertNotEmpty($label);
     $period = new Month(Date::today());
     $label = $period->getLabel();
     $this->assertInternalType('string', $label);
     $this->assertNotEmpty($label);
     $period = new Year(Date::today());
     $label = $period->getLabel();
     $this->assertInternalType('string', $label);
     $this->assertNotEmpty($label);
 }
Exemple #3
0
 /**
  * @group Core
  */
 public function testGetPrettyString()
 {
     $this->loadEnglishTranslation();
     $week = new Week(Date::factory('2024-10-09'));
     $shouldBe = 'From 2024-10-07 to 2024-10-13';
     $this->assertEquals($shouldBe, $week->getPrettyString());
 }
Exemple #4
0
 /**
  * Determine which kind of period is best to use.
  * See Range.test.php
  *
  * @param Date $startDate
  * @param Date $endDate
  */
 protected function processOptimalSubperiods($startDate, $endDate)
 {
     while ($startDate->isEarlier($endDate) || $startDate == $endDate) {
         $endOfPeriod = null;
         $month = new Month($startDate);
         $endOfMonth = $month->getDateEnd();
         $startOfMonth = $month->getDateStart();
         $year = new Year($startDate);
         $endOfYear = $year->getDateEnd();
         $startOfYear = $year->getDateStart();
         if ($startDate == $startOfYear && ($endOfYear->isEarlier($endDate) || $endOfYear == $endDate || $endOfYear->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString('Y') == $endOfYear->toString('Y') && $this->today->compareYear($endOfYear) == 0)) {
             $this->addSubperiod($year);
             $endOfPeriod = $endOfYear;
         } else {
             if ($startDate == $startOfMonth && ($endOfMonth->isEarlier($endDate) || $endOfMonth == $endDate || $endOfMonth->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString('Y') == $endOfMonth->toString('Y') && $this->today->compareMonth($endOfMonth) == 0)) {
                 $this->addSubperiod($month);
                 $endOfPeriod = $endOfMonth;
             } else {
                 // From start date,
                 //  Process end of week
                 $week = new Week($startDate);
                 $startOfWeek = $week->getDateStart();
                 $endOfWeek = $week->getDateEnd();
                 $firstDayNextMonth = $startDate->addPeriod(2, 'month')->setDay(1);
                 $useMonthsNextIteration = $firstDayNextMonth->isEarlier($endDate);
                 if ($useMonthsNextIteration && $endOfWeek->isLater($endOfMonth)) {
                     $this->fillArraySubPeriods($startDate, $endOfMonth, 'day');
                     $endOfPeriod = $endOfMonth;
                 } elseif ($this->isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) && ($endOfWeek->isEarlier($this->today) || $startOfWeek->toString() != $startDate->toString() || $endDate->isEarlier($this->today))) {
                     $this->fillArraySubPeriods($startDate, $endDate, 'day');
                     break 1;
                 } elseif ($startOfWeek->isEarlier($startDate) && $endOfWeek->isEarlier($this->today)) {
                     $this->fillArraySubPeriods($startDate, $endOfWeek, 'day');
                     $endOfPeriod = $endOfWeek;
                 } else {
                     $this->addSubperiod($week);
                     $endOfPeriod = $endOfWeek;
                 }
             }
         }
         $startDate = $endOfPeriod->addDay(1);
     }
 }
 public function testRangeLastweek_onFirstDayOfWeek()
 {
     $end = Date::factory('2013-11-04');
     $range = new Range('week', 'last2', 'UTC', $end);
     $correct = array();
     for ($i = 0; $i < 2; $i++) {
         $date = $end->subWeek($i);
         $week = new Week($date);
         $correct[] = $week->toString();
     }
     $correct = array_reverse($correct);
     $this->assertEquals($correct, $range->toString());
 }