Changeset 7102
- Timestamp:
- 05/24/2013 01:33:06 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-functions.php
r7099 r7102 592 592 // array of time period chunks 593 593 $chunks = array( 594 array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),595 array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),596 array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),597 array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),598 array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),599 array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),600 array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )594 YEAR_IN_SECONDS, 595 30 * DAY_IN_SECONDS, 596 WEEK_IN_SECONDS, 597 DAY_IN_SECONDS, 598 HOUR_IN_SECONDS, 599 MINUTE_IN_SECONDS, 600 1 601 601 ); 602 602 … … 631 631 // Step one: the first chunk 632 632 for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) { 633 $seconds = $chunks[$i] [0];633 $seconds = $chunks[$i]; 634 634 635 635 // Finding the biggest chunk (if the chunk fits, break) … … 647 647 648 648 // Set output var 649 $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2]; 649 switch ( $seconds ) { 650 case YEAR_IN_SECONDS : 651 $output = sprintf( _n( '%s year', '%s years', $count, 'buddypress' ), $count ); 652 break; 653 case 30 * DAY_IN_SECONDS : 654 $output = sprintf( _n( '%s month', '%s months', $count, 'buddypress' ), $count ); 655 break; 656 case WEEK_IN_SECONDS : 657 $output = sprintf( _n( '%s week', '%s weeks', $count, 'buddypress' ), $count ); 658 break; 659 case DAY_IN_SECONDS : 660 $output = sprintf( _n( '%s day', '%s days', $count, 'buddypress' ), $count ); 661 break; 662 case HOUR_IN_SECONDS : 663 $output = sprintf( _n( '%s hour', '%s hours', $count, 'buddypress' ), $count ); 664 break; 665 case MINUTE_IN_SECONDS : 666 $output = sprintf( _n( '%s minute', '%s minutes', $count, 'buddypress' ), $count ); 667 break; 668 default: 669 $output = sprintf( _n( '%s second', '%s seconds', $count, 'buddypress' ), $count ); 670 } 650 671 651 672 // Step two: the second chunk 652 673 if ( $i + 2 < $j ) { 653 $seconds2 = $chunks[$i + 1][0]; 654 $name2 = $chunks[$i + 1][1]; 674 $seconds2 = $chunks[$i + 1]; 655 675 $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ); 656 676 657 677 // Add to output var 658 678 if ( 0 != $count2 ) { 659 $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $name2 : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2]; 679 $output .= _x( ',', 'Separator in time since', 'buddypress' ) . ' '; 680 681 switch ( $seconds2 ) { 682 case 30 * DAY_IN_SECONDS : 683 $output .= sprintf( _n( '%s month', '%s months', $count2, 'buddypress' ), $count2 ); 684 break; 685 case WEEK_IN_SECONDS : 686 $output .= sprintf( _n( '%s week', '%s weeks', $count2, 'buddypress' ), $count2 ); 687 break; 688 case DAY_IN_SECONDS : 689 $output .= sprintf( _n( '%s day', '%s days', $count2, 'buddypress' ), $count2 ); 690 break; 691 case HOUR_IN_SECONDS : 692 $output .= sprintf( _n( '%s hour', '%s hours', $count2, 'buddypress' ), $count2 ); 693 break; 694 case MINUTE_IN_SECONDS : 695 $output .= sprintf( _n( '%s minute', '%s minutes', $count2, 'buddypress' ), $count2 ); 696 break; 697 default: 698 $output .= sprintf( _n( '%s second', '%s seconds', $count2, 'buddypress' ), $count2 ); 699 } 660 700 } 661 701 } -
trunk/tests/testcases/core/functions.php
r7101 r7102 160 160 161 161 /** 162 * Sanity check for the singular version of 'year' 163 * 164 * @group bp_core_time_since 165 */ 166 public function test_bp_core_time_since_year() { 167 $now = time(); 168 $then = $now - YEAR_IN_SECONDS; 169 $this->assertEquals( '1 year ago', bp_core_time_since( $then, $now ) ); 170 } 171 172 /** 162 173 * @group bp_core_time_since 163 174 */
Note: See TracChangeset
for help on using the changeset viewer.