1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39:
<?php
namespace Affilinet\ProductData\Responses;
trait DataParser
{
private static $datePattern = '/^\/Date\((\d{10})(\d{3})([+-]\d{4})\)\/$/';
private static $dateFormat = 'U.u.O';
private static $dateMask = '%2$s.%3$s.%4$s';
public static function parseDate($string)
{
$string = (string) $string;
$r = preg_match('/^\/Date\((\d{10})(\d{3})([+-]\d{4})\)\/$/', $string, $matches);
if (!$r) {
throw new \UnexpectedValueException('Preg Regex Pattern failed.');
}
$buffer = vsprintf(self::$dateMask, $matches);
$result = \DateTime::createFromFormat(self::$dateFormat, $buffer);
return $result;
}
}