Skip to content

Commit

Permalink
Add test and fix for microformats#149
Browse files Browse the repository at this point in the history
  • Loading branch information
gRegorLove committed Mar 13, 2018
1 parent acd29b8 commit befc781
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Mf2/ParseDTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div class="h-card"> <time class="dt-bday" datetime="--12-28"></time> </div>';
$parser = new Parser($input);
$output = $parser->parse();

$this->assertEquals('--12-28', $output['items'][0]['properties']['bday'][0]);
}

}

0 comments on commit befc781

Please sign in to comment.