Skip to content

Commit

Permalink
also allow Y-m-d\TH:i:s.v timeformat
Browse files Browse the repository at this point in the history
  • Loading branch information
mathielen committed Nov 13, 2024
1 parent 865e263 commit 91187ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/CXml/Jms/JmsDateTimeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ public function deserialize(XmlDeserializationVisitor $visitor, SimpleXMLElement
return $dateTime;
}

// else try milliseconds-format
// else try milliseconds-format with Timezone
$dateTime = DateTime::createFromFormat('Y-m-d\TH:i:s.vP', $dateAsString->__toString());
if ($dateTime instanceof DateTimeInterface) {
return $dateTime;
}

// else try milliseconds-format without Timezone
$dateTime = DateTime::createFromFormat('Y-m-d\TH:i:s.v', $dateAsString->__toString());
if ($dateTime instanceof DateTimeInterface) {
return $dateTime;
}

// else try simple date-format
$dateTime = Date::createFromFormat('Y-m-d', $dateAsString->__toString());
if ($dateTime instanceof DateTimeInterface) {
Expand Down
19 changes: 17 additions & 2 deletions tests/CXmlTest/Model/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function testDeserialize(): void
* even though the cXML definition defines the timestamp value to be in ISO-8601 format there are some providers that
* also uses the milliseconds value (i.e. JAGGAER).
*/
public function testDeserializeWithMilliseconds(): void
public function testDeserializeWithMillisecondsAndTimezone(): void
{
$xmlIn =
'<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -239,7 +239,6 @@ public function testDeserializeWithMilliseconds(): void
$cXml = $serializer->deserialize($xmlIn);

$actual = $serializer->serialize($cXml);

$xmlOut =
'<?xml version="1.0" encoding="UTF-8"?>
<cXML timestamp="2022-06-07T10:09:56+00:00" payloadID="x.y.z">
Expand All @@ -250,6 +249,22 @@ public function testDeserializeWithMilliseconds(): void
$this->assertXmlStringEqualsXmlString($xmlOut, $actual);
}

public function testDeserializeWithMillisecondsNoTimezone(): void
{
$xmlIn =
'<?xml version="1.0" encoding="UTF-8"?>
<cXML timestamp="2022-06-07T10:09:56.728" payloadID="x.y.z">
<Response>
<Status code="200" text="OK">Ping Response CXml</Status>
</Response>
</cXML>';

$serializer = Serializer::create();
$cXml = $serializer->deserialize($xmlIn);

$this->assertSame('2022-06-07T10:09:56+00:00', $cXml->getTimestamp()->format('c'));
}

public function testDeserializeWithDateTimeForDate(): void
{
$xmlIn =
Expand Down

0 comments on commit 91187ad

Please sign in to comment.