bp_nouveau_get_message_date( $date,  $date_format = '' )

Get message date.

Description

Source

File: bp-templates/bp-nouveau/includes/messages/functions.php

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
function bp_nouveau_get_message_date( $date ) {
    $now  = bp_core_current_time( true, 'timestamp' );
    $date = strtotime( $date );
 
    $now_date    = getdate( $now );
    $date_date   = getdate( $date );
    $compare     = array_diff( $date_date, $now_date );
    $date_format = 'Y/m/d';
 
    // Use Timezone string if set.
    $timezone_string = bp_get_option( 'timezone_string' );
    if ( ! empty( $timezone_string ) ) {
        $timezone_object = timezone_open( $timezone_string );
        $datetime_object = date_create( "@{$date}" );
        $timezone_offset = timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS;
 
    // Fall back on less reliable gmt_offset
    } else {
        $timezone_offset = bp_get_option( 'gmt_offset' );
    }
 
    // Calculate time based on the offset
    $calculated_time = $date + ( $timezone_offset * HOUR_IN_SECONDS );
 
    // use M j for all, will revisit this later
    // if ( empty( $compare['mday'] ) && empty( $compare['mon'] ) && empty( $compare['year'] ) ) {
    //  $date_format = 'H:i';
 
    // } elseif ( empty( $compare['mon'] ) || empty( $compare['year'] ) ) {
    //  $date_format = 'M j';
    // }
 
    $date_format = 'M j';
 
    /**
     * Filters the message date for BuddyPress Nouveau display.
     *
     * @since BuddyPress 3.0.0
     *
     * @param string $value           Internationalization-ready formatted date value.
     * @param mixed  $calculated_time Calculated time.
     * @param string $date            Date value.
     * @param string $date_format     Format to convert the calcuated date to.
     */
    return apply_filters( 'bp_nouveau_get_message_date', date_i18n( $date_format, $calculated_time, true ), $calculated_time, $date, $date_format );
}

Changelog

Changelog
Version Description
BuddyPress 3.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.