Patch for Twitter Tools plugin’s timezone problem

Since I got an extra day off from work yesterday, I had some time to spend on solving a problem. I use Twitter Tools to display my five most recent tweets on my blog, as well as creating a digest post of my tweets every day, and a notification tweet of new posts to my blog. Its a really nice plugin and a good piece of work. But, it has a bug – Twitter returns tweets in UTC time, while some of the key comparisons inside Twitter Tools uses local time. This affected the digest posts; some tweets would appear on the wrong day.

It was hard to find all the comparison items and get them converted to UTC time, so I decided to convert the tweet time to local time using the setting in the WordPress application. I’ve posted this patch to the WordPress support forum at Here’s the patch as well (this patch only applies to the 1.2b1 version):

*** twitter-tools.php.0	Sun Apr 13 20:07:12 2008
--- twitter-tools.php	Thu Jul  3 13:06:44 2008
*** 401,406 ****
--- 401,409 ----

  	function add() {
  		global $wpdb, $aktt;
+ 		// RLH: The next line corrects Twitter's UTC to WordPress timezone setting
+ 		$this->tw_created_at = $this->tw_created_at + (get_option('gmt_offset') * 3600);
+ 		// RLH: End changes
  			INTO $wpdb->aktt
*** 1353,1358 ****
--- 1356,1364 ----

  	$now = time();
+ 	// RLH: Must shift "now" back to proper timezone to match WordPress
+ 	$now = $now +  + (get_option('gmt_offset') * 3600);
+ 	// RLH: End changes

  	$time = gmmktime(
  		substr($date, 11, 2)

I hope that helps make this plugin more effective. Perhaps the author could eventually fix all the comparisons and we could go back to using UTC for everything, as I think that’s the right answer. But, this works for now.


There are no revisions for this post.

Posted in Computer, Tags: ,