Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Activity ‘Posted an update’ – Displaying time but wrong timezone?

  • @mcuk

    Participant

    Hi all,

    Found a couple of useful code snippets to change the ’15 minutes ago’, ‘1 day ago’ etc into actual times and dates on the activity stream. Might be useful so thought I’d post:

    https://gist.github.com/dzmounir/8706592
    (courtesy of dzmounir)

    add_filter('bp_activity_time_since', 'bp_activity_time_since_newformat', 10, 2);
    function bp_activity_time_since_newformat( $time_since, &$actvitiy ) {
     
            // you can change the date format to "Y-m-d H:i:s"
    	$time_since = '<span class="time-since">' .  date_i18n("F j, Y", strtotime( $actvitiy->date_recorded ) ) . '</span>';
    	return $time_since;
    }
     
     
    add_filter('bp_activity_comment_date_recorded', 'bp_activity_comment_date_recorded_newformat', 10, 2);
    function bp_activity_comment_date_recorded_newformat( $date_recorded ) {
    	global $activities_template;
    	
            // you can change the date format to "Y-m-d H:i:s"
    	$date_recorded = date_i18n("F j, Y", strtotime( $activities_template->activity->current_comment->date_recorded );
    	return $date_recorded;
    }

    There is the issue of the time being incorrect however (in my case, out by 1 hour). If i choose a city under WP Dash>Settings General>Timezone, the code found in the old forum post below can be used/integrated to correct the issue. But if the timezone is set to a UTC value, it doesn’t work.

    This old forum post discusses issue of incorrect post time:
    https://buddypress.org/support/topic/activity-time-is-gmt-activity-stream-posted-an-update-time-is-incorrect/

    So my questions are:

    1. Is there a way to always display the local user’s post time (even if they are international)

    2. What timezone setting should be applied in the back end on WP Dash in order to address this issue of incorrect post time (or is using the code above and specifying a city the only way)?

    2. If i specify a city which fixes the issue for me personally, does that mean another international site user would have wrong post times appear on their activity streams when they use it their end?

    Thanks

    WP : 4.2.2
    BP : 2.2.3.1

Viewing 7 replies - 1 through 7 (of 7 total)
  • @almase

    Participant

    I have the same problem 🙁

    Pls help!

    @danbp

    Participant

    Please have a look to this ticket
    https://buddypress.trac.wordpress.org/ticket/6421

    Don’t hesitate to give more details or information to the devs. Login is using same credentials as on this forum.

    @almase

    Participant

    Ok i found here an other code:
    https://buddypress.org/support/topic/activity-time-is-gmt-activity-stream-posted-an-update-time-is-incorrect/

    
    function format_activity_date() {
      $activityDate=bp_get_activity_date_recorded();
      // Get GMT offset from root blog
      $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
      // Calculate offset time
      $time_offset = $time + ( $root_blog_offset * 3600 );
      // Format the time using the offset and return it; date-i18n retrieves the date in localized format
      return '' . date_i18n("l, M j, Y, g:ia T", strtotime($activityDate) + $time_offset) . '';
    }
    add_filter('bp_activity_time_since', 'format_activity_date');

    The timezone is now the right one for the first posting in stream, but the comments in stream have now the wrong timezone…. 🙁

    @danbp

    Participant

    Have you tried bp_get_activity_comment_date_recorded()

    See bp-activity-template.php:2396

    @almase

    Participant

    dont really understand.
    this code?

    	function bp_get_activity_comment_date_recorded() {
    		global $activities_template;
    
    		if ( empty( $activities_template->activity->current_comment->date_recorded ) )
    			return false;
    
    		$date_recorded = bp_core_time_since( $activities_template->activity->current_comment->date_recorded );
    
    		/**
    		 * Filters the recorded date of the activity comment currently being displayed.
    		 *
    		 * @since BuddyPress (1.5.0)
    		 *
    		 * @param string|bool Date for the activity comment currently being displayed.
    		 */
    		return apply_filters( 'bp_activity_comment_date_recorded', $date_recorded );
    	}

    and add to function.php?

    @almase

    Participant

    i now have these codes in my function.php:

    
    function bp_activity_comment_date_recorded_newformat( $date_recorded ) {
    	global $activities_template;
    	$root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
        $time_offset = $time + ( $root_blog_offset * 3600 );
    
    	$timestamp_now = time();
    	$timestamp_comment_date_recorded = strtotime( $activities_template->activity->current_comment->date_recorded );
    
    	if (abs($timestamp_now - $timestamp_comment_date_recorded) > 0 * 0 * 0 /* (24 hours) */) {
    		// you can change the date format to "l, j. F Y - H:i:s"
    		$date_recorded = date_i18n( "l, j. F Y - H:i:s", $timestamp_comment_date_recorded );
    	}
    	return $date_recorded;
    
    }
    add_filter('bp_activity_comment_date_recorded', 'bp_activity_comment_date_recorded_newformat', 10, 2);
    
    function format_activity_date() {
      $activityDate=bp_get_activity_date_recorded();
      // Get GMT offset from root blog
      $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
      // Calculate offset time
      $time_offset = $time + ( $root_blog_offset * 3600 );
      // Format the time using the offset and return it; date-i18n retrieves the date in localized format
      return '' . date_i18n("l, j. F Y - H:i:s", strtotime($activityDate) + $time_offset) . '';
    }
    add_filter('bp_activity_time_since', 'format_activity_date');

    The first posting in stream has now the right timezone, but not the comments… 🙁

    @almase

    Participant

    ok with this code it works in the comments too

    function bp_activity_comment_date_recorded_newformat( $date_recorded ) {
    	global $activities_template;
    	$root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
        $time_offset = $time + ( $root_blog_offset * 3600 );
    
      // Format the time using the offset and return it; date-i18n retrieves the date in localized format
      return '' . date_i18n("l, j. F Y - H:i:s", strtotime($activities_template->activity->current_comment->date_recorded) + $time_offset) . '';
    }
    
    add_filter('bp_activity_comment_date_recorded', 'bp_activity_comment_date_recorded_newformat', 10, 2);
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Activity ‘Posted an update’ – Displaying time but wrong timezone?’ is closed to new replies.
Skip to toolbar