Skip to content

Commit

Permalink
Fix dropped dependency on nette/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
foxycode committed Oct 8, 2022
1 parent ea517d8 commit 6009602
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/DateIntervalFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DateTimeInterface;
use InvalidArgumentException;
use Nette\Utils\ArrayHash;
use stdClass;

final class DateIntervalFactory
{
Expand All @@ -20,7 +20,7 @@ final class DateIntervalFactory
*
* @param array<string, mixed>|null $items
*
* @return ArrayHash[]
* @return stdClass[]
*/
public static function create(
DateTimeInterface $dateFrom,
Expand All @@ -34,7 +34,7 @@ public static function create(
$result = [];
while ($currentDate <= $dateTo) {
$intervalKey = self::getIntervalKey($currentDate, $interval);
$result[$intervalKey] = new ArrayHash;
$result[$intervalKey] = new stdClass;
$result[$intervalKey]->date = $currentDate;

if ($items) {
Expand Down
10 changes: 5 additions & 5 deletions src/SpentTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Sunfox\DateUtils;

use InvalidArgumentException;
use Nette\Utils\Strings;

class SpentTime
{
Expand All @@ -28,7 +27,8 @@ public function __construct(?string $time = null)
return;
}

if (!$match = Strings::match($time, '~^([0-9]{2}):([0-9]{2}):([0-9]{2})$~')) {
preg_match('~^([0-9]{2}):([0-9]{2}):([0-9]{2})$~', $time, $match);
if (!$match) {
throw new InvalidArgumentException("Bad time format: '{$time}'.");
}

Expand All @@ -39,9 +39,9 @@ public function __construct(?string $time = null)

public function __toString(): string
{
return Strings::padLeft((string) $this->hours, 2, '0') . ':' .
Strings::padLeft((string) $this->minutes, 2, '0') . ':' .
Strings::padLeft((string) $this->seconds, 2, '0');
return str_pad((string) $this->hours, 2, '0', STR_PAD_LEFT) . ':' .
str_pad((string) $this->minutes, 2, '0', STR_PAD_LEFT) . ':' .
str_pad((string) $this->seconds, 2, '0', STR_PAD_LEFT);
}

public function isZero(): bool
Expand Down
6 changes: 3 additions & 3 deletions tests/Cases/DateIntervalFactoryTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SunfoxTests\DateUtils\Cases;

use DateTime as NativeDateTime;
use InvalidArgumentException;
use Nette\Utils\ArrayHash;
use stdClass;
use Sunfox\DateUtils\DateIntervalFactory;
use Sunfox\DateUtils\DateTime;
use Tester;
Expand Down Expand Up @@ -43,7 +43,7 @@ final class DateIntervalFactoryTest extends Tester\TestCase

$array = DateIntervalFactory::create($start, $end, $interval, $count, $items);

$expected = new ArrayHash;
$expected = new stdClass;
$expected->date = new DateTime($expectedDate);

if ($items) {
Expand All @@ -53,7 +53,7 @@ final class DateIntervalFactoryTest extends Tester\TestCase
}

Assert::type('array', $array);
Assert::type('Nette\Utils\ArrayHash', $array[$intervalKey]);
Assert::type('stdClass', $array[$intervalKey]);
Assert::type(DateTime::class, $array[$intervalKey]->date);
Assert::equal($expected, $array[$intervalKey]);
Assert::count($expectedCount, $array);
Expand Down

0 comments on commit 6009602

Please sign in to comment.