cancel
Showing results for 
Search instead for 
Did you mean: 

bin/magento cron:run gives error in IntlDateFormatter

bin/magento cron:run gives error in IntlDateFormatter

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:Smiley Tonguearse(): 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?

10 REPLIES

Re: bin/magento cron:run gives error in IntlDateFormatter

Hi @MillTech,

 

Can you check if you php configuration is the same for CLI and webserver?

Also, the defautl timezone is properly configured?

 

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: bin/magento cron:run gives error in IntlDateFormatter

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?

Re: bin/magento cron:run gives error in IntlDateFormatter

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:Smiley FrustratedHORT : \IntlDateFormatter::NONE;
$formatter = new \IntlDateFormatter(
 
$locale,
 \IntlDateFormatter:Smiley FrustratedHORT,
 
$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:Smiley FrustratedHORT,
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?

Re: bin/magento cron:run gives error in IntlDateFormatter

I'm out of ideas. I'm using Magento 2.2.2 and I don't get that error.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: bin/magento cron:run gives error in IntlDateFormatter

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

Re: bin/magento cron:run gives error in IntlDateFormatter

Hi @ronnie_davies,

 

Which version of Magento are you using?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: bin/magento cron:run gives error in IntlDateFormatter

I am getting the same problem with 2.2.3 and after upgrading to 2.2.4.

 

Ronnie

Re: bin/magento cron:run gives error in IntlDateFormatter

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.

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: bin/magento cron:run gives error in IntlDateFormatter

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):

  • Make sure the php_intl.so file exists within your php extensions directory, find the extensions directory by:
    • using phpinfo()
    • running this command: php -r “echo ini_get(‘extension_dir’);
    • (note: both options gets the extension_dir right from the PHP runtime configuration)
  • If the file exists:
    • search for the config file (php.ini, usually /etc/php.ini) and open it
    • Make sure the line “extension=php_intl.so” is existing and not commented
    • Restart the web server (usually sudo service httpd restart)
    • Check if the extension is enabled using phpinfo()
  • If the file doesn’t exist
    • Check your php version by running the “php -v” command
    • For PHP 5 install the php-intl package using your package manager – package managers and commands
      • Most common: apt-get install php-intl (for ubuntu-based linux) or yum install php-intl (for CentOS)
    • For PHP 7, install the php7.x-intl (depending on your php version)
    • Repeat the steps for the case in which the file exists

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:

  • Make sure the php_intl.dll file exists within your php extensions directory
    • for separately installed PHP: C:\path\to\php\ext\
    • for xampp: C:\path\to\xampp\php\ext
    • (note: your drive letter might be different)
  • If the file exists:
    • search for the config file (php.ini, usually in the same folder as the php executable) and open it
    • Make sure the line “extension=php_intl.dll” is existing and not commented
    • Restart the web server (usually apache)
    • Check if the extension is enabled using phpinfo()
  • If the file doesn’t exist:
    • Check your php version by running the “php -v” command
    • Download the PHP version that corresponds to yours from the PHP Downloads Page (TS/NTS, x86/x64)
      • To find thread safety for php, run: php -i | findstr “Thread” , source & more info. 
    • Search for the php_intl.dll file in the ext folder in that version and copy it in your php\ext folder
    • Repeat the steps for the case in which the file exists

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"