public static function niceDate($dateString = null, $format = null, array $options = [])
{
$defaults = ['default' => '-----', 'timezone' => null];
$options += $defaults;
if ($options['timezone'] === null && strlen($dateString) === 10) {
$options['timezone'] = date_default_timezone_get();
}
if ($options['timezone']) {
$options['timezone'] = static::safeCreateDateTimeZone($options['timezone']);
}
if ($dateString === null) {
return $options['default'];
}
if (!is_object($dateString)) {
$date = new DateTime($dateString, $options['timezone']);
} else {
$date = $dateString;
}
$date = $date->format('U');
if ($date === null || $date === false || $date <= 0) {
return $options['default'];
}
if ($format === null) {
if (is_int($dateString) || strpos($dateString, ' ') !== false) {
$format = FORMAT_NICE_YMDHM;
} else {
$format = FORMAT_NICE_YMD;
}
}
$ret = date($format, $date);
if (!empty($options['oclock'])) {
switch ($format) {
case FORMAT_NICE_YMDHM:
case FORMAT_NICE_YMDHMS:
case FORMAT_NICE_HM:
case FORMAT_NICE_HMS:
$ret .= ' ' . __d('tools', 'o\'clock');
break;
}
}
return $ret;
}