Skip to content

Commit

Permalink
Merge pull request microformats#148 from gRegorLove/issue147
Browse files Browse the repository at this point in the history
Add test and fix for microformats#147
  • Loading branch information
aaronpk committed Mar 11, 2018
2 parents cd2cf55 + 59a7eef commit ec95de7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Mf2/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -760,16 +760,20 @@ public function parseDT(\DOMElement $dt, &$dates = array(), &$impliedTimezone =
if (!$impliedTimezone && $timezoneOffset) {
$impliedTimezone = $timezoneOffset;
}
// Is the current part a valid date AND no other date representation has been found?
} elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $part) and empty($datePart)) {
// Is the current part a valid date AND no other date representation has been found?
$datePart = $part;
// Is the current part a valid timezone offset AND no other timezone part has been found?
} elseif (preg_match('/^(Z|[+-]\d{1,2}:?(\d{2})?)$/', $part) and empty($timezonePart)) {
$timezonePart = $part;

$timezoneOffset = normalizeTimezoneOffset($timezonePart);
if (!$impliedTimezone && $timezoneOffset) {
$impliedTimezone = $timezoneOffset;
}
// Current part already represented by other VCP parts; do nothing with it
} else {
continue;
}

if ( !empty($datePart) && !in_array($datePart, $dates) ) {
Expand Down
28 changes: 28 additions & 0 deletions tests/Mf2/ParseDTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,32 @@ public function testDtVCPTimeAndTimezone() {
$this->assertEquals('2017-06-17 15:30-0700', $output['items'][0]['properties']['end'][0]);
}

/**
* @see https://github.com/indieweb/php-mf2/issues/147
*/
public function testDtVCPMultipleDatesAndTimezones() {
$input = '<div class="h-event">
<h1 class="p-name">Multiple date and time values</h1>
<p> When:
<span class="dt-start">
<span class="value" title="June 1, 2014">2014-06-01</span>
<span class="value" title="June 1, 3014">3014-06-01</span>
<span class="value" title="12:30">12:30</span>
(UTC<span class="value">-06:00</span>)
<span class="value" title="23:00">23:00</span>
(UTC<span class="value">+01:00</span>)
<span class="dt-end">19:30</span>
</p>
</div>';
$parser = new Parser($input);
$output = $parser->parse();

$this->assertEquals('2014-06-01 12:30-0600', $output['items'][0]['properties']['start'][0]);
$this->assertEquals('2014-06-01 19:30-0600', $output['items'][0]['properties']['end'][0]);
}

}

0 comments on commit ec95de7

Please sign in to comment.