当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange方法代码示例

本文整理汇总了PHP中DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange方法的具体用法?PHP DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange怎么用?PHP DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTimeUtil的用法示例。


在下文中一共展示了DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: makeGroupedDateTimeData

 /**
  * 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;
 }
开发者ID:KulturedKitsch,项目名称:kulturedkitsch.info,代码行数:52,代码来源:MarketingChartDataProvider.php

示例2: testGetMonthStartAndEndDatesBetweenTwoDatesInARange

 public function testGetMonthStartAndEndDatesBetweenTwoDatesInARange()
 {
     $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-02-01', '2013-06-01');
     $compareData = array('2013-02-01' => '2013-02-28', '2013-03-01' => '2013-03-31', '2013-04-01' => '2013-04-30', '2013-05-01' => '2013-05-31', '2013-06-01' => '2013-06-30');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-08-03');
     $compareData = array('2013-01-01' => '2013-01-31', '2013-02-01' => '2013-02-28', '2013-03-01' => '2013-03-31', '2013-04-01' => '2013-04-30', '2013-05-01' => '2013-05-31', '2013-06-01' => '2013-06-30', '2013-07-01' => '2013-07-31', '2013-08-01' => '2013-08-31');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-01-26');
     $compareData = array('2013-01-01' => '2013-01-31');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2014-01-26');
     $compareData = array('2013-01-01' => '2013-01-31', '2013-02-01' => '2013-02-28', '2013-03-01' => '2013-03-31', '2013-04-01' => '2013-04-30', '2013-05-01' => '2013-05-31', '2013-06-01' => '2013-06-30', '2013-07-01' => '2013-07-31', '2013-08-01' => '2013-08-31', '2013-09-01' => '2013-09-30', '2013-10-01' => '2013-10-31', '2013-11-01' => '2013-11-30', '2013-12-01' => '2013-12-31', '2014-01-01' => '2014-01-31');
     $this->assertEquals($compareData, $monthsData);
     $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-04-01', '2013-04-01');
     $compareData = array('2013-04-01' => '2013-04-30');
     $this->assertEquals($compareData, $monthsData);
 }
开发者ID:sandeep1027,项目名称:zurmo_,代码行数:18,代码来源:DateTimeUtilTest.php


注:本文中的DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。