Graphing cleanup (#14492)

* WIP

* Fixes and cleanups

* Move parseAtTime to Time util class

* lint fixes, explicitly define variables

* Style fixes
This commit is contained in:
Tony Murray
2022-10-28 08:06:29 -05:00
committed by GitHub
parent d5fcf53e01
commit 4b65dc41d2
16 changed files with 420 additions and 308 deletions

View File

@@ -27,6 +27,7 @@ namespace LibreNMS\Tests;
use LibreNMS\Device\YamlDiscovery;
use LibreNMS\Util\Rewrite;
use LibreNMS\Util\Time;
class FunctionsTest extends TestCase
{
@@ -102,20 +103,20 @@ class FunctionsTest extends TestCase
public function testParseAtTime()
{
$this->assertEquals(time(), parse_at_time('now'), 'now did not match');
$this->assertEquals(time() + 180, parse_at_time('+3m'), '+3m did not match');
$this->assertEquals(time() + 7200, parse_at_time('+2h'), '+2h did not match');
$this->assertEquals(time() + 172800, parse_at_time('+2d'), '+2d did not match');
$this->assertEquals(time() + 63115200, parse_at_time('+2y'), '+2y did not match');
$this->assertEquals(time() - 180, parse_at_time('-3m'), '-3m did not match');
$this->assertEquals(time() - 7200, parse_at_time('-2h'), '-2h did not match');
$this->assertEquals(time() - 172800, parse_at_time('-2d'), '-2d did not match');
$this->assertEquals(time() - 63115200, parse_at_time('-2y'), '-2y did not match');
$this->assertEquals(429929439, parse_at_time('429929439'));
$this->assertEquals(212334234, parse_at_time(212334234));
$this->assertEquals(time() - 43, parse_at_time('-43'), '-43 did not match');
$this->assertEquals(0, parse_at_time('invalid'));
$this->assertEquals(606614400, parse_at_time('March 23 1989 UTC'));
$this->assertEquals(time() + 86400, parse_at_time('+1 day'));
$this->assertEquals(time(), Time::parseAt('now'), 'now did not match');
$this->assertEquals(time() + 180, Time::parseAt('+3m'), '+3m did not match');
$this->assertEquals(time() + 7200, Time::parseAt('+2h'), '+2h did not match');
$this->assertEquals(time() + 172800, Time::parseAt('+2d'), '+2d did not match');
$this->assertEquals(time() + 63115200, Time::parseAt('+2y'), '+2y did not match');
$this->assertEquals(time() - 180, Time::parseAt('-3m'), '-3m did not match');
$this->assertEquals(time() - 7200, Time::parseAt('-2h'), '-2h did not match');
$this->assertEquals(time() - 172800, Time::parseAt('-2d'), '-2d did not match');
$this->assertEquals(time() - 63115200, Time::parseAt('-2y'), '-2y did not match');
$this->assertEquals(429929439, Time::parseAt('429929439'));
$this->assertEquals(212334234, Time::parseAt(212334234));
$this->assertEquals(time() - 43, Time::parseAt('-43'), '-43 did not match');
$this->assertEquals(0, Time::parseAt('invalid'));
$this->assertEquals(606614400, Time::parseAt('March 23 1989 UTC'));
$this->assertEquals(time() + 86400, Time::parseAt('+1 day'));
}
}