private function getCacheId() { $end = ''; if ($this->defaultEndDate) { $end = $this->defaultEndDate->getTimestamp(); } $today = $this->today->getTimestamp(); return 'range' . $this->strPeriod . $this->strDate . $this->timezone . $end . $today; }
public function setUp() { $firstFixture = array_shift($this->fixtures); $this->setUpFixture($firstFixture); $initialSitesProperties = SitesManagerAPI::getInstance()->getAllSites(); foreach ($this->fixtures as $fixture) { $this->restoreSitesProperties($initialSitesProperties); $this->setUpFixture($fixture); } Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp()); }
/** * Performs three-way comparison of the month of the current date against the given `$date`'s year. * * @param \Piwik\Date $date Year to compare * @return int Returns `0` if the current year is equal to `$date`'s, `-1` if the current year is * earlier or `1` if the current year is later. */ public function compareYear(Date $date) { $currentYear = date('Y', $this->getTimestamp()); $toCompareYear = date('Y', $date->getTimestamp()); if ($currentYear == $toCompareYear) { return 0; } if ($currentYear < $toCompareYear) { return -1; } return 1; }
public static function getMinTimeProcessedForTemporaryArchive(Date $dateStart, \Piwik\Period $period, Segment $segment, Site $site) { $now = time(); $minimumArchiveTime = $now - Rules::getTodayArchiveTimeToLive(); $idSites = array($site->getId()); $isArchivingDisabled = Rules::isArchivingDisabledFor($idSites, $segment, $period->getLabel()); if ($isArchivingDisabled) { if ($period->getNumberOfSubperiods() == 0 && $dateStart->getTimestamp() <= $now) { // Today: accept any recent enough archive $minimumArchiveTime = false; } else { // This week, this month, this year: // accept any archive that was processed today after 00:00:01 this morning $timezone = $site->getTimezone(); $minimumArchiveTime = Date::factory(Date::factory('now', $timezone)->getDateStartUTC())->setTimezone($timezone)->getTimestamp(); } } return $minimumArchiveTime; }
/** * Returns all annotations within a specific date range. The result is * an array that maps site IDs with arrays of annotations within the range. * * Note: The date range is inclusive. * * @see self::get for info on what attributes stored within annotations. * * @param Date|bool $startDate The start of the date range. * @param Date|bool $endDate The end of the date range. * @param array|bool|int|string $idSite IDs of the sites whose annotations to * search through. * @return array Array mapping site IDs with arrays of annotations, eg: * array( * '5' => array( * array(...), // annotation * array(...), // annotation * ... * ), * '6' => array( * array(...), // annotation * array(...), // annotation * ... * ), * ) */ public function search($startDate, $endDate, $idSite = false) { if ($idSite) { $idSites = Site::getIdSitesFromIdSitesString($idSite); } else { $idSites = array_keys($this->annotations); } // collect annotations that are within the right date range & belong to the right // site $result = array(); foreach ($idSites as $idSite) { if (!isset($this->annotations[$idSite])) { continue; } foreach ($this->annotations[$idSite] as $idNote => $annotation) { if ($startDate !== false) { $annotationDate = Date::factory($annotation['date']); if ($annotationDate->getTimestamp() < $startDate->getTimestamp() || $annotationDate->getTimestamp() > $endDate->getTimestamp()) { continue; } } $this->augmentAnnotationData($idSite, $idNote, $annotation); $result[$idSite][] = $annotation; } // sort by annotation date if (!empty($result[$idSite])) { uasort($result[$idSite], array($this, 'compareAnnotationDate')); } } return $result; }