A plancast “widget” – parsing @plancast RSS data

16 Mar


I’ve been enjoying plancast – similar to foursquare, which I don’t really use, but instead of saying where you *are*, you say where you *will be*. And for meaningful places, ie industry events, not just checking in because you have to be at the dry cleaners.

In my homepage revamp, I decided to integrate my next event using my plancast feed. However, the feed doesn’t provide much in the way of timing details. There’s no human-friendly format (“in 3 days”) and in fact, there’s no structured date format (i.e. 12092840482 seconds after 1970), and in fact, there’s not even a specific field for the time at all. It just appears in the “description” field, and it appears in different ways, i.e. a single date vs. a date range. (And different again if it spans two months, and if it spans two years, hmmm, it doesn’t seem to be working yet for that – ).

So I wrote a custom parser to deal with it. It accepts the “description” string from the RSS feed:

  function plancastDaysAgo($descriptionString) {

    $match = preg_match(“/When: (.*?)<br/”, $descriptionString, $matches);
    if (!$match) return;
    $whenString = $matches[1];

    # “Monday, March 14, 2010” or “March 14-15, 2010”
    $match = preg_match(“/^(?:w+, )?(w+) (d+)(?:-d+)?, (d+)$/”, $whenString, $matches);

    # “May 30- June 2, 2010”;
    if (! $match) $match = preg_match(“/^(w+) (d+)- w+ d+, (d+)/”, $whenString, $matches);

    $inputDateString = $matches[1].” “.$matches[2].”, “.$matches[3];
    $days = floor((time() – strtotime($inputDateString))/86400);

    if ($days==0) return “today”;
    elseif ($days==1) return “yesterday”;
    elseif ($days==-1) return “tomorrow”;
    elseif ($days>1) return “$days days ago”;
    return “in “.abs($days).” days”;


It’s called daysAgo for compatibility with standards “timeAgo”/”daysAgo” libraries, even though most of the time, the date will be in the future in this case.

Incidentally, a single item looks like this:

<item> <title><![CDATA[2010: The Year We Broadcast Our Credit Card at Radisson Austin, Tuesday, March 16, 2010, 12:30pm (Robert Scoble)]]></title> <link>http://plancast.com/a/1g51?utm_source=rss&amp;utm_medium=feed&amp;utm_campaign=feed</link> <description><![CDATA[Robert Scoble shared a new plan.<br /><br />What: 2010: The Year We Broadcast Our Credit Card<br />When: Tuesday, March 16, 2010, 12:30pm<br />Where: Radisson Austin]]></description> <pubDate>Mon, 08 Mar 2010 19:05:08 +0000</pubDate> <guid isPermaLink="false">l3095567@plancast.com</guid> <author>Robert Scoble (Scobleizer)</author> </item>

I’m using MagpieRSS, so it looks something like:
     if ($rss) {
      $next = $rss->items[0];
      print “on the calendar: “.plancastDaysAgo($next[description]);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: