From 4dde0eaaf6c650e949ff047e2dc177938f352f4e Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 28 Feb 2016 13:55:16 +0100 Subject: [PATCH] IcingaConfigHelper: Icinga2 doesn't support 2m 30s --- library/Director/IcingaConfig/IcingaConfigHelper.php | 11 +++-------- .../Director/IcingaConfig/IcingaConfigHelperTest.php | 5 +++-- 2 files changed, 6 insertions(+), 10 deletions(-) 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'); } }