Fatal Error on unexpected datetime format
Created by: alexschwarz89
The __construct of a DateTime object fails, if the input format is just a year like "2013" in this example.
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (2013--T) at position 4 (-): Unexpected character in /Users/alexs/Work/onixtest/vendor/ribal/onix/src/Date.php:124
Stack trace:
#0 /Users/alexs/Work/onixtest/vendor/ribal/onix/src/Date.php(124): DateTime->__construct('2013--T')
#1 /Users/alexs/Work/onixtest/vendor/ribal/onix/src/Date.php(144): Ribal\Onix\Date->parseDate('2013')
#2 /Users/alexs/Work/onixtest/vendor/ribal/onix/src/Normalizer/DateNormalizer.php(22): Ribal\Onix\Date::parse('2013', '00')
#3 /Users/alexs/Work/onixtest/vendor/symfony/serializer/Serializer.php(196): Ribal\Onix\Normalizer\DateNormalizer->denormalize('2013', 'Ribal\\Onix\\Date', 'xml', Array)
#4 /Users/alexs/Work/onixtest/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(477): Symfony\Component\Serializer\Serializer->denormalize('2013', 'Ribal\\Onix\\Date', 'xml', Array)
#5 /Users/alexs/Work/onixtest/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(364): Symfony\Component\Serialize in /Users/alexs/Work/onixtest/vendor/ribal/onix/src/Date.php on line 124
It's caused by following data inside a ONIX file:
<publishingdetail>
<publishingdate><x448>11</x448><j260>05</j260><b306>2013</b306></publishingdate>
<publishingdate><x448>01</x448><j260>00</j260><b306>20131001</b306></publishingdate>
</publishingdetail>
If i add a try…catch block around the __construct, the ONIX file can be parsed without problems. I believe the correct solution is the need of parsing the date differently, inside those cryptic onix elements i think it should be 11.05.2013