Skip to content

Commit d50b485

Browse files
committed
add Arrays::castValueToType() and DateTimeComparator
1 parent feadc89 commit d50b485

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Arrays.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ public static function firstValue(array $array)
4949
return $array[$key];
5050
}
5151

52+
/**
53+
* @param mixed[] $values
54+
* @return mixed[]
55+
*/
56+
public static function castValueToType(array $values, string $type): array
57+
{
58+
return array_map(function ($value) use ($type) {
59+
settype($value, $type);
60+
61+
return $value;
62+
}, $values);
63+
}
64+
5265
/**
5366
* @param mixed[] $previous
5467
* @param mixed[] $current

src/DateTimeComparator.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Utilitte\Php;
4+
5+
use DateTime;
6+
7+
final class DateTimeComparator
8+
{
9+
10+
private DateTime $dateTime;
11+
12+
public function __construct(DateTime $dateTime)
13+
{
14+
$this->dateTime = $dateTime;
15+
}
16+
17+
public function isSameDate(DateTime $dateTime): bool
18+
{
19+
return $this->dateTime->format('Y-m-d') === $dateTime->format('Y-m-d');
20+
}
21+
22+
}

0 commit comments

Comments
 (0)