Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/222119
Change subject: Do not trim the T in TimeDetailsFormatter ...................................................................... Do not trim the T in TimeDetailsFormatter I did that in I27861d4. I think I was wrong. Originally the idea of the timezone was similar to the calendar: the timestamp string is *always* Gregorian and *always* UTC (Z). The calendar option was meant as a formatter hint. Same for the timezone option. We are changing the meaning of the calendar option now. I think we will do the same with the timezone option. I suggest to show the timestamp string as it is (including the Z) no matter what. This makes this more transparent/visible. Change-Id: Id453e9e9f57a3bfa246b83aa1dd17e42017c2313 --- M lib/includes/formatters/TimeDetailsFormatter.php M lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php 2 files changed, 11 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/19/222119/1 diff --git a/lib/includes/formatters/TimeDetailsFormatter.php b/lib/includes/formatters/TimeDetailsFormatter.php index 6aba78d..6f051cc 100644 --- a/lib/includes/formatters/TimeDetailsFormatter.php +++ b/lib/includes/formatters/TimeDetailsFormatter.php @@ -106,17 +106,19 @@ * @return string HTML */ private function getTimestampHtml( $timestamp ) { - // Loose check if the ISO-like string contains at least year, month, day and hour. - if ( !preg_match( '/^([-+]?)(\d+)(-\d+-\d+T\d+(?::\d+)*)Z?$/i', $timestamp, $matches ) ) { + // Loose check if the ISO-like string contains at least year, month, day and the T. + if ( !preg_match( '/^([-+]?)(\d+)(-\d+-\d+T.*)/', $timestamp, $matches ) ) { return htmlspecialchars( $timestamp ); } + list( , $sign, $year, $rest ) = $matches; + // Actual MINUS SIGN (U+2212) instead of HYPHEN-MINUS (U+002D) - $sign = $matches[1] === '-' ? "\xE2\x88\x92" : '+'; + $sign = $sign === '-' ? "\xE2\x88\x92" : '+'; // Warning, never cast the year to integer to not run into 32-bit integer overflows! - $year = ltrim( $matches[2], '0' ); + $year = ltrim( $year, '0' ); // Keep the sign. Pad the year. Keep month, day, and time. Drop the trailing "Z". - return htmlspecialchars( $sign . str_pad( $year, 4, '0', STR_PAD_LEFT ) . $matches[3] ); + return htmlspecialchars( $sign . str_pad( $year, 4, '0', STR_PAD_LEFT ) . $rest ); } /** diff --git a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php index 1e8ebc2..5dc1ede 100644 --- a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php +++ b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php @@ -110,7 +110,7 @@ '@' . implode( '.*', array( '<h4[^<>]*><a>HTML</a></h4>', - '<td[^<>]*>\+0*2001-01-01T00:00:00</td>', + '<td[^<>]*>\+0*2001-01-01T00:00:00Z</td>', '<td[^<>]*>\+01:00</td>', '<td[^<>]*>\(valueview-expert-timevalue-calendar-gregorian\)</td>', '<td[^<>]*>\(months: 1\)</td>', @@ -121,11 +121,11 @@ ), '3 digit year' => array( new TimeValue( '+999-01-01T00:00:00Z', 0, 0, 0, $day, $gregorian ), - '@.*<td[^<>]*isotime">\+0999-01-01T00:00:00</td>.*@s' + '@.*<td[^<>]*isotime">\+0999-01-01T00:00:00Z</td>.*@s' ), 'Negative, padded year' => array( new TimeValue( '-099999-01-01T00:00:00Z', 0, 0, 0, $day, $gregorian ), - '@.*<td[^<>]*isotime">\xE2\x88\x9299999-01-01T00:00:00</td>.*@s' + '@.*<td[^<>]*isotime">\xE2\x88\x9299999-01-01T00:00:00Z</td>.*@s' ), 'Optional Z' => array( $this->getTimeValue( '-099999-01-01T00:00:00' ), @@ -133,7 +133,7 @@ ), 'Optional sign' => array( $this->getTimeValue( '099999-01-01T00:00:00Z' ), - '@.*<td[^<>]*isotime">\+99999-01-01T00:00:00</td>.*@s' + '@.*<td[^<>]*isotime">\+99999-01-01T00:00:00Z</td>.*@s' ), 'Julian' => array( new TimeValue( '+2001-01-01T00:00:00Z', 0, 0, 0, $day, $julian ), -- To view, visit https://gerrit.wikimedia.org/r/222119 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id453e9e9f57a3bfa246b83aa1dd17e42017c2313 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits