Index: trunk/phase3/tests/phpunit/languages/LanguageTest.php |
— | — | @@ -56,6 +56,60 @@ |
57 | 57 | $this->lang->formatTimePeriod( 7199.55 ), |
58 | 58 | 'formatTimePeriod() rounding (>=1h)' |
59 | 59 | ); |
| 60 | + |
| 61 | + $this->assertEquals( |
| 62 | + "2h 0m", |
| 63 | + $this->lang->formatTimePeriod( 7199.55, 'avoidseconds' ), |
| 64 | + 'formatTimePeriod() rounding (>=1h), avoidseconds' |
| 65 | + ); |
| 66 | + |
| 67 | + $this->assertEquals( |
| 68 | + "2h 0m", |
| 69 | + $this->lang->formatTimePeriod( 7199.55, 'avoidminutes' ), |
| 70 | + 'formatTimePeriod() rounding (>=1h), avoidminutes' |
| 71 | + ); |
| 72 | + |
| 73 | + $this->assertEquals( |
| 74 | + "48h 0m", |
| 75 | + $this->lang->formatTimePeriod( 172799.55, 'avoidseconds' ), |
| 76 | + 'formatTimePeriod() rounding (=48h), avoidseconds' |
| 77 | + ); |
| 78 | + |
| 79 | + $this->assertEquals( |
| 80 | + "3d 0h", |
| 81 | + $this->lang->formatTimePeriod( 259199.55, 'avoidminutes' ), |
| 82 | + 'formatTimePeriod() rounding (>48h), avoidminutes' |
| 83 | + ); |
| 84 | + |
| 85 | + $this->assertEquals( |
| 86 | + "2d 1h 0m", |
| 87 | + $this->lang->formatTimePeriod( 176399.55, 'avoidseconds' ), |
| 88 | + 'formatTimePeriod() rounding (>48h), avoidseconds' |
| 89 | + ); |
| 90 | + |
| 91 | + $this->assertEquals( |
| 92 | + "2d 1h", |
| 93 | + $this->lang->formatTimePeriod( 176399.55, 'avoidminutes' ), |
| 94 | + 'formatTimePeriod() rounding (>48h), avoidminutes' |
| 95 | + ); |
| 96 | + |
| 97 | + $this->assertEquals( |
| 98 | + "3d 0h 0m", |
| 99 | + $this->lang->formatTimePeriod( 259199.55, 'avoidseconds' ), |
| 100 | + 'formatTimePeriod() rounding (>48h), avoidminutes' |
| 101 | + ); |
| 102 | + |
| 103 | + $this->assertEquals( |
| 104 | + "2d 0h 0m", |
| 105 | + $this->lang->formatTimePeriod( 172801.55, 'avoidseconds' ), |
| 106 | + 'formatTimePeriod() rounding, (>48h), avoidseconds' |
| 107 | + ); |
| 108 | + |
| 109 | + $this->assertEquals( |
| 110 | + "2d 1h 1m 1s", |
| 111 | + $this->lang->formatTimePeriod( 176460.55 ), |
| 112 | + 'formatTimePeriod() rounding, recursion, (>48h)' |
| 113 | + ); |
60 | 114 | } |
61 | 115 | |
62 | 116 | /** |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -3413,16 +3413,16 @@ |
3414 | 3414 | * @param $seconds int|float |
3415 | 3415 | * @param $format String Optional, one of ("avoidseconds","avoidminutes"): |
3416 | 3416 | * "avoidseconds" - don't mention seconds if $seconds >= 1 hour |
3417 | | - * "avoidminutes" - don't mention seconds/minutes if $seconds > 2 days |
| 3417 | + * "avoidminutes" - don't mention seconds/minutes if $seconds > 48 hours |
3418 | 3418 | * @return string |
3419 | 3419 | */ |
3420 | 3420 | function formatTimePeriod( $seconds, $format = false ) { |
3421 | 3421 | if ( round( $seconds * 10 ) < 100 ) { |
3422 | | - return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . |
3423 | | - $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3422 | + $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ); |
| 3423 | + $s .= $this->getMessageFromDB( 'seconds-abbrev' ); |
3424 | 3424 | } elseif ( round( $seconds ) < 60 ) { |
3425 | | - return $this->formatNum( round( $seconds ) ) . |
3426 | | - $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3425 | + $s = $this->formatNum( round( $seconds ) ); |
| 3426 | + $s .= $this->getMessageFromDB( 'seconds-abbrev' ); |
3427 | 3427 | } elseif ( round( $seconds ) < 3600 ) { |
3428 | 3428 | $minutes = floor( $seconds / 60 ); |
3429 | 3429 | $secondsPart = round( fmod( $seconds, 60 ) ); |
— | — | @@ -3430,9 +3430,9 @@ |
3431 | 3431 | $secondsPart = 0; |
3432 | 3432 | $minutes++; |
3433 | 3433 | } |
3434 | | - return $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . |
3435 | | - ' ' . |
3436 | | - $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3434 | + $s = $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3435 | + $s .= ' '; |
| 3436 | + $s .= $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); |
3437 | 3437 | } elseif ( round( $seconds ) <= 2*86400 ) { |
3438 | 3438 | $hours = floor( $seconds / 3600 ); |
3439 | 3439 | $minutes = floor( ( $seconds - $hours * 3600 ) / 60 ); |
— | — | @@ -3445,25 +3445,47 @@ |
3446 | 3446 | $minutes = 0; |
3447 | 3447 | $hours++; |
3448 | 3448 | } |
3449 | | - $s = $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ) . |
3450 | | - ' ' . |
3451 | | - $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
3452 | | - if ( $format !== 'avoidseconds' ) { |
| 3449 | + $s = $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3450 | + $s .= ' '; |
| 3451 | + $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3452 | + if ( !in_array( $format, array( 'avoidseconds', 'avoidminutes' ) ) ) { |
3453 | 3453 | $s .= ' ' . $this->formatNum( $secondsPart ) . |
3454 | 3454 | $this->getMessageFromDB( 'seconds-abbrev' ); |
3455 | 3455 | } |
3456 | | - return $s; |
3457 | 3456 | } else { |
3458 | 3457 | $days = floor( $seconds / 86400 ); |
3459 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ) . ' '; |
3460 | 3458 | if ( $format === 'avoidminutes' ) { |
| 3459 | + $hours = round( ( $seconds - $days * 86400 ) / 3600 ); |
| 3460 | + if ( $hours == 24 ) { |
| 3461 | + $hours = 0; |
| 3462 | + $days++; |
| 3463 | + } |
| 3464 | + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3465 | + $s .= ' '; |
| 3466 | + $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3467 | + } elseif ( $format === 'avoidseconds' ) { |
3461 | 3468 | $hours = floor( ( $seconds - $days * 86400 ) / 3600 ); |
| 3469 | + $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 ); |
| 3470 | + if ( $minutes == 60 ) { |
| 3471 | + $minutes = 0; |
| 3472 | + $hours++; |
| 3473 | + } |
| 3474 | + if ( $hours == 24 ) { |
| 3475 | + $hours = 0; |
| 3476 | + $days++; |
| 3477 | + } |
| 3478 | + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3479 | + $s .= ' '; |
3462 | 3480 | $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3481 | + $s .= ' '; |
| 3482 | + $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
3463 | 3483 | } else { |
| 3484 | + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3485 | + $s .= ' '; |
3464 | 3486 | $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format ); |
3465 | 3487 | } |
3466 | | - return $s; |
3467 | 3488 | } |
| 3489 | + return $s; |
3468 | 3490 | } |
3469 | 3491 | |
3470 | 3492 | /** |