by

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 http://wordpress.org/support/topic/127916?replies=4#post-796201. 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
   		$wpdb->query("
  			INSERT
  			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.

Revisions:

There are no revisions for this post.

Posted in Computer, Tags: ,

5 Comments

  1. More fixes for the blog
    10:17 am on July 5th, 2008

    […] fixed Twitter Tools on Thursday, and now I’ve fixed the page menu on my blog. Turns out the theme I’m using […]

  2. Inane Excess for 2008-07-24 | See Ted Run. Run Ted Run.
    11:09 pm on July 24th, 2008

    […] a fairly big oversight for anyone who wants to call themselves a serious coder. Fortunately a kind soul found a solution to the twitter tools time problem… I hope. I’m going to patch tonight. Tomorrow’s digest post better be […]

  3. Josh and Emily’s Site » Blog Archive » update to twitter tools for time correction
    3:00 pm on August 15th, 2008

    […] a possible fix for Twitter Tools creating the summary posts and applied it to a new 1.2b1 version of the plugin. Hopefully it will cause the summaries to be […]

  4. botesteanu
    8:34 am on September 24th, 2008

    i’ve tried to get around to sending you this through email. this may be better.
    i have a huge issue with twitter tools, same one you did, although i may have made it worse by deactivating, activating, upgrading, downgrading the plugin. it worked at one point, then it stopped when i tried to tinker with the schedule.
    as you know, alex king is politely denying any mail and/or feedback. and i don’t know of any plugin that would replace his twitter daily digest.
    anyway.. a search redirected me to you. i don’t know where to add the code. help?

  5. admin
    12:52 pm on October 5th, 2008

    Lately, I’ve had to reset Twitter Tools and then reprocess (the two buttons near the bottom of the Twitter Tools settings page). I don’t know why this is happening, and since the author is pretty much useless for support, I just want everyone to know that you may have to do this regularly. At some point I may try to figure out what’s wrong.

Leave a Reply