Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/23/2014 06:07:39 PM (12 years ago)
Author:
r-a-y
Message:

Fix issues with bp_core_time_since().

Previously, when the $newer_date parameter isn't passed, we generated a
UNIX timestamp using strtotime() and bp_core_current_time(). strtotime()
uses the default timezone, which can cause timezone discrepencies if the
server time is not UTC.

This commit removes the strtotime() usage and refactors bp_core_current_time()
to accept current_time()'s 'type' parameter. This allows us to correctly
grab the UTC timestamp when setting bp_core_current_time()'s second
argument to 'timestamp'.

Commit also adds some unit tests.

Fixes #4310.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r8579 r8676  
    772772 *
    773773 * @param bool $gmt True to use GMT (rather than local) time. Default: true.
     774 * @param string $type See the 'type' parameter in {@link current_time()}.
     775          Default: 'mysql'.
    774776 * @return string Current time in 'Y-m-d h:i:s' format.
    775777 */
    776 function bp_core_current_time( $gmt = true ) {
    777         // Get current time in MYSQL format
    778         $current_time = current_time( 'mysql', $gmt );
     778function bp_core_current_time( $gmt = true, $type = 'mysql' ) {
     779        // Get current time
     780        $current_time = current_time( $type, $gmt );
    779781
    780782        return apply_filters( 'bp_core_current_time', $current_time );
     
    841843         * work out time elapsed between two known dates.
    842844         */
    843         $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
     845        $newer_date = ( !$newer_date ) ? bp_core_current_time( true, 'timestamp' ) : $newer_date;
    844846
    845847        // Difference in seconds
Note: See TracChangeset for help on using the changeset viewer.