Skip to:
Content

BuddyPress.org

Changeset 9618


Ignore:
Timestamp:
03/11/2015 08:58:29 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Core: Clean up bp_format_time:

  • More detailed phpdoc block.
  • Add @since tag.
  • White space is delicious.
  • Rename parameters to avoid double negative checks.
  • Rename another variable.

See #2693.

File:
1 edited

Legend:

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

    r9617 r9618  
    273273
    274274/**
    275  * Format a date.
    276  *
    277  * @param int $time The UNIX timestamp to be formatted.
    278  * @param bool $just_date Optional. True to return only the month + day, false
    279  *        to return month, day, and time. Default: false.
    280  * @param bool $localize_time Optional. True to display in local time, false to
    281  *        leave in GMT. Default: true.
    282  * @return string|bool $localize_time Optional. A string representation of
    283  *         $time, in the format "January 1, 2010 at 9:50pm" (or whatever your
    284  *         'date_format' and 'time_format' settings are). False on failure.
    285  */
    286 function bp_format_time( $time = '', $just_date = false, $localize_time = true ) {
     275 * Format a date based on a UNIX timestamp
     276 *
     277 * This function can be used to turn a UNIX timestamp into a properly formatted
     278 * (and possibly localized) string, userful for ouputting the date & time an
     279 * action took place.
     280 *
     281 * Not to be confused with `bp_core_time_since()`, this function is best used
     282 * for displaying a more exact date and time vs. a human-readable time.
     283 *
     284 * Note: This function may be improved or removed at a later date, as it is
     285 * hardly used and adds an additional layer of complexity to calculating dates
     286 * and times together with timezone offsets and i18n.
     287 *
     288 * @since BuddyPress (1.1.0)
     289 *
     290 * @param int  $time         The UNIX timestamp to be formatted.
     291 * @param bool $exclude_time Optional. True to return only the month + day, false
     292 *                           to return month, day, and time. Default: false.
     293 * @param bool $gmt          Optional. True to display in local time, false to
     294 *                           leave in GMT. Default: true.
     295 *
     296 * @return mixed             A string representation of $time, in the format
     297 *                           "March 18, 2014 at 2:00 pm" (or whatever your
     298 *                           'date_format' and 'time_format' settings are
     299 *                           on your root blog). False on failure.
     300 */
     301function bp_format_time( $time = '', $exclude_time = false, $gmt = true ) {
    287302
    288303    // Bail if time is empty or not numeric
     
    293308
    294309    // Get GMT offset from root blog
    295     if ( true === $localize_time ) {
     310    if ( true === $gmt ) {
    296311
    297312        // Use Timezone string if set
     
    315330    }
    316331
    317     // Current date (January 1, 2010)
    318     $formatted_date = date_i18n( bp_get_option( 'date_format' ), $calculated_time, $localize_time );
     332    // Formatted date: "March 18, 2014"
     333    $formatted_date = date_i18n( bp_get_option( 'date_format' ), $calculated_time, $gmt );
    319334
    320335    // Should we show the time also?
    321     if ( false === $just_date ) {
    322 
    323         // Current time (9:50pm)
    324         $formatted_time = date_i18n( bp_get_option( 'time_format' ), $calculated_time, $localize_time );
     336    if ( true !== $exclude_time ) {
     337
     338        // Formatted time: "2:00 pm"
     339        $formatted_time = date_i18n( bp_get_option( 'time_format' ), $calculated_time, $gmt );
    325340
    326341        // Return string formatted with date and time
Note: See TracChangeset for help on using the changeset viewer.