Upgrade to 3.8.0
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Kirby\Toolkit;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeInterface;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
@@ -32,7 +33,7 @@ class Date extends DateTime
|
||||
$datetime = date('r', $datetime);
|
||||
}
|
||||
|
||||
if (is_a($datetime, 'DateTimeInterface') === true) {
|
||||
if ($datetime instanceof DateTimeInterface) {
|
||||
$datetime = $datetime->format('r');
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ class Date extends DateTime
|
||||
* @param int|null $day
|
||||
* @return int
|
||||
*/
|
||||
public function day(?int $day = null): int
|
||||
public function day(int|null $day = null): int
|
||||
{
|
||||
if ($day === null) {
|
||||
return (int)$this->format('d');
|
||||
@@ -126,7 +127,7 @@ class Date extends DateTime
|
||||
* @param int|null $hour
|
||||
* @return int
|
||||
*/
|
||||
public function hour(?int $hour = null): int
|
||||
public function hour(int|null $hour = null): int
|
||||
{
|
||||
if ($hour === null) {
|
||||
return (int)$this->format('H');
|
||||
@@ -234,7 +235,7 @@ class Date extends DateTime
|
||||
* @param int|null $minute
|
||||
* @return int
|
||||
*/
|
||||
public function minute(?int $minute = null): int
|
||||
public function minute(int|null $minute = null): int
|
||||
{
|
||||
if ($minute === null) {
|
||||
return (int)$this->format('i');
|
||||
@@ -250,7 +251,7 @@ class Date extends DateTime
|
||||
* @param int|null $month
|
||||
* @return int
|
||||
*/
|
||||
public function month(?int $month = null): int
|
||||
public function month(int|null $month = null): int
|
||||
{
|
||||
if ($month === null) {
|
||||
return (int)$this->format('m');
|
||||
@@ -305,7 +306,7 @@ class Date extends DateTime
|
||||
* @param \DateTimeZone|null $timezone
|
||||
* @return static|null
|
||||
*/
|
||||
public static function optional(?string $datetime = null, ?DateTimeZone $timezone = null)
|
||||
public static function optional(string|null $datetime = null, ?DateTimeZone $timezone = null)
|
||||
{
|
||||
if (empty($datetime) === true) {
|
||||
return null;
|
||||
@@ -313,7 +314,7 @@ class Date extends DateTime
|
||||
|
||||
try {
|
||||
return new static($datetime, $timezone);
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +369,7 @@ class Date extends DateTime
|
||||
* @param int|array|null $step array of `unit` and `size` to round to nearest
|
||||
* @return int|null
|
||||
*/
|
||||
public static function roundedTimestamp(?string $date = null, $step = null): ?int
|
||||
public static function roundedTimestamp(string|null $date = null, $step = null): int|null
|
||||
{
|
||||
if ($date = static::optional($date)) {
|
||||
if ($step !== null) {
|
||||
@@ -391,7 +392,7 @@ class Date extends DateTime
|
||||
* @param int|null $second
|
||||
* @return int
|
||||
*/
|
||||
public function second(?int $second = null): int
|
||||
public function second(int|null $second = null): int
|
||||
{
|
||||
if ($second === null) {
|
||||
return (int)$this->format('s');
|
||||
@@ -421,7 +422,7 @@ class Date extends DateTime
|
||||
* @param array|null $default Default values to use if one or both values are not provided
|
||||
* @return array
|
||||
*/
|
||||
public static function stepConfig($input = null, ?array $default = null): array
|
||||
public static function stepConfig($input = null, array|null $default = null): array
|
||||
{
|
||||
$default ??= [
|
||||
'size' => 1,
|
||||
@@ -502,19 +503,12 @@ class Date extends DateTime
|
||||
*/
|
||||
public function toString(string $mode = 'datetime', bool $timezone = true): string
|
||||
{
|
||||
switch ($mode) {
|
||||
case 'date':
|
||||
$format = 'Y-m-d';
|
||||
break;
|
||||
case 'time':
|
||||
$format = 'H:i:s';
|
||||
break;
|
||||
case 'datetime':
|
||||
$format = 'Y-m-d H:i:s';
|
||||
break;
|
||||
default:
|
||||
throw new InvalidArgumentException('Invalid mode');
|
||||
}
|
||||
$format = match ($mode) {
|
||||
'date' => 'Y-m-d',
|
||||
'time' => 'H:i:s',
|
||||
'datetime' => 'Y-m-d H:i:s',
|
||||
default => throw new InvalidArgumentException('Invalid mode')
|
||||
};
|
||||
|
||||
if ($timezone === true) {
|
||||
$format .= 'P';
|
||||
@@ -529,7 +523,7 @@ class Date extends DateTime
|
||||
* @param int|null $year
|
||||
* @return int
|
||||
*/
|
||||
public function year(?int $year = null): int
|
||||
public function year(int|null $year = null): int
|
||||
{
|
||||
if ($year === null) {
|
||||
return (int)$this->format('Y');
|
||||
|
||||
Reference in New Issue
Block a user