@@ -30,30 +30,25 @@ public function match(mixed $value, DataCollection $collection, InputValueContex
30
30
return is_string ($ value ) || is_numeric ($ value );
31
31
}
32
32
33
-
34
-
35
33
/**
36
34
* @throws DateInvalidTimeZoneException
37
35
*/
38
36
public function resolve (mixed $ value , DataCollection $ collection , InputValueContext $ context ): string |DateTime
39
37
{
40
- $ timezone = $ this ->timezone ? new DateTimeZone ($ this ->timezone ) : null ;
41
- $ types = $ collection ->getTypes ();
42
- if (!$ types || count ($ types ) !== 1 ) {
43
- $ dateTime = DateTime::createFromFormat ($ this ->inputFormat , (string )$ value , $ timezone );
44
- return $ dateTime !== false ? $ dateTime ->format ($ this ->outFormat ) : (string )$ value ;
45
- }
46
38
47
- $ className = current ($ types )->className ;
39
+ $ timezone = $ this ->timezone ? new DateTimeZone ($ this ->timezone ) : null ;
40
+ $ className = current ($ collection ->getTypes ())->className ;
48
41
49
42
if (!$ this ->outFormat
50
- && in_array ($ className , [DateTime ::class, DateTimeImmutable::class], true )
43
+ && is_subclass_of ($ className , DateTimeInterface ::class)
51
44
&& method_exists ($ className , 'createFromFormat ' )
45
+ && count ($ collection ->getTypes ()) === 1
52
46
) {
53
47
return $ className ::createFromFormat ($ this ->inputFormat , (string )$ value , $ timezone );
54
48
}
55
49
56
50
$ dateTime = DateTime::createFromFormat ($ this ->inputFormat , (string )$ value , $ timezone );
57
51
return $ dateTime !== false ? $ dateTime ->format ($ this ->outFormat ) : (string )$ value ;
52
+
58
53
}
59
54
}
0 commit comments