Archive for March, 2010

GitHub has a nice feature called “Punchcard”. It’s a graph that represents numbers of commits by day and hour (example). You can easily see wherether a project was hacked over weekends or nights, if it’s done by full-time employees, etc. There are two problems though:

  1. It ignores timezones. All timestamps are treated as if they were somewhere in the US. For projects where committers live across the world (most open source projects) it’s therefore almost useless.
  2. It only works for GitHub projects, obviously.

I’ve put together a little Bazaar plugin that can generate similar graphs for Bazaar branches. You can get the plugin here. It requires PyQt for image drawing, but many Bazaar users should already have PyQt installed. Once you install the plugin, you can generate a “Punchcard” by running a command like this in a branch directory:

bzr punchcard project-punchcard.png

For example, for QBzr you will get this graph:

You can see that the project is done by people who obviously have too much free time. There is activity pretty much any time. I guess only on weekend nights, people are tired and enjoy some sleep. :)

On the other hand, Picard was hacked by people with good sleep patterns over evenings and weekends:

MusicBrainz Server is in a similar situation, minus the good sleep patterns:

The last example is Bazaar. It’s mostly written by full-time employees and it shows:

Some programming languages really encourage using UNIX timestamps for working with dates. PHP is a good example of such a language. Functions like date, strtotime, strftime are used all the time. Most people don’t realize that timestamps in general can’t really be used for calculations though. The problem is that most countries use daylight saving time, which means that two times a year the local timezone changes. This nicely breaks the assumption that every day has 24 hours. It doesn’t. Sometimes it has 23 or 25 hours.

This StackOverflow answer is a nice example of the problem:

$mondayStr = "last monday";
if (date('N') !== '1') {  // it's not Monday today
    $mondayStr .= " last week";
}

$monday = strtotime($mondayStr);
echo date('r', $monday);    // Mon, 22 Feb 2010 00:00:00 +1000

$sunday = $monday + 86400 * 7 - 1;
echo date('r', $sunday);    // Sun, 28 Feb 2010 23:59:59 +1000

The code seems logical. Get the timestamp of the last Monday, add 60 * 60 * 24 * 7 – 1 seconds and you have the end of Sunday. Works fine most of the time. Although, if the $monday happens to be Mon, 22 Mar 2010 00:00:00, the date that was supposed to be Sun, 28 Mar 2010 23:59:59 will actually be Mon, 29 Mar 2010 00:59:59. Why? Because 28 March 2010 has only 23 hours.

Never use timestamps to do calendar calculations. It’s hard to get it right. If you really have to, at least use GMT timestamps.