Skip to content

Instantly share code, notes, and snippets.

@tistre
Last active December 7, 2015 12:23
Show Gist options
  • Save tistre/4dcf120dc5b756871f80 to your computer and use it in GitHub Desktop.
Save tistre/4dcf120dc5b756871f80 to your computer and use it in GitHub Desktop.
Lack of error handling in IntlDateFormatter::localtime()
<?php
// Correct input value:
// $value = 'Wednesday, December 18, 2014 4:05:06 PM PT';
// Wrong input value that I suppose should rather return false:
$value = 'XXX';
$formatter = new IntlDateFormatter
(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
$localtime = $formatter->localtime($value, $position);
var_dump(datefmt_get_error_code($formatter)); // int(0) no matter what
var_dump(intl_get_error_code()); // int(0) no matter what
var_dump($formatter->format($localtime)); // string(60) "Monday, December 7, 2015 at 4:17:13 AM Pacific Standard Time"
var_dump(datefmt_get_error_code($formatter)); // int(0) no matter what
var_dump(intl_get_error_code()); // int(0) no matter what
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment