コード例 #1
0
 public function testGetWeekStartAndEndDatesBetweenTwoDatesInARange()
 {
     $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-08-03');
     $this->assertEquals('2013-01-20', $monthsData['2013-01-14']);
     $this->assertEquals('2013-08-04', $monthsData['2013-07-29']);
     $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-21', '2013-01-28');
     $compareData = array('2013-01-21' => '2013-01-27', '2013-01-28' => '2013-02-03');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-01-26');
     $compareData = array('2013-01-14' => '2013-01-20', '2013-01-21' => '2013-01-27');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2014-01-26');
     $this->assertEquals('2013-01-20', $monthsData['2013-01-14']);
     $this->assertEquals('2014-01-26', $monthsData['2014-01-20']);
     $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2012-12-28', '2013-01-03');
     $compareData = array('2012-12-24' => '2012-12-30', '2012-12-31' => '2013-01-06');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-04-01', '2013-04-01');
     $compareData = array('2013-04-01' => '2013-04-07');
     $this->assertEquals($compareData, $monthsData);
 }
 /**
  * Given a begin date, end date and grouping type, return array of data that includes information on how the
  * grouping breaks up by the date range including the start/end dateTime for each range and a display label
  * @param string $beginDate
  * @param string $endDate
  * @param string $groupBy
  * @param boolean $treatDatesAsDefinitive - if the group begin/end dates should be restricted by the passed
  * begin end dates, then set this true. If you want the true begin month or end month to be returned then set
  * to false.
  * @throws NotSupportedException
  * @return array
  */
 public static function makeGroupedDateTimeData($beginDate, $endDate, $groupBy, $treatDatesAsDefinitive = true)
 {
     assert('is_string($beginDate)');
     assert('is_string($endDate)');
     assert('is_string($groupBy)');
     $data = array();
     if ($groupBy == MarketingOverallMetricsForm::GROUPING_TYPE_DAY) {
         foreach (DateTimeUtil::getDatesBetweenTwoDatesInARange($beginDate, $endDate) as $date) {
             $data[] = array('beginDate' => $date, 'endDate' => $date, 'displayLabel' => static::resolveAbbreviatedDayMonthDisplayLabel($date));
         }
     } elseif ($groupBy == MarketingOverallMetricsForm::GROUPING_TYPE_WEEK) {
         foreach (DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange($beginDate, $endDate) as $beginWeekDate => $endWeekDate) {
             $displayLabel = static::resolveAbbreviatedDayMonthDisplayLabel($beginWeekDate);
             if ($treatDatesAsDefinitive) {
                 if ($beginWeekDate < $beginDate) {
                     $beginWeekDate = $beginDate;
                 }
                 if ($endWeekDate > $endDate) {
                     $endWeekDate = $endDate;
                 }
             }
             $data[] = array('beginDate' => $beginWeekDate, 'endDate' => $endWeekDate, 'displayLabel' => $displayLabel);
         }
     } elseif ($groupBy == MarketingOverallMetricsForm::GROUPING_TYPE_MONTH) {
         foreach (DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange($beginDate, $endDate) as $beginMonthDate => $endMonthDate) {
             if ($treatDatesAsDefinitive) {
                 if ($beginMonthDate < $beginDate) {
                     $beginMonthDate = $beginDate;
                 }
                 if ($endMonthDate > $endDate) {
                     $endMonthDate = $endDate;
                 }
             }
             $data[] = array('beginDate' => $beginMonthDate, 'endDate' => $endMonthDate, 'displayLabel' => static::resolveAbbreviatedMonthDisplayLabel($beginMonthDate));
         }
     } else {
         throw new NotSupportedException();
     }
     return $data;
 }