@@ -114,14 +114,20 @@ private static function convertValueObject(array|int|float|string|bool $value, s
114114 protected static function convertDateTime (array |float |bool |int |string $ value , ?\ReflectionParameter $ reflectionParameter = null ): \DateTime
115115 {
116116 $ propertyAttribute = $ reflectionParameter ? StringProperty::tryFromReflectionParameter ($ reflectionParameter ) : null ;
117- $ format = match ($ propertyAttribute ?->format) {
118- StringProperty::FORMAT_DATE => 'Y-m-d ' ,
119- default => \DateTimeInterface::RFC3339
120- };
121- $ converted = match (true ) {
122- is_string ($ value ) => \DateTime::createFromFormat ($ format , $ value ),
123- default => false ,
117+ $ formats = match ($ propertyAttribute ?->format) {
118+ StringProperty::FORMAT_DATE => ['Y-m-d ' ],
119+ default => [\DateTimeInterface::RFC3339 , \DateTimeInterface::RFC3339_EXTENDED ]
124120 };
121+ if (is_string ($ value )) {
122+ foreach ($ formats as $ format ) {
123+ $ converted = \DateTime::createFromFormat ($ format , $ value );
124+ if ($ converted instanceof \DateTime) {
125+ break ;
126+ }
127+ }
128+ } else {
129+ $ converted = false ;
130+ }
125131 if ($ converted === false ) {
126132 throw new \DomainException ('Can only denormalize \DateTime from an RFC 3339 string ' );
127133 }
@@ -137,14 +143,20 @@ protected static function convertDateTime(array|float|bool|int|string $value, ?\
137143 protected static function convertDateTimeImmutable (array |float |bool |int |string $ value , ?\ReflectionParameter $ reflectionParameter = null ): \DateTimeImmutable
138144 {
139145 $ propertyAttribute = $ reflectionParameter ? StringProperty::tryFromReflectionParameter ($ reflectionParameter ) : null ;
140- $ format = match ($ propertyAttribute ?->format) {
141- StringProperty::FORMAT_DATE => 'Y-m-d ' ,
142- default => \DateTimeInterface::RFC3339
143- };
144- $ converted = match (true ) {
145- is_string ($ value ) => \DateTimeImmutable::createFromFormat ($ format , $ value ),
146- default => false ,
146+ $ formats = match ($ propertyAttribute ?->format) {
147+ StringProperty::FORMAT_DATE => ['Y-m-d ' ],
148+ default => [\DateTimeInterface::RFC3339 , \DateTimeInterface::RFC3339_EXTENDED ]
147149 };
150+ if (is_string ($ value )) {
151+ foreach ($ formats as $ format ) {
152+ $ converted = \DateTimeImmutable::createFromFormat ($ format , $ value );
153+ if ($ converted instanceof \DateTimeImmutable) {
154+ break ;
155+ }
156+ }
157+ } else {
158+ $ converted = false ;
159+ }
148160 if ($ converted === false ) {
149161 throw new \DomainException ('Can only denormalize \DateTimeImmutable from an RFC 3339 string ' );
150162 }
0 commit comments