public function localeDateTime($dateTime, $format = '%B %e, %Y %H:%M')
{
if (!$dateTime instanceof \DateTime) {
$dateTime = new \DateTime($dateTime);
}
// Check for Windows to find and replace the %e modifier correctly
// @see: http://php.net/strftime
$os = strtoupper(substr(PHP_OS, 0, 3));
$format = $os !== 'WIN' ? $format : preg_replace('#(?<!%)((?:%%)*)%e#', '\\1%#d', $format);
// According to http://php.net/manual/en/function.setlocale.php manual
// if the second parameter is "0", the locale setting is not affected,
// only the current setting is returned.
$result = setlocale(LC_ALL, 0);
if ($result === false) {
// This shouldn't occur, but.. Dude!
// You ain't even got locale or English on your platform??
// Various things we could do. We could fail miserably, but a more
// graceful approach is to use the datetime to display a default
// format
$this->app['logger.system']->error('No valid locale detected. Fallback on DateTime active.', ['event' => 'system']);
return $dateTime->format('Y-m-d H:i:s');
} else {
$timestamp = $dateTime->getTimestamp();
return strftime($format, $timestamp);
}
}