Skip to content

Commit ec95de7

Browse files
authored
Merge pull request #148 from gRegorLove/issue147
Add test and fix for #147
2 parents cd2cf55 + 59a7eef commit ec95de7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Mf2/Parser.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,16 +760,20 @@ public function parseDT(\DOMElement $dt, &$dates = array(), &$impliedTimezone =
760760
if (!$impliedTimezone && $timezoneOffset) {
761761
$impliedTimezone = $timezoneOffset;
762762
}
763+
// Is the current part a valid date AND no other date representation has been found?
763764
} elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $part) and empty($datePart)) {
764-
// Is the current part a valid date AND no other date representation has been found?
765765
$datePart = $part;
766+
// Is the current part a valid timezone offset AND no other timezone part has been found?
766767
} elseif (preg_match('/^(Z|[+-]\d{1,2}:?(\d{2})?)$/', $part) and empty($timezonePart)) {
767768
$timezonePart = $part;
768769

769770
$timezoneOffset = normalizeTimezoneOffset($timezonePart);
770771
if (!$impliedTimezone && $timezoneOffset) {
771772
$impliedTimezone = $timezoneOffset;
772773
}
774+
// Current part already represented by other VCP parts; do nothing with it
775+
} else {
776+
continue;
773777
}
774778

775779
if ( !empty($datePart) && !in_array($datePart, $dates) ) {

tests/Mf2/ParseDTTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,32 @@ public function testDtVCPTimeAndTimezone() {
442442
$this->assertEquals('2017-06-17 15:30-0700', $output['items'][0]['properties']['end'][0]);
443443
}
444444

445+
/**
446+
* @see https://github.com/indieweb/php-mf2/issues/147
447+
*/
448+
public function testDtVCPMultipleDatesAndTimezones() {
449+
$input = '<div class="h-event">
450+
<h1 class="p-name">Multiple date and time values</h1>
451+
452+
<p> When:
453+
<span class="dt-start">
454+
<span class="value" title="June 1, 2014">2014-06-01</span>
455+
<span class="value" title="June 1, 3014">3014-06-01</span>
456+
<span class="value" title="12:30">12:30</span>
457+
(UTC<span class="value">-06:00</span>)
458+
<span class="value" title="23:00">23:00</span>
459+
(UTC<span class="value">+01:00</span>)
460+
461+
<span class="dt-end">19:30</span>
462+
</p>
463+
464+
</div>';
465+
$parser = new Parser($input);
466+
$output = $parser->parse();
467+
468+
$this->assertEquals('2014-06-01 12:30-0600', $output['items'][0]['properties']['start'][0]);
469+
$this->assertEquals('2014-06-01 19:30-0600', $output['items'][0]['properties']['end'][0]);
470+
}
471+
445472
}
473+

0 commit comments

Comments
 (0)