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); }
public function _testRangeLastmonth_onFirstOfMonth() { $end = Date::factory('2013-11-01'); $range = new Range('month', 'last10', 'UTC', $end); $correct = array(); for ($i = 0; $i < 10; $i++) { $date = $end->subMonth($i); $week = new Month($date); $correct[] = $week->toString(); } $correct = array_reverse($correct); $this->assertEquals(10, $range->getNumberOfSubperiods()); $this->assertEquals($correct, $range->toString()); }
/** * 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 testGetPrettyString() { $month = new Month(Date::factory('2024-10-09')); $shouldBe = '2024-10'; $this->assertEquals($shouldBe, $month->getPrettyString()); }