Skip to:
Content
Pages
Categories
Search
Top
Bottom

time zones different in Messages and Forums (bbpress)


  • 3sixty
    Participant

    @3sixty

    I can’t get Messages to report “time ago” correctly without breaking the time reporting in the Forums.

    Out of the box, Forums are reporting times correctly (“Posted 2 seconds ago”) but Messages report incorrectly (“Posted 5 hours ago”). In an attempt to fix this, I tried using date_default_timezone_set(); which fixed Messages, but it “broke” Forums – the times now say “Posted sometime ago”.

    Any idea what’s going on, and how to fix it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ensure your WP install is set to use the same timezone as your server. Test with a new message, not an old one, because in some areas the timestamps are cached and so won’t reflect any changes to the timezone (i.e. the Activity Stream is an easy example). If you still find an inconsistency, please report this as a bug on https://trac.buddypress.org/


    3sixty
    Participant

    @3sixty

    WP is set to UTC, and so is my server.

    I can duplicate this on a fresh BP install, but I can’t duplicate this on testbp.org

    In debugging, I sent a test Message that had a Sent Time of 2010-03-24 08:22:03 when the server time is UTC time 2010-03-24 13:22:52. So there is the 5 hour difference.

    Must be some issue with my server. Anyone else having this? Either way, will file this on trac as a bug.


    3sixty
    Participant

    @3sixty

    hmm, it turns out my server is on CDST. However, changing the time zone on the WPMU backend had no effect on the Messaging “Time Ago” inconsistency. I’ll file a bug report now.


    3sixty
    Participant

    @3sixty

    OK, starting to solve the issue. I think the root of the problem is that my BP installation is on shared hosting (I know, I know…) and the server time zone is different than my WP installation time. HowEVER, BP Messages is pulling the SERVER time when it INSERTs the message record (bp-messages-classes.php:

    // First insert the message into the messages table
    if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, FROM_UNIXTIME(%d) )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) )

    I added a variable and changed the query like this:

    $wp_current_time = current_time('mysql');
    // First insert the message into the messages table
    if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $wp_current_time ) ) )

    Now the message inserts correctly using my WP installation time instead of the server time, and REPLIES show up as having the correct time (such as “posted 4 minutes ago”). However…

    While REPLIES report time correctly, for some reason, the INITIAL MESSAGE does not. I think that <?php bp_the_thread_message_time_since() ?> is somehow not reporting correctly. Let me check to see what’s wrong with that.


    3sixty
    Participant

    @3sixty

    Actually, I ran out of time. I’m just going to use the $thread_template->message->date_sent variable and convert it to “posted … ago” using the “nicetime” function found on the PHP manual pages… works for now!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘time zones different in Messages and Forums (bbpress)’ is closed to new replies.
Skip to toolbar