diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 0e52b4ce..5f11eb31 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -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'; } } diff --git a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php index 9e05a694..5055a7e6 100644 --- a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php +++ b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php @@ -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'); } }