Skip to content

Commit cfb637c

Browse files
committed
Add getDateTime and findDateTime
1 parent 92c8b46 commit cfb637c

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
operating-system: [ ubuntu-latest ]
11-
php-versions: [ '8.2', '8.3', '8.4', '8.5' ]
11+
php-versions: [ '8.4', '8.5' ]
1212
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1313

1414
steps:

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A strictly typed array reader for PHP.
99

1010
## Requirements
1111

12-
* PHP 8.2 - 8.5
12+
* PHP 8.4 - 8.5
1313

1414
## Installation
1515

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"homepage": "https://github.com/selective-php/array-reader",
1515
"require": {
16-
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0"
16+
"php": "~8.4.0 || ~8.5.0"
1717
},
1818
"require-dev": {
1919
"cakephp/chronos": "^2 || ^3",

‎src/ArrayReader.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ private function toDateTimeImmutable(string $key, mixed $value): DateTimeImmutab
440440
return DateTimeImmutable::createFromInterface($value);
441441
}
442442

443-
if (is_int($value)) {
444-
return new DateTimeImmutable('@' . $value);
443+
if (is_int($value) || (is_float($value) && is_finite($value))) {
444+
return DateTimeImmutable::createFromTimestamp($value);
445445
}
446446

447447
if (!is_string($value)) {

‎tests/ArrayReaderTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,15 @@ public function testGetDateTime($data, string $key, $default, $expected): void
460460
public static function providerGetDateTime(): array
461461
{
462462
$date = new DateTimeImmutable('2020-01-02T03:04:05+00:00');
463+
$fraction = new DateTimeImmutable('2020-01-02T03:04:05.500000+00:00');
463464
$chronos = new Chronos('2020-01-02T03:04:05+00:00');
464465

465466
return [
466467
[['created' => '2020-01-02T03:04:05+00:00'], 'created', null, $date],
467468
[['created' => $date], 'created', null, $date],
468469
[['created' => new DateTime('2020-01-02T03:04:05+00:00')], 'created', null, $date],
469470
[['created' => 1577934245], 'created', null, $date],
471+
[['created' => 1577934245.5], 'created', null, $fraction],
470472
[['user' => ['created' => '2020-01-02T03:04:05+00:00']], 'user.created', null, $date],
471473
[['created' => $chronos], 'created', null, $chronos],
472474
[[], 'missing', $date, $date],
@@ -505,6 +507,8 @@ public static function providerGetDateTimeError(): array
505507
[['created' => ''], 'created', null],
506508
[[], 'missing', null],
507509
[['created' => ['not-a-date']], 'created', null],
510+
[['created' => INF], 'created', null],
511+
[['created' => NAN], 'created', null],
508512
[['user' => ['created' => null]], 'user.created', null],
509513
];
510514
}

0 commit comments

Comments
 (0)