IcingaConfigHelper: Icinga2 doesn't support 2m 30s

This commit is contained in:
Thomas Gelf 2016-02-28 13:55:16 +01:00
parent a5013cd052
commit 4dde0eaaf6
2 changed files with 6 additions and 10 deletions

View File

@ -218,16 +218,11 @@ class IcingaConfigHelper
);
foreach ($steps as $unit => $duration) {
if ($seconds >= $duration) {
$parts[] = (int) floor($seconds / $duration) . $unit;
$seconds = $seconds % $duration;
if ($seconds % $duration === 0) {
return (int) floor($seconds / $duration) . $unit;
}
}
if ($seconds > 0) {
$parts[] = $seconds . 's';
}
return implode(' ', $parts);
return $seconds . 's';
}
}

View File

@ -28,8 +28,9 @@ class IcingaConfigHelperTest extends BaseTestCase
{
$this->assertEquals(c::renderInterval(10), '10s');
$this->assertEquals(c::renderInterval(60), '1m');
$this->assertEquals(c::renderInterval(121), '2m 1s');
$this->assertEquals(c::renderInterval(121), '121s');
$this->assertEquals(c::renderInterval(3600), '1h');
$this->assertEquals(c::renderInterval(86400), '1d');
$this->assertEquals(c::renderInterval(86459), '1d 59s');
$this->assertEquals(c::renderInterval(86459), '86459s');
}
}