Formatter should fail for invalid data

This commit is contained in:
Thomas Gelf 2014-02-21 10:29:27 +00:00
parent 859d964d6b
commit a79df3943a
1 changed files with 5 additions and 0 deletions

View File

@ -29,6 +29,8 @@
namespace Icinga\Util;
use Icinga\Exception\ProgrammingError;
class Format
{
const STANDARD_IEC = 0;
@ -99,6 +101,9 @@ class Format
if (! $timestamp) {
return '-';
}
if (! preg_match('~^\d+$~', $timestamp)) {
throw new ProgrammingError(sprintf('"%s" is not a number', $timestamp));
}
$duration = time() - $timestamp;
$prefix = '';
if ($duration < 0) {