Tim B did a little work with an e-learning vendor, with some very old code. The code in question happened to be so old that “this is server side JavaScript” was a horrifying novelty when they wrote it, instead of a standard deployment option via Node.

The code in question is bad date handling code, which isn’t impressive. What is impressive is that it demonstrates a terrible approach to dates which I’ve never seen before. It doubles as a terrible approach to arrays which I have seen before, but… it remains special.

  for (i=0; intMonthsToDisplay>0; i++)  
  {
        if (IsLeapYearDate(intMonth+i+1 +"/1/" + intYear) )  
        {
          strDaysInMonths = "312931303130313130313031312931303130313130313031"  
        }
        else  
        {
          strDaysInMonths = "312831303130313130313031312831303130313130313031"  
        }
        arrNoDaysInMonth[i] = parseInt(strDaysInMonths.substr((intMonth+i)*2,2));  
        intMonthsToDisplay = intMonthsToDisplay - 1;  
        intTotalDays = intTotalDays +arrNoDaysInMonth[i]  
  }

Yes, strDaysInMonths is our old “30 days has November…” rhyme, compressed down to two characters a month. I only wish Tim sent along the implementation of IsLeapYeaarDate, which I’m sure would be a thing to see.

[Advertisement] ProGet can centralize your organization's software applications and components to provide uniform access to developers and servers. Check it out!