toString() public method

Converts this date to the requested string format. See {@link http://php.net/date} for the list of format strings.
public toString ( string $format = 'Y-m-d' ) : string
$format string
return string
Ejemplo n.º 1
0
 protected static function getTable(Date $date, $type)
 {
     $tableNamePrefix = "archive_" . $type;
     $tableName = $tableNamePrefix . "_" . $date->toString('Y_m');
     $tableName = Common::prefixTable($tableName);
     self::createArchiveTablesIfAbsent($tableName, $tableNamePrefix);
     return $tableName;
 }
 private function setDateMonthAndYear($dateString, Date $archiveDate)
 {
     return $archiveDate->toString('Y-m') . '-' . Date::factory($dateString)->toString('d');
 }
Ejemplo n.º 3
0
 /**
  * Sets the last date available in the period selector's calendar. Usually this is just the "today" date
  * for a site (which varies based on the timezone of a site).
  *
  * @param Date $maxDate The max date.
  * @param View $view The view that contains the period selector.
  * @api
  */
 protected function setMaxDateView(Date $maxDate, $view)
 {
     $view->maxDateYear = $maxDate->toString('Y');
     $view->maxDateMonth = $maxDate->toString('m');
     $view->maxDateDay = $maxDate->toString('d');
 }
Ejemplo n.º 4
0
 /**
  * Given a monthly archive table, will delete all reports that are now outdated,
  * or reports that ended with an error
  *
  * @param \Piwik\Date $date
  * @return int|bool  False, or timestamp indicating which archives to delete
  */
 public static function shouldPurgeOutdatedArchives(Date $date)
 {
     if (self::$purgeOutdatedArchivesIsDisabled) {
         return false;
     }
     $key = self::FLAG_TABLE_PURGED . "blob_" . $date->toString('Y_m');
     $timestamp = Option::get($key);
     // we shall purge temporary archives after their timeout is finished, plus an extra 6 hours
     // in case archiving is disabled or run once a day, we give it this extra time to run
     // and re-process more recent records...
     $temporaryArchivingTimeout = self::getTodayArchiveTimeToLive();
     $hoursBetweenPurge = 6;
     $purgeEveryNSeconds = max($temporaryArchivingTimeout, $hoursBetweenPurge * 3600);
     // we only delete archives if we are able to process them, otherwise, the browser might process reports
     // when &segment= is specified (or custom date range) and would below, delete temporary archives that the
     // browser is not able to process until next cron run (which could be more than 1 hour away)
     if (self::isRequestAuthorizedToArchive() && (!$timestamp || $timestamp < time() - $purgeEveryNSeconds)) {
         Option::set($key, time());
         if (self::isBrowserTriggerEnabled()) {
             // If Browser Archiving is enabled, it is likely there are many more temporary archives
             // We delete more often which is safe, since reports are re-processed on demand
             $purgeArchivesOlderThan = Date::factory(time() - 2 * $temporaryArchivingTimeout)->getDateTime();
         } else {
             // If cron core:archive command is building the reports, we should keep all temporary reports from today
             $purgeArchivesOlderThan = Date::factory('today')->getDateTime();
         }
         return $purgeArchivesOlderThan;
     }
     Log::info("Purging temporary archives: skipped.");
     return false;
 }
Ejemplo n.º 5
0
 /**
  * The constructor
  * Initialize some local variables from the request
  * @param int $idSite
  * @param Date $date ($this->date from controller)
  * @param null|string $graphType
  * @throws Exception
  */
 public function __construct($idSite, $date, $graphType = 'graphEvolution')
 {
     $this->apiMethod = Common::getRequestVar('apiMethod', '', 'string');
     if (empty($this->apiMethod)) {
         throw new Exception("Parameter apiMethod not set.");
     }
     $this->label = DataTablePostProcessor::getLabelFromRequest($_GET);
     if (!is_array($this->label)) {
         throw new Exception("Expected label to be an array, got instead: " . $this->label);
     }
     $this->label = $this->label[0];
     if ($this->label === '') {
         throw new Exception("Parameter label not set.");
     }
     $this->period = Common::getRequestVar('period', '', 'string');
     PeriodFactory::checkPeriodIsEnabled($this->period);
     $this->idSite = $idSite;
     $this->graphType = $graphType;
     if ($this->period != 'range') {
         // handle day, week, month and year: display last X periods
         $end = $date->toString();
         list($this->date, $lastN) = EvolutionViz::getDateRangeAndLastN($this->period, $end);
     }
     $this->segment = \Piwik\API\Request::getRawSegmentFromRequest();
     $this->loadEvolutionReport();
 }
Ejemplo n.º 6
0
 /**
  * @internal
  */
 public function forgetRememberedArchivedReportsToInvalidate($idSite, Date $date)
 {
     $id = $this->buildRememberArchivedReportId($idSite, $date->toString());
     Option::delete($id);
 }
Ejemplo n.º 7
0
 /**
  * Returns true if a report with the given year & month should be purged or not.
  *
  * @param int $reportDateYear The year of the report in question.
  * @param int $reportDateMonth The month of the report in question.
  * @param Date $toRemoveDate The date a report must be older than in order to be purged.
  * @return bool
  */
 public static function shouldReportBePurged($reportDateYear, $reportDateMonth, $toRemoveDate)
 {
     $toRemoveYear = (int) $toRemoveDate->toString('Y');
     $toRemoveMonth = (int) $toRemoveDate->toString('m');
     return $reportDateYear < $toRemoveYear || $reportDateYear == $toRemoveYear && $reportDateMonth <= $toRemoveMonth;
 }
Ejemplo n.º 8
0
 private function getAllOverlappingChildPeriodsInRange(Date $dateStart, Date $dateEnd)
 {
     $result = array();
     $childPeriodType = $this->getImmediateChildPeriodLabel();
     if (empty($childPeriodType)) {
         return $result;
     }
     $childPeriods = Factory::build($childPeriodType, $dateStart->toString() . ',' . $dateEnd->toString());
     return array_merge($childPeriods->getSubperiods(), $childPeriods->getAllOverlappingChildPeriodsInRange($dateStart, $dateEnd));
 }
Ejemplo n.º 9
0
 public static function getTableMonthFromDate(Date $date)
 {
     return $date->toString('Y_m');
 }
Ejemplo n.º 10
0
 /**
  * The constructor
  * Initialize some local variables from the request
  * @param int $idSite
  * @param Date $date ($this->date from controller)
  * @param null|string $graphType
  * @throws Exception
  */
 public function __construct($idSite, $date, $graphType = null)
 {
     $this->apiMethod = Common::getRequestVar('apiMethod', '', 'string');
     if (empty($this->apiMethod)) {
         throw new Exception("Parameter apiMethod not set.");
     }
     $this->label = ResponseBuilder::getLabelFromRequest($_GET);
     $this->label = $this->label[0];
     if ($this->label === '') {
         throw new Exception("Parameter label not set.");
     }
     $this->period = Common::getRequestVar('period', '', 'string');
     if (empty($this->period)) {
         throw new Exception("Parameter period not set.");
     }
     $this->idSite = $idSite;
     $this->graphType = $graphType;
     if ($this->period != 'range') {
         // handle day, week, month and year: display last X periods
         $end = $date->toString();
         list($this->date, $lastN) = EvolutionViz::getDateRangeAndLastN($this->period, $end);
     }
     $this->segment = \Piwik\API\Request::getRawSegmentFromRequest();
     $this->loadEvolutionReport();
 }
 public function removeDate(Date $date)
 {
     $yearMonth = $date->toString('Y_m');
     $this->remove($yearMonth);
 }