Ejemplo n.º 1
0
 /**
  * @group Core
  */
 public function testGetPrettyString()
 {
     Translate::loadEnglishTranslation();
     $year = new Year(Date::factory('2024-10-09'));
     $shouldBe = '2024';
     $this->assertEquals($shouldBe, $year->getPrettyString());
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 public function testCustomRangeYearUsesCurrentYear_onLastDayOfYear()
 {
     $range = new Range('range', '2013-01-01,2013-12-31', 'UTC', Date::factory('2013-12-31'));
     $year2013 = new Year(Date::factory('2013-01-01'));
     $correct = array($year2013->toString());
     $this->assertEquals(1, $range->getNumberOfSubperiods());
     $this->assertEquals($correct, $range->toString());
 }