r114321 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114320‎ | r114321 | r114322 >
Date:22:47, 20 March 2012
Author:jeroendedauw
Status:reverted
Tags:gerritmigration 
Comment:
handle cases where an empty array is provided by using this as default, also correctly handle cases where the smallest unit is not the second and the result is 0 smallestunit
Modified paths:
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/Language.php
@@ -1919,7 +1919,7 @@
19201920 *
19211921 * @return string
19221922 */
1923 - public function formatDuration( $seconds, array $chosenIntervals = array( 'millennia', 'centuries', 'decades', 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
 1923+ public function formatDuration( $seconds, array $chosenIntervals = array() ) {
19241924 $intervals = array(
19251925 'millennia' => 1000 * 31557600,
19261926 'centuries' => 100 * 31557600,
@@ -1932,16 +1932,20 @@
19331933 'seconds' => 1,
19341934 );
19351935
1936 - if ( !empty( $chosenIntervals ) ) {
1937 - $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
 1936+ if ( empty( $chosenIntervals ) ) {
 1937+ $chosenIntervals = array( 'millennia', 'centuries', 'decades', 'years', 'days', 'hours', 'minutes', 'seconds' );
19381938 }
19391939
 1940+ $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
 1941+ $sortedNames = array_keys( $intervals );
 1942+ $smallestInterval = array_pop( $sortedNames );
 1943+
19401944 $segments = array();
19411945
19421946 foreach ( $intervals as $name => $length ) {
19431947 $value = floor( $seconds / $length );
19441948
1945 - if ( $value > 0 || ( $name == 'seconds' && empty( $segments ) ) ) {
 1949+ if ( $value > 0 || ( $name == $smallestInterval && empty( $segments ) ) ) {
19461950 $seconds -= $value * $length;
19471951 $message = new Message( 'duration-' . $name, array( $value ) );
19481952 $segments[] = $message->inLanguage( $this )->escaped();

Follow-up revisions

RevisionCommit summaryAuthorDate
r114326Revert r114067, r114071, r114075, r114079, r114081, r114082, r114084, r114086......catrope23:03, 20 March 2012

Status & tagging log