jenkins-bot has submitted this change and it was merged.

Change subject: Format time zone as +01:00 in TimeDetailsFormatter
......................................................................


Format time zone as +01:00 in TimeDetailsFormatter

This turns the number of minutes into the common, human readable
format for time zones (with colon and correct minus character).

This can be seen in diffs.

Change-Id: Ifa5058a079a4a49a2e4eacb07e58ec74aa3f1b87
---
M lib/includes/formatters/TimeDetailsFormatter.php
M lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
2 files changed, 23 insertions(+), 4 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/formatters/TimeDetailsFormatter.php 
b/lib/includes/formatters/TimeDetailsFormatter.php
index e5700fb..008d37b 100644
--- a/lib/includes/formatters/TimeDetailsFormatter.php
+++ b/lib/includes/formatters/TimeDetailsFormatter.php
@@ -87,8 +87,10 @@
                $html .= $this->renderLabelValuePair( 'isotime', 
htmlspecialchars( $value->getTime() ) );
 
                //TODO: provide "nice" rendering of timezone, calendar, 
precision, etc.
-               $html .= $this->renderLabelValuePair( 'timezone',
-                       htmlspecialchars( $value->getTimezone() ) );
+               $html .= $this->renderLabelValuePair(
+                       'timezone',
+                       $this->formatTimezone( $value->getTimezone() )
+               );
                $html .= $this->renderLabelValuePair( 'calendar',
                        htmlspecialchars( $calendarModel ) );
                $html .= $this->renderLabelValuePair( 'precision',
@@ -103,6 +105,18 @@
        }
 
        /**
+        * @param int $timezone
+        *
+        * @return string
+        */
+       private function formatTimezone( $timezone ) {
+               $sign = $timezone < 0 ? "\xE2\x88\x92" : '+';
+               $hour = floor( abs( $timezone ) / 60 );
+               $minute = abs( $timezone ) - $hour * 60;
+               return sprintf( '%s%02d:%02d', $sign, $hour, $minute );
+       }
+
+       /**
         * @param string $fieldName
         * @param string $valueHtml
         *
diff --git a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php 
b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
index 04307a6..9a350d5 100644
--- a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
@@ -45,7 +45,7 @@
                                        array(
                                                
'<h4[^<>]*>[^<>]*2001[^<>]*</h4>',
                                                
'<td[^<>]*>\+0*2001-01-01T00:00:00Z</td>',
-                                               '<td[^<>]*>60</td>',
+                                               '<td[^<>]*>\+01:00</td>',
                                                '<td[^<>]*>Gregorian</td>',
                                                '<td[^<>]*>10</td>',
                                                '<td[^<>]*>0</td>',
@@ -56,7 +56,12 @@
                        array(
                                new TimeValue( '+2001-01-01T00:00:00Z', 60, 0, 
1, 10, 'Stardate' ),
                                $options,
-                               '@.*<td[^<>]*>Stardate</td>.*@s'
+                               '@.*<td 
class="wb-time-calendar">Stardate</td>.*@s'
+                       ),
+                       array(
+                               new TimeValue( '+2001-01-01T00:00:00Z', -179, 
0, 1, 10, TimeFormatter::CALENDAR_GREGORIAN ),
+                               $options,
+                               '@.*<td 
class="wb-time-timezone">\xE2\x88\x9202:59</td>.*@s'
                        ),
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/188535
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifa5058a079a4a49a2e4eacb07e58ec74aa3f1b87
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to