diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
index 9e46100..e2b6d79 100644
|
|
function bp_core_get_site_path() { |
759 | 759 | * @since BuddyPress (1.2.6) |
760 | 760 | * |
761 | 761 | * @param bool $gmt True to use GMT (rather than local) time. Default: true. |
| 762 | * @param bool $unix True to use UNIX timestamp. False to use formatted date. |
| 763 | * Default: false. |
762 | 764 | * @return string Current time in 'Y-m-d h:i:s' format. |
763 | 765 | */ |
764 | | function bp_core_current_time( $gmt = true ) { |
765 | | // Get current time in MYSQL format |
766 | | $current_time = current_time( 'mysql', $gmt ); |
| 766 | function bp_core_current_time( $gmt = true, $unix = false ) { |
| 767 | if ( true == $unix ) { |
| 768 | $mode = 'timestamp'; |
| 769 | } else { |
| 770 | $mode = 'mysql'; |
| 771 | } |
| 772 | |
| 773 | // Get current time |
| 774 | $current_time = current_time( $mode, $gmt ); |
767 | 775 | |
768 | 776 | return apply_filters( 'bp_core_current_time', $current_time ); |
769 | 777 | } |
… |
… |
function bp_core_time_since( $older_date, $newer_date = false ) { |
828 | 836 | * a date and the current time. $newer_date will have a value if we want to |
829 | 837 | * work out time elapsed between two known dates. |
830 | 838 | */ |
831 | | $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date; |
| 839 | $newer_date = ( !$newer_date ) ? bp_core_current_time( true, true ) : $newer_date; |
832 | 840 | |
833 | 841 | // Difference in seconds |
834 | 842 | $since = $newer_date - $older_date; |
diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php
index ffcfa19..4060836 100644
|
|
class BP_Tests_Core_Functions extends BP_UnitTestCase { |
345 | 345 | $this->assertTrue( buddypress()->foo->has_directory ); |
346 | 346 | $this->assertNotEmpty( buddypress()->loaded_components['foo'] ); |
347 | 347 | } |
| 348 | |
| 349 | /** |
| 350 | * @group bp_core_time_since |
| 351 | * @group bp_core_current_time |
| 352 | */ |
| 353 | public function test_bp_core_time_since_timezone_right_now() { |
| 354 | // backup timezone |
| 355 | $tz_backup = date_default_timezone_get(); |
| 356 | |
| 357 | // set timezone to something other than UTC |
| 358 | date_default_timezone_set( 'Europe/Paris' ); |
| 359 | |
| 360 | $this->assertSame( 'right now', bp_core_time_since( time() ) ); |
| 361 | |
| 362 | // revert timezone back to normal |
| 363 | if ( $tz_backup ) { |
| 364 | date_default_timezone_set( $tz_backup ); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * @group bp_core_time_since |
| 370 | * @group bp_core_current_time |
| 371 | */ |
| 372 | public function test_bp_core_time_since_timezone() { |
| 373 | // backup timezone |
| 374 | $tz_backup = date_default_timezone_get(); |
| 375 | |
| 376 | // set timezone to something other than UTC |
| 377 | date_default_timezone_set( 'Europe/Paris' ); |
| 378 | |
| 379 | $this->assertSame( '1 hour ago', bp_core_time_since( time() - 60*60 ) ); |
| 380 | |
| 381 | // revert timezone back to normal |
| 382 | if ( $tz_backup ) { |
| 383 | date_default_timezone_set( $tz_backup ); |
| 384 | } |
| 385 | } |
348 | 386 | } |