Skip to content

Commit 1a3c2f0

Browse files
committed
Update tests for normalized timezones in VCP dates
No longer normalizes timezone for non-VCP dates. Additional test and comments on each test.
1 parent befc781 commit 1a3c2f0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Mf2/Parser.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ function convertTimeFormat($time) {
244244
* @return string isolated, normalized TZ offset for implied TZ for other dt- properties
245245
*/
246246
function normalizeTimezoneOffset(&$dtValue) {
247-
preg_match('/Z|[+-]\d{1,2}:?(\d{2})?$/i', $dtValue, $matches);
247+
preg_match('/Z|[+-]\d{1,2}:?(\d{2})?$/i', $dtValue, $matches);
248248

249249
if (empty($matches)) {
250250
return null;
251251
}
252252

253-
$timezoneOffset = null;
253+
$timezoneOffset = null;
254254

255255
if ( $matches[0] != 'Z' ) {
256256
$timezoneString = str_replace(':', '', $matches[0]);

tests/Mf2/ParseDTTest.php

+18-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,11 @@ public function testDTStartDateOnly() {
260260
}
261261

262262
/**
263-
*
263+
* TZ offsets normalized only for VCP.
264+
* This behavior is implied from "However the colons ":" separating the hours and minutes of any timezone offset are optional and discouraged in order to make it less likely that a timezone offset will be confused for a time."
265+
* @see http://microformats.org/wiki/index.php?title=value-class-pattern&oldid=66473##However+the+colons
264266
*/
265-
public function testNormalizeTZOffset() {
267+
public function testNormalizeTZOffsetVCP() {
266268
$input = '<div class="h-event">
267269
<span class="dt-start"> <time class="value" datetime="2017-05-27">May 27</time>, from
268270
<time class="value">20:57-07:00</time> </span>
@@ -273,6 +275,19 @@ public function testNormalizeTZOffset() {
273275
$this->assertEquals('2017-05-27 20:57-0700', $output['items'][0]['properties']['start'][0]);
274276
}
275277

278+
279+
/**
280+
* TZ offsets *not* normalized for non-VCP dates
281+
*/
282+
public function testNoNormalizeTZOffset() {
283+
$input = '<div class="h-entry"> <time class="dt-start" datetime="2018-03-13 15:30-07:00">March 13, 2018 3:30PM</time> </div>';
284+
$parser = new Parser($input);
285+
$output = $parser->parse();
286+
287+
$this->assertEquals('2018-03-13 15:30-07:00', $output['items'][0]['properties']['start'][0]);
288+
}
289+
290+
276291
/**
277292
* @see https://github.com/indieweb/php-mf2/issues/115
278293
*/
@@ -297,7 +312,7 @@ public function testPreserrveTIfAuthored() {
297312
$parser = new Parser($input);
298313
$output = $parser->parse();
299314

300-
$this->assertEquals('2009-06-26T19:01-0800', $output['items'][0]['properties']['start'][0]);
315+
$this->assertEquals('2009-06-26T19:01-08:00', $output['items'][0]['properties']['start'][0]);
301316
}
302317

303318
/**

0 commit comments

Comments
 (0)