Warning generated when editing a node and don't permitted save, generate error message "You have to specify a valid date."

On Drupal\node\NodeFormController

before
$node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d H:i:s O');
after
$node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d HH:mm:ss Z');

Example:
print_r($node->getCreatedTime());//1377543481
$node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d H:i:s O');
print_r($node->date); //2013-58-26 15::
$node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d HH:mm:ss Z');
print_r($node->date); //2013-58-26 15:58:01 -0300

Warning: date_format() expects parameter 1 to be DateTime, boolean given in Drupal\node\NodeFormController->form() (line 202 of core/modules/node/lib/Drupal/node/NodeFormController.php).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Cyberwolf’s picture

Assigned: Unassigned » Cyberwolf
Cyberwolf’s picture

This seems to occur when a 'custom' formatting string is passed to format_date() and PHPs Internationalization (intl) extension is available. Drupal's date classes try to use intl for formatting dates if it's available, but intl expect ICU style date format strings which differ from PHP date formats.

I think a proper, quick way to solve this for now is ignoring intl when a custom date format is passed to format_date(). A patch is attached that takes this approach. I replaced the variable $key as well with $format_string_type which is much better describing the contents of the variable.

Cyberwolf’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2074535-dateformat-custom-string-2.patch, failed testing.

Cyberwolf’s picture

Status: Needs work » Closed (duplicate)

Seems like this is a duplicate of #2000384: php-intl module causes problems with Date and Time fields when editing Basic Page.

Edit: had another look at it but this is not exactly the same problem.

Cyberwolf’s picture

Cyberwolf’s picture

Assigned: Cyberwolf » Unassigned
Status: Closed (duplicate) » Needs work
marcingy’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)