Article 3KWSG CodeSOD: 30 Days

CodeSOD: 30 Days

by
Remy Porter
from The Daily WTF on (#3KWSG)

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.

proget-icon.png [Advertisement] ProGet can centralize your organization's software applications and components to provide uniform access to developers and servers. Check it out! TheDailyWtf?d=yIl2AUoC8zAsc_FZVR8A3A
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments