Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
}

Expand Down
36 changes: 36 additions & 0 deletions tests/Mf2/ParseDTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="h-card"><time class="dt-start" datetime="2012-08-05T14:50:00Z"></div>';
$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 = '<div class="h-card"><time class="dt-start" datetime="2012-08-05T14:50:00-0700"></div>';
$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 = '<div class="h-card"><time class="dt-start" datetime="2012-08-05T14:50:00-07:00"></div>';
$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
*/
Expand Down