Use international standard date and time notation ...

... instead of depending on the locale.
We hardcode date and time formats all over the place anyway.

refs #6778
This commit is contained in:
Eric Lippmann 2015-05-19 13:26:46 +02:00
parent 9edc4a129b
commit 14b24ff57d
1 changed files with 16 additions and 14 deletions

View File

@ -3,10 +3,8 @@
namespace Icinga\Date; namespace Icinga\Date;
use IntlDateFormatter;
/** /**
* ICU date formatting * Date formatting
*/ */
class DateFormatter class DateFormatter
{ {
@ -57,8 +55,11 @@ class DateFormatter
} }
if ($diff > 3600 * 24 * 3) { if ($diff > 3600 * 24 * 3) {
$type = static::DATE; $type = static::DATE;
$fmt = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::NONE); if (date('Y') === date('Y', $time)) {
$formatted = $fmt->format($time); $formatted = date('M j', $time);
} else {
$formatted = date('Y-m', $time);
}
} else { } else {
$minutes = floor($diff / 60); $minutes = floor($diff / 60);
if ($minutes < 60) { if ($minutes < 60) {
@ -67,9 +68,13 @@ class DateFormatter
} else { } else {
$hours = floor($minutes / 60); $hours = floor($minutes / 60);
if ($hours < 24) { if ($hours < 24) {
$type = static::TIME; if (date('d') === date('d', $time)) {
$fmt = new IntlDateFormatter(null, IntlDateFormatter::NONE, IntlDateFormatter::SHORT); $type = static::TIME;
$formatted = $fmt->format($time); $formatted = date('H:i', $time);
} else {
$type = static::DATE;
$formatted = date('M j H:i', $time);
}
} else { } else {
$type = static::RELATIVE; $type = static::RELATIVE;
$formatted = sprintf('%dd %dh', floor($hours / 24), $hours % 24); $formatted = sprintf('%dd %dh', floor($hours / 24), $hours % 24);
@ -88,8 +93,7 @@ class DateFormatter
*/ */
public static function formatDate($date) public static function formatDate($date)
{ {
$fmt = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::NONE); return date('Y-m-d', (float) $date);
return $fmt->format((float) $date);
} }
/** /**
@ -101,8 +105,7 @@ class DateFormatter
*/ */
public static function formatDateTime($dateTime) public static function formatDateTime($dateTime)
{ {
$fmt = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); return date('Y-m-d H:i:s', (float) $dateTime);
return $fmt->format((float) $dateTime);
} }
/** /**
@ -114,8 +117,7 @@ class DateFormatter
*/ */
public static function formatTime($time) public static function formatTime($time)
{ {
$fmt = new IntlDateFormatter(null, IntlDateFormatter::NONE, IntlDateFormatter::SHORT); return date('H:i:s', (float) $time);
return $fmt->format((float) $time);
} }
/** /**