Scalr_Util_DateTime::yearweek PHP Method

yearweek() public static method

Gets the week of the year in the same way as MYSQL's YEARWEEK(date, 0) MODE 0
public static yearweek ( string $date ) : number
$date string The date YYYY-MM-DD
return number Returns yearweek, for example: 201402
    public static function yearweek($date)
    {
        $year = substr($date, 0, 4);
        $week = strftime('%U', strtotime($date));
        if ($week == 0) {
            return self::yearweek(--$year . '-12-31');
        }
        return sprintf('%d%02d', $year, $week);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * {@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];
 }
All Usage Examples Of Scalr_Util_DateTime::yearweek