當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。