Skip to content

Commit

Permalink
Merge e2ac6d5 into 454f742
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Aug 11, 2022
2 parents 454f742 + e2ac6d5 commit 86ef353
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ public static function isDisallowedFromTime(\DateTime $date, Config $config)
}
return false;
}

public static function isAllowed(Config $config)
{
return !self::isDisallowed($config);
}

public static function isAllowedFromTime(\DateTime $date, Config $config)
{
return !self::isDisallowedFromTime($date, $config);
}
}
17 changes: 15 additions & 2 deletions tests/src/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ public function testWholeDay()
{
$config = new Config();
$config->setConfig((object) [
'timeframe_disallowed' => '00:00-2359',
'timeframe_disallowed' => '00:00-23:59',
]);
self::assertTrue(Handler::isDisallowed($config));
self::assertFalse(Handler::isAllowed($config));
}

public function testOneMinute()
{
// I guess this test can fail one minute every day🤷.
$config = new Config();
$config->setConfig((object) [
'timeframe_disallowed' => '00:00-0001',
'timeframe_disallowed' => '00:00-00:01',
]);
self::assertFalse(Handler::isDisallowed($config));
}
Expand All @@ -49,4 +50,16 @@ public function testCrapTimezone()
]);
self::assertFalse(Handler::isDisallowed($config));
}

public function testFromTimeAllowed()
{
$config = new Config();
$timezone = new \DateTimeZone('+0200');
$date = new \DateTime('now', $timezone);
$date2 = new \DateTime('now', new \DateTimeZone('+0000'));
$config->setConfig((object) [
'timeframe_disallowed' => sprintf('%s-%s', $date2->modify('-1 hour')->format('H:i'), $date2->modify('+2 hour')->format('H:i')),
]);
self::assertTrue(Handler::isAllowedFromTime($date, $config));
}
}

0 comments on commit 86ef353

Please sign in to comment.