From 14b24ff57d09d0064b0dbfc8e490f77478ed3d75 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 13:26:46 +0200 Subject: [PATCH] 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 --- library/Icinga/Date/DateFormatter.php | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/library/Icinga/Date/DateFormatter.php b/library/Icinga/Date/DateFormatter.php index 4e7d2e15f..8ea8e2b3c 100644 --- a/library/Icinga/Date/DateFormatter.php +++ b/library/Icinga/Date/DateFormatter.php @@ -3,10 +3,8 @@ namespace Icinga\Date; -use IntlDateFormatter; - /** - * ICU date formatting + * Date formatting */ class DateFormatter { @@ -57,8 +55,11 @@ class DateFormatter } if ($diff > 3600 * 24 * 3) { $type = static::DATE; - $fmt = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::NONE); - $formatted = $fmt->format($time); + if (date('Y') === date('Y', $time)) { + $formatted = date('M j', $time); + } else { + $formatted = date('Y-m', $time); + } } else { $minutes = floor($diff / 60); if ($minutes < 60) { @@ -67,9 +68,13 @@ class DateFormatter } else { $hours = floor($minutes / 60); if ($hours < 24) { - $type = static::TIME; - $fmt = new IntlDateFormatter(null, IntlDateFormatter::NONE, IntlDateFormatter::SHORT); - $formatted = $fmt->format($time); + if (date('d') === date('d', $time)) { + $type = static::TIME; + $formatted = date('H:i', $time); + } else { + $type = static::DATE; + $formatted = date('M j H:i', $time); + } } else { $type = static::RELATIVE; $formatted = sprintf('%dd %dh', floor($hours / 24), $hours % 24); @@ -88,8 +93,7 @@ class DateFormatter */ public static function formatDate($date) { - $fmt = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::NONE); - return $fmt->format((float) $date); + return date('Y-m-d', (float) $date); } /** @@ -101,8 +105,7 @@ class DateFormatter */ public static function formatDateTime($dateTime) { - $fmt = new IntlDateFormatter(null, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT); - return $fmt->format((float) $dateTime); + return date('Y-m-d H:i:s', (float) $dateTime); } /** @@ -114,8 +117,7 @@ class DateFormatter */ public static function formatTime($time) { - $fmt = new IntlDateFormatter(null, IntlDateFormatter::NONE, IntlDateFormatter::SHORT); - return $fmt->format((float) $time); + return date('H:i:s', (float) $time); } /**