So, much of the work I do involves web apps that use MySQL behind them, and more often than not, I’ve got to deal with dates and date math. PHP has its handy mkTime() function that will return Unix time given a funky order of time chunks (hh, mm, ss, mo, dy, yr). But I could rarely ever remember that particular order, and I always hated trying to parse out my MySQL date (YYYY-MM-DD) into the necessary pieces.
Alas, makeTime() was born:
function makeTime($date) {
// takes YYYY-MM-DD HH:MM:SS, or some combination thereof and returns mktime
$length = strlen($date);
$isdate = false;
$istime = false;
$sArray = explode(" ", $date);
if (sizeof($sArray) > 1) {
// explode found a " ", and we now have an array w/ length > 1
$dateString = $sArray[0];
$timeString = $sArray[1];
} else {
// explode didn't find a " ", and we have an array w/ length == 1
// check to see if it's a date or a time value
if (strstr($sArray[0], "-")) {
$dateString = $sArray[0];
} else {
$timeString = $sArray[0];
}
}
if (($dateString) && (sizeof($dateString > 0))) {
// we have a date string, parse it out
$dArray = explode("-", $dateString);
$yr = $dArray[0];
$mo = $dArray[1];
$dy = $dArray[2];
}
if (($timeString) && (sizeof($timeString > 0))) {
// we have a time string, parse it out
$tArray = explode(":", $timeString);
$hh = $tArray[0];
$mm = $tArray[1];
$ss = $tArray[2];
}
$hh = ($hh) ? $hh : "00";
$mm = ($mm) ? $mm : "00";
$ss = ($ss) ? $ss : "00";
$yr = ($yr) ? $yr : date("Y");
$mo = ($mo) ? $mo : date("m");
$dy = ($dy) ? $dy : date("d");
return mktime($hh, $mm, $ss, $mo, $dy, $yr);
}
Enjoy!
Written on May 30, 2006 Filed under Code
Using Javascript, here are a couple of fixes we came up with for issues regarding the UVM web template:
- Linking a banner graphic back to your site’s home page
If your site uses a graphic for the the banner image (instead of the standard block of color), it’s nice to offer your users a way back to your site’s home page by allowing them to click on your banner. This is especially true if you’re not using a departmental logo.
Here’s how we did it with some basic Javascript:
function bannerLink() {
var home = "http://www.uvm.edu/ctl";
document.getElementById("banner").onclick = function() {
window.location = home;
}
document.getElementById("global").onclick = function() {
window.location = home;
}
}
First, we set a variable for our site’s home:
var home="http://www.uvm.edu/ctl";
Then we set up onclick event handlers for each of the elements in question, “banner” and “global”:
document.getElementById("banner").onclick = function() {
window.location = home;
}
document.getElementById("global").onclick = function() {
window.location = home;
}
Place that bannerLink() function in a .js file so you can link to it from each page and then call it using an onload handler of the body.
- Styling the footer below the main menu
Did you ever notice how even though you might have set a background color for the footer of your site, the footer bar below the menu doesn’t change? Again, using some basic Javascript, we can change that:
function setFooter() {
var bkgd = "#DE9442";
document.getElementById("footer").style.background = bkgd;
}
First we’ll set a variable to hold the color (this is the orange of the CTL site footer), and then set the footer background to be that color.
Stash the setFooter() function in your .js file and call it with a body onload handler.
We actually combined the above functions into one init() function so that we could do multiple things when the page loads.
Written on May 28, 2006 Filed under Code
My first Wilco album was actually A Ghost is Born. I bought it after hearing “The Late Greats” on The Point, and I totally dug it. Then we watched the film I am Trying to Break Your Heart, a documentary on the making of Yankee Hotel Foxtrot and I was blown away. I picked it up at iTunes that night and was in love with it ever since.
I can solemnly swear that Wilco is actually one of the best bands on the planet.
Written on May 20, 2006 Filed under Playlist
I have no idea when I bought this book. Perhaps it was around when i read Catcher in the Rye in high school, but maybe it was earlier. For some reason I have it mentally connected with my sixth-grade teacher, George Penny. Regardless, I finally picked it up recently and I’m enjoying it. Nine short stories most of which appeared in the New Yorker years ago. If you’re a recent ex-smoker, I’d recommend avoiding this book for several years, as Salinger’s painstaking detail of the minutae of life (including describing the way one interacts with their cigarettes) can really put a strain on your desire to remain smoke free.
Written on May 20, 2006 Filed under Nightstand
Front Porch Forum is the second coming of a long-standing neighborhood email list. With a short-term goal of branching out from the initial neighborhood in Burlington’s south end to all of Chittenden County, we needed a way to scale the original third-party mailing list to a grander scale and to offer more web-based access than was originally available.
To accomplish these goals, I developed a site to help introduce the concept to newcomers, a managed user’s section to view, search, and post messages, and an administrative control panel for Front Porch Forum staff to manage member accounts, messages, and other aspects of the site. Members can post to their neighborhood forum via email or the web interface.
http://www.frontporchforum.com
Written on May 15, 2006 Filed under Portfolio
So, this just came down in my podcast of TextMate screencasts and I almost soiled myself when I watched it. Therefore, I must share it with you, my loyal reader (you know who you are).

You can also subscribe to the TextMate Screencast Podcast
Written on May 10, 2006 Filed under Apple; Code; Web
So, after a few days of messing around w/ Bootcamp and XP on the Mini, the biggest issue I’d run into was the fact that WinXP was trying to power down my USB Root Hubs to save juice. Unfortunately, I DIDN’T KNOW THIS until I came across this thread over on Google Groups.
I was experiencing the same symptoms except without the luxury of being able to quit Outlook and AIM, etc.. My keyboard & mouse would stop responding after a little while of being back on the Mac side of the KVM. After I would try to switch back to XP, nothing would respond.
However, changing the settings suggested in post #2 of that thread so far seem to do the trick.
Those XP Weenies are going to just love the Mac noobs looking for help to problems that have been solved in 2001.
Written on May 1, 2006 Filed under Apple