Just installed Magento 2.2.2 into a new folder on the server. Everything has fired up as expected except for one of the cron jobs. When I run the cron job bin/magento cron:run (with all the correct parameters etc as per the documentation) it gives the error [Exception]
Warning: IntlDateFormatter:arse(): Date parsing failed in /home/sites/3b/6/6bfe122699/public_html/vendor/magento/framework/Stdlib/DateTime/Timezone.php on line 177
Any ideas how I fix this?
Hi @MillTech,
Can you check if you php configuration is the same for CLI and webserver?
Also, the defautl timezone is properly configured?
As far as I can tell, the php config is the same for CLI and webserver.
When you talk about the default timezone, is this Magento's or the web server's timezone?
I'm really confused what is happening here.
When I run the cron job bin/magento cron:run it still gives me the parse error. So, I added some echo statements into the Timezone.php script to try and see what was happening.
The line it fails on is in this function
public function date($date = null, $locale = null, $useTimezone = true, $includeTime = true)
{
$locale = $locale ?: $this->_localeResolver->getLocale();
$timezone = $useTimezone
? $this->getConfigTimezone()
: date_default_timezone_get();
switch (true) {
case (empty($date)):
return new \DateTime('now', new \DateTimeZone($timezone));
case ($date instanceof \DateTime):
return $date->setTimezone(new \DateTimeZone($timezone));
case ($date instanceof \DateTimeImmutable):
return new \DateTime($date->format('Y-m-d H:i:s'), $date->getTimezone());
case (!is_numeric($date)):
$timeType = $includeTime ? \IntlDateFormatter:HORT : \IntlDateFormatter::NONE;
$formatter = new \IntlDateFormatter(
$locale,
\IntlDateFormatter:HORT,
$timeType,
new \DateTimeZone($timezone)
);
echo $locale.'<br/>';
echo $timeType.'<br/>';
echo (new \DateTime($date))->getTimestamp();
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
break;
}
$locale gives en_GB which seems correct
$timeType gives the value 3
The echo from getTimetamp line gives 1515085680
This all seems fine to me so I took that bit of code and put it into a separate php file
<?php
$formatter = new \IntlDateFormatter(
'en_GB',
\IntlDateFormatter:HORT,
3,
new \DateTimeZone(date_default_timezone_get())
);
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
echo $date;
and ran it.
I got the result for $date of 1515086227
That all seems to be okay, there were no errors so why on earth is the cron job producing errors?
I'm out of ideas. I'm using Magento 2.2.2 and I don't get that error.
I've had a tinker with Timezone.php.
I have found that changing the line reading:
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
to:
$date = (new \DateTime($date))->getTimestamp();
solves the problem.
It appears that $formatter->parse($date) is not returning a value. I do not know why.
Is my fix safe?
Thanks.
Ronnie
I am getting the same problem with 2.2.3 and after upgrading to 2.2.4.
Ronnie
Hi @ronnie_davies,
I guess you'll find this link useful: https://github.com/magento/magento2/issues/10663
It seems is an open issue. Maybe you con participate there and contribute in order to help to solve it.
This happened because the PHP Intl extension isn’t installed or enabled.
Please make sure php_intl extension installed on the server and let me know.
If not installed then please follow below steps to install it.
Solutions For Linux-based Server (assuming you have root access):
For projects hosted on a shared hosting platform you must ask your hosting provider to install/enable the PHP Intl extension.
For Windows-based Server:
Edit: changed php7.0 occurrences with php7.x as the version may vary.
--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"