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


PHP Scalr_Util_DateTime::yearweek方法代码示例

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


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

示例1: current

 /**
  * {@inheritdoc}
  * @see Iterator::current()
  * @return ChartPointInfo
  */
 public function current()
 {
     if (!isset($this->c[$this->i])) {
         $chartPoint = new ChartPointInfo($this);
         $previousPeriodDt = clone $chartPoint->dt;
         $previousPeriodDt->sub($this->getPreviousPeriodInterval());
         $ddt = clone $chartPoint->dt;
         $ddt->modify('next saturday');
         if ($ddt > $chartPoint->end) {
             $ddt = $chartPoint->end;
         }
         $chartPoint->label = $chartPoint->dt->format('M j') . ' - ' . $ddt->format('M j');
         $chartPoint->key = \Scalr_Util_DateTime::yearweek($chartPoint->dt->format('Y-m-d'));
         $chartPoint->previousPeriodKey = \Scalr_Util_DateTime::yearweek($previousPeriodDt->format('Y-m-d'));
         $chartPoint->show = $chartPoint->i % 3 == 0 ? $chartPoint->dt->format('M j') : ($chartPoint->isLastPoint && $chartPoint->i % 3 > 1 ? $ddt->format('M j') : '');
         $this->c[$this->i] = $chartPoint;
     }
     return $this->c[$this->i];
 }
开发者ID:mheydt,项目名称:scalr,代码行数:24,代码来源:ChartQuarterlyIterator.php

示例2: __construct

 /**
  * Constructor
  *
  * @param   ChartPeriodIterator $iterator  The iterator
  * @throws  \InvalidArgumentException
  */
 public function __construct(ChartPeriodIterator $iterator)
 {
     $this->mode = $iterator->getMode();
     $this->dt = $iterator->getIterationTimestamp();
     $this->interval = $iterator->getInterval();
     $this->i = $iterator->getIterationNumber();
     $prevStart = $iterator->getPreviousStart();
     $previousPeriodDt = clone $this->dt;
     $previousPeriodDt->sub($iterator->getPreviousPeriodInterval());
     $this->start = $iterator->getStart();
     $this->end = $iterator->getEnd();
     $this->isLastPoint = $iterator->isLastPoint();
     if ($this->mode == 'year' || $this->mode == 'custom' && $this->interval == '1 month') {
         $this->show = $this->label = $this->dt->format('M');
         $this->key = $this->dt->format('Y-m');
         $this->previousPeriodKey = $previousPeriodDt->format('Y-m');
     } elseif ($this->mode == 'quarter' || $this->mode == 'custom' && $this->interval == '1 week') {
         $ddt = clone $this->dt;
         $ddt->modify('next saturday');
         if ($ddt > $this->end) {
             $ddt = $this->end;
         }
         $this->label = $this->dt->format('M j') . ' - ' . $ddt->format('M j');
         $this->key = \Scalr_Util_DateTime::yearweek($this->dt->format('Y-m-d'));
         $this->previousPeriodKey = \Scalr_Util_DateTime::yearweek($previousPeriodDt->format('Y-m-d'));
         $this->show = $this->i % 3 == 0 ? $this->dt->format('M j') : ($this->isLastPoint && $this->i % 3 > 1 ? $ddt->format('M j') : '');
     } elseif ($this->mode == 'week') {
         $this->label = $this->dt->format('l, M j');
         $this->show = $this->dt->format('M j');
         $this->key = $this->dt->format('Y-m-d');
         $this->previousPeriodKey = $previousPeriodDt->format('Y-m-d');
     } elseif ($this->mode == 'month' || $this->mode == 'custom' && $this->interval == '1 day') {
         $this->label = $this->dt->format('M j');
         $this->key = $this->dt->format('Y-m-d');
         $this->previousPeriodKey = $previousPeriodDt->format('Y-m-d');
         $this->show = $this->i % 4 == 0 || $this->isLastPoint && $this->i % 4 > 2 ? $this->dt->format('M j') : '';
     } elseif ($this->mode == 'custom') {
         switch ($this->interval) {
             case '1 hour':
                 $h = $this->dt->format('H');
                 $this->label = $this->dt->format('l, M j, g A');
                 $this->show = $h == 0 ? $this->dt->format('M j') : ($h % 3 == 0 ? $this->dt->format('g a') : '');
                 $this->key = $this->dt->format("Y-m-d H:00:00");
                 $this->previousPeriodKey = $previousPeriodDt->format('Y-m-d H:00:00');
                 break;
             case '1 quarter':
                 //Quarter breakdown is not supported yet
                 $quarters = new Quarters(SettingEntity::getQuarters());
                 $currentPeriod = $quarters->getPeriodForDate($this->start);
                 $prevPeriod = $quarters->getPeriodForDate($prevStart);
                 $this->show = $this->label = $currentPeriod->year . ' Q' . $currentPeriod->quarter;
                 $this->key = $currentPeriod->year . '-' . $currentPeriod->quarter;
                 $this->previousPeriodKey = $prevPeriod->year . '-' . $prevPeriod->quarter;
                 break;
             case '1 year':
                 $this->show = $this->label = $this->dt->format('Y');
                 $this->key = $this->label;
                 $this->previousPeriodKey = $previousPeriodDt->format('Y');
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Unsupported interval for custom mode %s.', $this->interval));
                 break;
         }
     } else {
         throw new \InvalidArgumentException(sprintf('Invalid mode %s', strip_tags($this->mode)));
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:73,代码来源:ChartPointInfo.php

示例3: current

 /**
  * {@inheritdoc}
  * @see Iterator::current()
  * @return ChartPointInfo
  */
 public function current()
 {
     if (!isset($this->c[$this->i])) {
         $chartPoint = new ChartPointInfo($this);
         $previousPeriodDt = clone $chartPoint->dt;
         $previousPeriodDt->sub($this->getPreviousPeriodInterval());
         switch ($chartPoint->interval) {
             case '1 hour':
                 $h = $chartPoint->dt->format('H');
                 $chartPoint->label = $chartPoint->dt->format('l, M j, g A');
                 $chartPoint->show = $h == 0 ? $chartPoint->dt->format('M j') : ($h % 3 == 0 ? $chartPoint->dt->format('g a') : '');
                 $chartPoint->key = $chartPoint->dt->format("Y-m-d H:00:00");
                 $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y-m-d H:00:00');
                 break;
             case '1 day':
                 $chartPoint->label = $chartPoint->dt->format('M j');
                 $chartPoint->key = $chartPoint->dt->format('Y-m-d');
                 $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y-m-d');
                 $chartPoint->show = $chartPoint->i % 4 == 0 || $chartPoint->isLastPoint && $chartPoint->i % 4 > 2 ? $chartPoint->dt->format('M j') : '';
                 break;
             case '1 week':
                 $ddt = clone $chartPoint->dt;
                 $ddt->modify('next saturday');
                 if ($ddt > $chartPoint->end) {
                     $ddt = $chartPoint->end;
                 }
                 $chartPoint->label = $chartPoint->dt->format('M j') . ' - ' . $ddt->format('M j');
                 $chartPoint->key = \Scalr_Util_DateTime::yearweek($chartPoint->dt->format('Y-m-d'));
                 $chartPoint->previousPeriodKey = \Scalr_Util_DateTime::yearweek($previousPeriodDt->format('Y-m-d'));
                 $chartPoint->show = $chartPoint->i % 3 == 0 ? $chartPoint->dt->format('M j') : ($chartPoint->isLastPoint && $chartPoint->i % 3 > 1 ? $ddt->format('M j') : '');
                 break;
             case '1 month':
                 $diffdays = $this->start->diff($this->end, true)->days;
                 if ($diffdays < 366) {
                     $chartPoint->show = $chartPoint->label = $chartPoint->dt->format('M');
                 } else {
                     $chartPoint->show = $chartPoint->label = $chartPoint->dt->format('M, Y');
                 }
                 $chartPoint->key = $chartPoint->dt->format('Y-m');
                 $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y-m');
                 break;
             case '1 quarter':
                 //Quarter breakdown is not supported yet
                 $quarters = new Quarters(SettingEntity::getQuarters());
                 $currentPeriod = $quarters->getPeriodForDate($chartPoint->start);
                 $prevStart = $this->getPreviousStart();
                 $prevPeriod = $quarters->getPeriodForDate($prevStart);
                 $chartPoint->show = $chartPoint->label = $currentPeriod->year . ' Q' . $currentPeriod->quarter;
                 $chartPoint->key = $currentPeriod->year . '-' . $currentPeriod->quarter;
                 $chartPoint->previousPeriodKey = $prevPeriod->year . '-' . $prevPeriod->quarter;
                 break;
             case '1 year':
                 $chartPoint->show = $chartPoint->label = $chartPoint->dt->format('Y');
                 $chartPoint->key = $chartPoint->label;
                 $chartPoint->previousPeriodKey = $previousPeriodDt->format('Y');
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf('Unsupported interval for custom mode %s.', $chartPoint->interval));
                 break;
         }
         $this->c[$this->i] = $chartPoint;
     }
     return $this->c[$this->i];
 }
开发者ID:mheydt,项目名称:scalr,代码行数:69,代码来源:ChartCustomIterator.php

示例4: testYearweek

 /**
  * @test
  * @dataProvider providerYearweek
  */
 public function testYearweek($date)
 {
     $db = \Scalr::getDb();
     $expected = $db->GetOne("SELECT YEARWEEK(?, 0)", [$date]);
     $this->assertEquals($expected, \Scalr_Util_DateTime::yearweek($date));
 }
开发者ID:scalr,项目名称:scalr,代码行数:10,代码来源:DateTimeTest.php


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