## Friday, July 1, 2011

As I have mentioned before, I run the single serving site, IsFamilyGuyCurrentlyPlayingOnAdultSwim.com. Tonight, the first of July, as I went to check if Family Guy was indeed playing, I noticed the site was displaying my catchall bug informing the user something went wrong. Nervous that Adult Swim had retooled their scheduling or caught on and blocked me from leeching their scheduling data, I began to investigate.

As it turns out, it was a bug I had never caught in which the first day of the month (which begins at 12 midnight) was looking backwards for the previous day's schedule (which is what late night programming is technically classified under). So, being the first of July, the late night Adult Swim programming is still technically part June 30th's programming block. However, my naive code was simply subtracting 1 from the date so that it was looking for day 0 and not day 30 (the last day of June).

Adult Swim stores schedules in XML files located at URLs such as http://schedule.adultswim.com/asXml/1.EST.xml. This link may appear to lead to a blank page but if you look at the source, it is an XML file containing show data. The naming format is fairly simple: the "1" is the date of the current month so that if it is July, then 1 represents July 1st. The "EST" means this is the schedule for Eastern Standard Time (they have all the American time zones). So basically, on the first of the month, my website knew it was first but technically the scheduling for all late night programming on the first is really part of yesterday. Unfortunately, my error resulted in looking for a file named "http://schedule.adultswim.com/asXml/0.EST.xml" instead of "http://schedule.adultswim.com/asXml/30.EST.xml".

Before, I said the format "1.EST.xml" meant the first of the current month for Eastern time zones in the US? Well one catch, apparently if it is the first, then "30.EST.xml" or "31.EST.xml" or any other "last day of month" schedule points to last month's 30th or 31st or what have you. Luckily, in PHP, it is easy to work with dates and times and calling date("t", mktime(0, 0, 0, date("n") - 1, 1, date("y"))); returns the last day of the last month. So, in August this will return 31 (31 days in July) but right now (in July) it returns 30 (30 days in June).

What is interesting is that I went to confirm that the official Adult Swim schedule was working and that the "30.EST.xml" and the like all actually pointed to June 30th's programming and not July's. When loading the page I was greeted with this:

It looks like Adult Swim has a similar issue; the schedule does not load and inspecting the page reveals it is trying to load "undefined.EST.xml". I haven't looked at this page in a while, but I assume it's a similar error of judgement when programming in terms of "it's 2 AM, we need to actually pull the programming from yesterday so let's do some subtraction and forget about how the day before the first isn't the 0th".