27 \IntlDateFormatter::FULL,
28 \IntlDateFormatter::LONG,
29 \IntlDateFormatter::MEDIUM,
30 \IntlDateFormatter::SHORT,
79 $this->_scopeResolver = $scopeResolver;
80 $this->_localeResolver = $localeResolver;
82 $this->_defaultTimezonePath = $defaultTimezonePath;
83 $this->_scopeConfig = $scopeConfig;
84 $this->_scopeType = $scopeType;
108 return $this->_scopeConfig->getValue(
110 $scopeType ?: $this->_scopeType,
120 return (
new \IntlDateFormatter(
121 $this->_localeResolver->getLocale(),
123 \IntlDateFormatter::NONE
144 return (
new \IntlDateFormatter(
145 $this->_localeResolver->getLocale(),
146 \IntlDateFormatter::NONE,
162 public function date($date =
null, $locale =
null, $useTimezone =
true, $includeTime =
true)
164 $locale = $locale ?: $this->_localeResolver->getLocale();
165 $timezone = $useTimezone
167 : date_default_timezone_get();
171 return new \DateTime(
'now',
new \DateTimeZone($timezone));
173 return $date->setTimezone(
new \DateTimeZone($timezone));
174 case ($date instanceof \DateTimeImmutable):
175 return new \DateTime($date->format(
'Y-m-d H:i:s'), $date->getTimezone());
176 case (!is_numeric($date)):
177 $timeType = $includeTime ? \IntlDateFormatter::SHORT : \IntlDateFormatter::NONE;
178 $formatter = new \IntlDateFormatter(
180 \IntlDateFormatter::SHORT,
182 new \DateTimeZone($timezone)
185 $date = $this->appendTimeIfNeeded($date, $includeTime);
186 $date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
190 return (
new \
DateTime(
null,
new \DateTimeZone($timezone)))->setTimestamp($date);
196 public function scopeDate($scope =
null, $date =
null, $includeTime =
false)
199 $date = new \DateTime(is_numeric($date) ?
'@' . $date : $date,
new \DateTimeZone($timezone));
201 $date->setTime(0, 0, 0);
209 public function formatDate($date =
null,
$format = \IntlDateFormatter::SHORT, $showTime =
false)
211 $formatTime = $showTime ?
$format : \IntlDateFormatter::NONE;
213 if (!($date instanceof \DateTimeInterface)) {
214 $date = new \DateTime($date);
226 $currentTimezone = @date_default_timezone_get();
227 @date_default_timezone_set($timezone);
228 $date =
date(
'Y-m-d H:i:s');
229 @date_default_timezone_set($currentTimezone);
230 return strtotime($date);
239 $scope = $this->_scopeResolver->getScope($scope);
243 $fromTimeStamp = strtotime($dateFrom);
244 $toTimeStamp = strtotime($dateTo);
247 $toTimeStamp += 86400;
251 if (!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp) {
252 }
elseif (!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp) {
270 $dateType = \IntlDateFormatter::SHORT,
271 $timeType = \IntlDateFormatter::SHORT,
276 if (!($date instanceof \DateTimeInterface)) {
277 $date = new \DateTime($date);
280 if ($timezone ===
null) {
281 if ($date->getTimezone() ==
null || $date->getTimezone()->getName() ==
'UTC' 282 || $date->getTimezone()->getName() ==
'+00:00' 286 $timezone = $date->getTimezone();
290 $formatter = new \IntlDateFormatter(
291 $locale ?: $this->_localeResolver->getLocale(),
298 return $formatter->format($date);
312 if (!($date instanceof \DateTimeInterface)) {
313 if ($date instanceof \DateTimeImmutable) {
314 $date = new \DateTime($date->format(
'Y-m-d H:i:s'), new \DateTimeZone($this->
getConfigTimezone()));
322 'The DateTime object timezone needs to be the same as the "%1" timezone in config.',
329 $date->setTimezone(
new \DateTimeZone(
'UTC'));
341 private function appendTimeIfNeeded($date, $includeTime)
343 if ($includeTime && !preg_match(
'/\d{1}:\d{2}/', $date)) {
elseif(isset( $params[ 'redirect_parent']))
date($date=null, $locale=null, $useTimezone=true, $includeTime=true)
getDateFormatWithLongYear()
formatDate($date=null, $format=\IntlDateFormatter::SHORT, $showTime=false)
formatDateTime( $date, $dateType=\IntlDateFormatter::SHORT, $timeType=\IntlDateFormatter::SHORT, $locale=null, $timezone=null, $pattern=null)
getDateFormat($type=\IntlDateFormatter::SHORT)
getConfigTimezone($scopeType=null, $scopeCode=null)
scopeDate($scope=null, $date=null, $includeTime=false)
convertConfigTimeToUtc($date, $format='Y-m-d H:i:s')
scopeTimeStamp($scope=null)
getTimeFormat($type=\IntlDateFormatter::SHORT)
__construct(ScopeResolverInterface $scopeResolver, ResolverInterface $localeResolver, \Magento\Framework\Stdlib\DateTime $dateTime, ScopeConfigInterface $scopeConfig, $scopeType, $defaultTimezonePath)
isScopeDateInInterval($scope, $dateFrom=null, $dateTo=null)