Anatomy of a Function

It’s been a little while since my last post. My recent work schedule and Turkey Day played a part in that. I’ve been working .com hours on a super cool project. (I mentioned the TERRA group in an earlier post.) I’ve learned so much in the last couple of weeks. It’s amazing what a hard deadline and a shifting set of requirements will do to your web programming skills. All the hard work is about to bear fruit as as the new TERRA web site is about to go live. Have a look at a different kind of digital library.

But, that’s not the point of this post… I wanted to share a little code that made some data conversion very simple over the course of the TERRA project. It’s a simple little php function that converts a MySQL timestamp into an RFC 822 date format (For the project, we stored the item update fields as timestamps and then converted them when we generated our various XML feeds. RFC 822 or RFC 2822 are necessary for valid feeds.) Here’s the php function in all its glory:

//function converts mysql timestamp into rfc 822 date
function dateConvertTimestamp($mysqlDate)
{
$rawdate=strtotime($mysqlDate);
if ($rawdate == -1) {
$convertedDate = ‘conversion failed’;
} else {
$convertedDate = date(‘D, d M Y h:i:s T’,$rawdate);
return $convertedDate;
}
}
//end dateConvertTimestamp

You call the function by including it on the page and using the following code:

$newPubdate = dateConvert(“$stringToConvert”);
echo $newPubdate;

Where $stringToConvert would be any MySQL timestamp value that needs conversion.

In the end a string like this “2005-05-17 12:00:00” looks something like this “Tue, 17 May 2005 12:00:00 EST”. You could also reverse the conversion using this php function:

//function converts rfc 822 date into mysql timestamp
function dateConvert($rssDate)
{
$rawdate=strtotime($rssDate);
if ($rawdate == -1) {
$convertedDate = ‘conversion failed’;
} else {
$convertedDate = date(‘Y-m-d h:i:s’,$rawdate);
return $convertedDate;
}
}
//end dateConvert

NOTE: If/when you copy and paste the above code, make sure all ” (double quotes) and ‘ (single quotes) are retyped. WordPress is doing a number on the proper format.

I just wanted to share the wealth a bit. If you’ve got questions or suggestions, don’t be shy about dropping a comment. I’ll be home in Wisconsin for the next several days, but I’ll have limited internet access there.  I’ll try to answer questions if they arise.


Dueling Ajax – couple of articles

I’ve been a bit of the Ajax poster boy lately. Two pieces that I wrote for library audiences have just been published.

Building an Ajax (Asynchronous JavaScript and XML) Application from Scratch.” Computers in Libraries 26, no. 10 (November/December 2006).

Ajax (Asynchronous JavaScript and XML): This Isn’t the Web I’m Used To.” Online 30, no. 6 (November/December 2006)
uri: http://www.infotoday.com/Online/nov06/Clark.shtml

Both articles fall into the “introductory” mode, although the CIL article walks you through a proof of concept Ajax page update script (mentioned in an earlier post…). I want to be clear: I’m not an Ajax evangelist. I find the suite of technologies that make Ajax go intriguing and the improvements that the Ajax framework can make to some library applications are worth learning about and applying. I tried to point out the good and the bad. Although, it is a four letter word…

I did want to mention a couple of books that were really helpful in getting me up to speed with the Ajax method.

Ajax in Action by Dave Crane, Eric Pascarello and Darren James

DHTML Utopia Modern Web Design Using JavaScript & DOM by Stuart Langridge

(Click on the book covers if you are into book learnin’ and want to browse the Amazon records.) Dig in and discover (or rediscover) some of the possibilities when you put Javascript to work in your apps.


Internet Librarian – Epilogue

I’ve been back for a little over a week and I’m still doing the catchup thing. Overall, Internet Librarian (IL) was a great experience. Got to do a little bit of everything: teaching, learning, networking…. you get the idea. One of the great things about IL is the small scale of it all. Enrollment tops at a little more than a grand which makes it easier to connect with all of the attendees. I had some extended conversations about libraries, code and workplace scenarios with a whole range of people. I’ve blogged most of the sessions I attended in earlier posts, so I won’t bore you again with the details. Here are a couple of quotes from the conference:

Favorite Library Quote from the week: “Libraries are a collection of services, not books”

Favorite Non-Library Quote from the week: “I just checked the il2006 tag on Flickr. Who is that brunette you were talking to?” (from my wife jokingly…)

One of the major themes from IL 2006 was libraries using social software – Flickr, MySpace, Facebook, Wikis… It’s a rich topic and most of the tech is easily implemented. But there are other parts of the conference where I struggle to understand the “where does the rubber meet the road” code questions. Most of the IL sessions offer the broad ideas and have little time for explaining how to do it. (I’m including myself here…) That’s not a criticism; that’s just the structure of the event. There are some ways to get at the “how’d they do that?” code questions.

  1. Attend conference workshops to answer some of the in-depth code questions.
  2. Ask for code examples from presenters (I had a number of people stop me after the presentation and over the course of the conference to talk a bit more about code questions.)
  3. Network and talk to librarians with some programming chops. Talk shop with those who are building apps in your field of interest.

As I said earlier, it was a great conference and I haven’t even mentioned Monterey, CA which is just a beautiful setting. I would suggest Internet Librarian for any public services librarian looking to understand what’s on the horizon for libraries. The smaller scale of the conference and the forward-looking nature of the presenters makes for a great mix. If you have the means and the time, check it out.