/** * */ public function testGetTimeZoneName() { $this->assertEquals('Europe/Berlin', $this->factory->getTimeZoneName('Europe/Berlin')); $this->assertEquals('Europe/Paris', $this->factory->getTimeZoneName('+01:00')); $this->assertEquals('Europe/Paris', $this->factory->getTimeZoneName(3600)); $this->assertEquals('Europe/Berlin', $this->factory->getTimeZoneName('cest')); $this->assertNull($this->factory->getTimeZoneName(-7300)); $this->assertEquals('America/Adak', $this->factory->getTimeZoneName(-36000, 1)); }
/** * {@inheritdoc} */ public function scopeDate($scope = null, $date = null, $includeTime = false) { $timezone = $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope); $date = $this->_dateFactory->create(array('date' => $date, 'part' => null, 'locale' => $this->_localeResolver->getLocale())); $date->setTimezone($timezone); if (!$includeTime) { $date->setHour(0)->setMinute(0)->setSecond(0); } return $date; }
/** * Creates a filename from title, prefixed with date if required. * * @param string The title to use e.g. IMG-1234.jpg * @return string The filename */ protected function buildFilename($title) { $ext = pathinfo($title, PATHINFO_EXTENSION); $filename = str_replace('.' . $ext, '', $title); $datePrefix = '/'; if ($this->mediaOrganizeByDate) { $now = $this->DateFactory->newStorageDate(); $datePrefix = $now->format('/Y/m/d/'); } return $datePrefix . SlugUtils::createSlug($filename) . '.' . strtolower($ext); }
function withoutFlyweightTest() { $startTime = microtime(true); $users = []; for ($i = 0; $i < MAX_INSTANCES; ++$i) { $month = mt_rand(1, 12); $maxDays = cal_days_in_month(CAL_GREGORIAN, $month, 2015); $day = mt_rand(1, $maxDays); $user = new User($i, DateFactory::getDate(2015, $month, $day)); $users[] = $user; } $data = new \stdClass(); $data->dateInstanceCount = count($users); $data->userInstanceCount = count($users); $data->memoryUsage = memory_get_usage(); $data->time = microtime(true) - $startTime; return $data; }
/** * Performs a fetch of our data from the filecache without logging in the logger. * That allows this method to be used in other locations. * * @param string $key The key to fetch * * @return mixed Data in this->storageFormat format or FALSE if data is invalid */ protected function getData($key) { $filename = $this->file($key); if (!file_exists($filename)) { return false; } else { $data = $this->readFile($filename); if ($this->isExpired(null, $data)) { return false; } else { // if going to expire in 10 seconds, extend the cache and let this request refresh it $expire = $data['expires']; $value = $data['value']; $duration = $data['duration']; $now = $this->DateFactory->newStorageDate(); if (!empty($value) && $duration > 0 && $now->toUnix() > $expire - 10) { $this->put($key, $value, $duration); return false; } return $data; } } }