diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 4fa03cd..4d72f94 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -856,6 +856,7 @@ public function parseDT(\DOMElement $dt, &$dates = array(), &$impliedTimezone = $dtValue = unicodeTrim($dtValue); + // Store the date part so that we can use it when assembling the final timestamp if the next one is missing a date part if (preg_match('/(\d{4}-\d{2}-\d{2})/', $dtValue, $matches)) { $dates[] = $matches[0]; } @@ -1032,7 +1033,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('/(Z|[+-]\d{2}:?(\d{2})?)$/i', $dtValue, $matches) == 0 ) { $dtValue .= $impliedTimezone; } diff --git a/tests/Mf2/ParseDTTest.php b/tests/Mf2/ParseDTTest.php index 06e65fe..b3885c6 100644 --- a/tests/Mf2/ParseDTTest.php +++ b/tests/Mf2/ParseDTTest.php @@ -90,6 +90,42 @@ public function testParseDTHandlesTimeDatetimeAttr() { $this->assertEquals('2012-08-05T14:50', $output['items'][0]['properties']['start'][0]); } + /** + * @group parseDT + */ + public function testParseDTHandlesTimeDatetimeAttrWithZ() { + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('start', $output['items'][0]['properties']); + $this->assertEquals('2012-08-05T14:50:00Z', $output['items'][0]['properties']['start'][0]); + } + + /** + * @group parseDT + */ + public function testParseDTHandlesTimeDatetimeAttrWithTZOffset() { + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('start', $output['items'][0]['properties']); + $this->assertEquals('2012-08-05T14:50:00-0700', $output['items'][0]['properties']['start'][0]); + } + + /** + * @group parseDT + */ + public function testParseDTHandlesTimeDatetimeAttrWithTZOffset2() { + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('start', $output['items'][0]['properties']); + $this->assertEquals('2012-08-05T14:50:00-07:00', $output['items'][0]['properties']['start'][0]); + } + /** * @group parseDT */