}
function formatTimePeriod( $seconds ) {
- if ( $seconds < 10 ) {
- return $this->formatNum( sprintf( "%.1f", $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
- } elseif ( $seconds < 60 ) {
+ if ( round( $seconds * 10 ) < 100 ) {
+ return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
+ } elseif ( round( $seconds ) < 60 ) {
return $this->formatNum( round( $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
- } elseif ( $seconds < 3600 ) {
+ } elseif ( round( $seconds ) < 3600 ) {
$minutes = floor( $seconds / 60 );
$secondsPart = round( fmod( $seconds, 60 ) );
if ( $secondsPart == 60 ) {
'convertDoubleWidth() with the full alphabet and digits'
);
}
+
+ function testFormatTimePeriod() {
+ $this->assertEquals(
+ "9.5s",
+ $this->lang->formatTimePeriod( 9.45 ),
+ 'formatTimePeriod() rounding (<10s)'
+ );
+
+ $this->assertEquals(
+ "10s",
+ $this->lang->formatTimePeriod( 9.95 ),
+ 'formatTimePeriod() rounding (<10s)'
+ );
+
+ $this->assertEquals(
+ "1m 0s",
+ $this->lang->formatTimePeriod( 59.55 ),
+ 'formatTimePeriod() rounding (<60s)'
+ );
+
+ $this->assertEquals(
+ "2m 0s",
+ $this->lang->formatTimePeriod( 119.55 ),
+ 'formatTimePeriod() rounding (<1h)'
+ );
+
+ $this->assertEquals(
+ "1h 0m 0s",
+ $this->lang->formatTimePeriod( 3599.55 ),
+ 'formatTimePeriod() rounding (<1h)'
+ );
+
+ $this->assertEquals(
+ "2h 0m 0s",
+ $this->lang->formatTimePeriod( 7199.55 ),
+ 'formatTimePeriod() rounding (>=1h)'
+ );
+ }
}