dcramer/wp-lifestream — pull request #82 by tonyduckles (2011-11-09 04:58:37+00:00)
Title: Timezone Issues fix

Hi David,

This is my stab at fixing the timezone support in wp-lifestream.

Once upon a time, it looks like Wordpress ran in local time, but for the past few years/versions Wordpress is forcibly running in GMT/UTC time. wp-lifestream was always rendering timestamps without a specific timezone offset given, so timestamps were always displayed in UTC time rather than the local timezone that the user configured Wordpress to show timestamps in.

I've created a wrapper function ($lifestream->date_format) which times in a timestamp format-string and a timestamp (in UTC time), internally gets the configured Wordpress timezone, and then returned a formatted timestamp with the correct timezone offset. This provides a nice central abstraction.

I've been running with these changes on my personal site for well-over a year now. The changes here are only _quasi_ "linked". All the data in the Lifestream tables is uniformly stored in UTC time, so everything works fine when we start trying to display those times based on the configured timezone offset. If I remember right, the trouble is with the "child" Wordpress post records ("lvevent" type), which were getting created with a UTC-based timestamp rather than the local-time like they expected. I think I ended-up manually deleting all the lsevent-type rows from my wp_posts table and then using the "Fix missing posts" on the Lifestream Maintenance settings page to call the updated $lifestream->create_post_for_event() tag to make sure to create the "child" WP post row with the same timestamp as the Lifestream event row. But that is really only important if you care about the "child" page, i.e. if you try to click-through a Lifestream event to go to the WP post page for that event.

(Sorry for the long-winded explanation. Just trying to be thorough...)

Just looking to push this upstream, to fix this issue for other people. I've seen a few open issues about this problem on the wp-lifestream GitHub page.

Enjoy! And thanks for this great project.
-Tony