diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 5832191..340043e 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -845,11 +845,12 @@ public function parseDT(\DOMElement $dt, &$dates = array(), &$impliedTimezone = $dtValue = $this->textContent($dt); } - // if the dtValue is not just YYYY-MM-DD, normalize the timezone offset + // if the dtValue is not just YYYY-MM-DD if (!preg_match('/^(\d{4}-\d{2}-\d{2})$/', $dtValue)) { - $timezoneOffset = normalizeTimezoneOffset($dtValue); - if (!$impliedTimezone && $timezoneOffset) { - $impliedTimezone = $timezoneOffset; + // no implied timezone set and dtValue has a TZ offset, use un-normalized TZ offset + preg_match('/Z|[+-]\d{1,2}:?(\d{2})?$/i', $dtValue, $matches); + if (!$impliedTimezone && !empty($matches[0])) { + $impliedTimezone = $matches[0]; } } @@ -1031,7 +1032,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf = foreach ($temp_dates as $propName => $data) { foreach ( $data as $dtValue ) { // var_dump(preg_match('/[+-]\d{2}(\d{2})?$/i', $dtValue)); - if ( $impliedTimezone && preg_match('/[+-]\d{2}(\d{2})?$/i', $dtValue, $matches) == 0 ) { + if ( $impliedTimezone && preg_match('/[+-]\d{2}:?(\d{2})?$/i', $dtValue, $matches) == 0 ) { $dtValue .= $impliedTimezone; } diff --git a/tests/Mf2/ParseDTTest.php b/tests/Mf2/ParseDTTest.php index 7f7a78d..2822191 100644 --- a/tests/Mf2/ParseDTTest.php +++ b/tests/Mf2/ParseDTTest.php @@ -469,5 +469,16 @@ public function testDtVCPMultipleDatesAndTimezones() { $this->assertEquals('2014-06-01 19:30-0600', $output['items'][0]['properties']['end'][0]); } + /** + * @see https://github.com/indieweb/php-mf2/issues/149 + */ + public function testDtWithoutYear() { + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertEquals('--12-28', $output['items'][0]['properties']['bday'][0]); + } + }