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); }
/** * {@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]; }