Timezones

Historically, bbPress has dealt with time in a… shall we say “interesting” manner. Without going into technical details, bbPress constrained you, the person installing bbPress, to set it’s internal timezone to match exactly that of the server it was running on.

That’s ridiculous.

What if you lived in Brisbane, but your servers were held captive in Cleveland and set to GMT? I’ll tell you what if: only after lots of trial and error were you able to get rid of that strange “-1 years ago” bug seen everywhere on your site. But then you were stuck at some arbitrary timezone.

With bbPress 0.8, all that has changed. You can set bbPress’ timezone to anything you like completely independent of where you are and where your server is.

But that’s not good enough, you cry! You want your users to be able to set their own timezones too! Well, bbPress doesn’t do that, and may never, but a plugin can and does! See the “proof-of-concept” User Timezones plugin.

Template Functions

Additionally, theme designing and tweaking is now much easier with respect to time template functions like bb_post_time(), topic_time(), and topic_start_time().

  • By default, these functions output time formatted like “7 hours” as in “7 hours ago”.
  • You can specify a different format by using a PHP date format string:
    bb_post_time( 'F j, Y, h:i A' )

    -> “February 8, 2007, 10:57 PM”

  • A lot of bbPress’ default templates used to do strange things like
    bb_since( strtotime( bb_get_post_time() ) )

    or something equally heinous. No longer. All the default templates now use the much more pleasant method described above. If you based any custom templates off of the old default templates, they will probably still work since the changes made were almost completely backward compatible. If you run into any problems, remove from your templates any mention of strtotime(), bb_since(), and bb_offset_time() as the bits you need from those functions should now work automagically.

  • For you plugin developers, you can also easily grab the Unix timestamp: bb_get_post_time( 'timestamp' ), and the MySQL date: bb_get_post_time( 'mysql' ).

Much more pleasant 🙂