Skip to content

Commit 583927d

Browse files
committed
Merge branch 'develop'
* develop: specify next release fix ci for php 8.4 bump minimum version of static analysis bump the minimum version of innmind/immutable fix access to old format fix using fixtures depending on the version used handle the case where the input string is empty add support for time-continuum 4
2 parents cc94c43 + 7d2f1eb commit 583927d

File tree

5 files changed

+76
-15
lines changed

5 files changed

+76
-15
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.9.0 - 2025-02-09
4+
5+
### Added
6+
7+
- Support for `innmind/time-continuum` `4`
8+
39
## 1.8.0 - 2025-02-09
410

511
### Added

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
},
1717
"require": {
1818
"php": "~8.2",
19-
"innmind/immutable": "~5.3",
20-
"innmind/time-continuum": "~3.4"
19+
"innmind/immutable": "~5.10",
20+
"innmind/time-continuum": "~3.4|^4.0.2"
2121
},
2222
"autoload": {
2323
"psr-4": {
2424
"Innmind\\Validation\\": "src/"
2525
}
2626
},
2727
"require-dev": {
28-
"innmind/static-analysis": "~1.1",
28+
"innmind/static-analysis": "^1.2.1",
2929
"innmind/black-box": "~5.5",
3030
"innmind/coding-standard": "~2.0"
3131
}

docs/constraints/dates.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ This will transform `string`s into `PointInTime`s from the [`innmind/time-contin
44

55
```php
66
use Innmind\Validation\PointInTime;
7-
use Innmind\TimeContinuum\Earth\{
7+
use Innmind\TimeContinuum\{
88
Clock,
9-
Format\ISO8601,
9+
Format,
1010
};
1111

1212
$validate = PointInTime::ofFormat(
13-
new Clock,
14-
new ISO8601,
13+
Clock::live(),
14+
Format::iso8601(),
1515
);
1616
```
1717

proofs/pointInTime.php

+57-8
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,38 @@
22
declare(strict_types = 1);
33

44
use Innmind\Validation\PointInTime;
5-
use Innmind\TimeContinuum\Earth\{
5+
use Innmind\TimeContinuum\{
6+
Earth,
7+
Earth\Format\ISO8601,
68
Clock,
7-
Format\ISO8601,
9+
Format,
810
};
911
use Innmind\BlackBox\Set;
10-
use Fixtures\Innmind\TimeContinuum\Earth\PointInTime as FPointInTime;
12+
use Fixtures\Innmind\TimeContinuum\{
13+
PointInTime as FPointInTime,
14+
Earth as FEarth,
15+
};
1116

1217
return static function() {
1318
yield proof(
1419
'PointInTime::ofFormat()',
1520
given(
16-
FPointInTime::any(),
21+
match (true) {
22+
\class_exists(FEarth\PointInTime::class) => FEarth\PointInTime::any(),
23+
default => FPointInTime::any(),
24+
},
1725
Set\Strings::any(),
1826
),
1927
static function($assert, $point, $random) {
20-
$format = new ISO8601;
28+
$format = match (true) {
29+
\class_exists(ISO8601::class) => new ISO8601,
30+
default => Format::of('Y-m-d\TH:i:s.uP'), // to support microseconds
31+
};
2132
$string = $point->format($format);
22-
$clock = new Clock;
33+
$clock = match (true) {
34+
\class_exists(Earth\Clock::class) => new Earth\Clock,
35+
default => Clock::live(),
36+
};
2337

2438
$assert->true(
2539
PointInTime::ofFormat($clock, $format)->asPredicate()($string),
@@ -58,8 +72,14 @@ static function($assert, $point, $random) {
5872
Set\Strings::any(),
5973
),
6074
static function($assert, $expected, $random) {
61-
$format = new ISO8601;
62-
$clock = new Clock;
75+
$format = match (true) {
76+
\class_exists(ISO8601::class) => new ISO8601,
77+
default => Format::iso8601(),
78+
};
79+
$clock = match (true) {
80+
\class_exists(Earth\Clock::class) => new Earth\Clock,
81+
default => Clock::live(),
82+
};
6383

6484
[[$path, $message]] = PointInTime::ofFormat($clock, $format)->withFailure($expected)($random)->match(
6585
static fn() => null,
@@ -73,4 +93,33 @@ static function($assert, $expected, $random) {
7393
$assert->same($expected, $message);
7494
},
7595
);
96+
97+
yield test(
98+
'PointInTime::ofFormat() with empty string fails',
99+
static function($assert) {
100+
$format = match (true) {
101+
\class_exists(ISO8601::class) => new ISO8601,
102+
default => Format::iso8601(),
103+
};
104+
$clock = match (true) {
105+
\class_exists(Earth\Clock::class) => new Earth\Clock,
106+
default => Clock::live(),
107+
};
108+
109+
[[$path, $message]] = PointInTime::ofFormat($clock, $format)('')->match(
110+
static fn() => null,
111+
static fn($failures) => $failures
112+
->map(static fn($failure) => [
113+
$failure->path()->toString(),
114+
$failure->message(),
115+
])
116+
->toList(),
117+
);
118+
$assert->same('$', $path);
119+
$assert
120+
->string($message)
121+
->startsWith('Value is not a date of format ')
122+
->endsWith($format->toString());
123+
},
124+
);
76125
};

src/PointInTime.php

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ private function __construct(
3939

4040
public function __invoke(mixed $value): Validation
4141
{
42+
if ($value === '') {
43+
return Validation::fail(Failure::of(
44+
$this->message ?? "Value is not a date of format {$this->format->toString()}",
45+
));
46+
}
47+
4248
return $this->clock->at($value, $this->format)->match(
4349
static fn($point) => Validation::success($point),
4450
fn() => Validation::fail(Failure::of(

0 commit comments

Comments
 (0)