<p>The Retro project has logs of conversation in the #retro irc channel on irc.freenode.net going
   back to 2006. This is a small web app to allow viewing them in a nicer fashion.</p>

<p>To get started, select a date from the calendar below. These logs are updated hourly. For direct
   linking, use this URL, replacing the yy.mm.dd with the date you wish to link to:
   <br>%u/log/yy.mm.dd</p>

  <script type="text/javascript">
  function pad(n, len) {
    s = n.toString();
    if (s.length < len)
      s = ('00' + s).slice(-len);
    return s;
  }

  function cut (n) {
    n = "" + n;
    return n.substring(2);
  }

  cal_days_labels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  cal_months_labels = ['January', 'February', 'March', 'April',
                       'May', 'June', 'July', 'August', 'September',
                       'October', 'November', 'December'];
  cal_days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  cal_current_date = new Date();

  function Calendar(month, year) {
    this.month = (isNaN(month) || month == null) ? cal_current_date.getMonth() : month;
    this.year  = (isNaN(year) || year == null) ? cal_current_date.getFullYear() : year;
    this.html = '';
  }

  Calendar.prototype.generateHTML = function(){
    // get first day of month
    var firstDay = new Date(this.year, this.month, 1);
    var startingDay = firstDay.getDay();
    // find number of days in month
    var monthLength = cal_days_in_month[this.month];
    // compensate for leap year
    if (this.month == 1) { // February only!
      if((this.year \% 4 == 0 && this.year \% 100 != 0) || this.year \% 400 == 0){
        monthLength = 29;
      }
    }
    // do the header
    var monthName = cal_months_labels[this.month]
    var html = '<table class="calendar-table">';
    html += '<tr><th colspan="7">';
    html +=  monthName + "&nbsp;" + this.year;
    html += '</th></tr>';
    html += '<tr class="calendar-header">';
    for(var i = 0; i <= 6; i++ ){
      html += '<td class="calendar-header-day">';
      html += cal_days_labels[i];
      html += '</td>';
    }
    html += '</tr><tr>';
    // fill in the days
    var day = 1;
    // this loop is for is weeks (rows)
    for (var i = 0; i < 9; i++) {
      // this loop is for weekdays (cells)
      for (var j = 0; j <= 6; j++) {
        html += '<td class="calendar-day">';
        if (day <= monthLength && (i > 0 || j >= startingDay)) {
          html += '<a href="%u/log/' + cut(this.year) + '.' + pad(this.month + 1, 2) + '.' + pad(day, 2) + '">' + day + '</a>';
          day++;
        }
        html += '</td>';
      }
      // stop making rows if we've run out of days
      if (day > monthLength) {
        break;
      } else {
        html += '</tr><tr>';
      }
    }
    html += '</tr></table>';
    this.html = html;
  }

  Calendar.prototype.getHTML = function() {
    return this.html;
  }

  var cal = new Calendar();
  cal.generateHTML();
  document.write(cal.getHTML());
</script>
