The Daily WTF
Long-lived projects can haveā¦ interesting little corners. Choices made 13 years ago can stick around, either because they work well enough, or because, well, every change breaks somebody’s workflow.
Today’s anonymous submitter was poking around the code base of a large, long-lived JavaScript framework. In a file, not modified since 2007, but still included in the product, they found this function.
_getAdjustedDay: function(/*Date*/dateObj){ //FIXME: use mod instead? //summary: used to adjust date.getDay() values to the new values based on the current first day of the week value var days = [0,1,2,3,4,5,6]; if(this.weekStartsOn>0){ for(var i=0;i<this.weekStartsOn;i++){ days.unshift(days.pop()); } } return days[dateObj.getDay()]; // Number: 0..6 where 0=Sunday }
Look, this is old JavaScript, it’s date handling code, and it’s handling an unusual date case, so we already know it’s going to be bad. That’s not a surprise at all.
The core problem is, given a date, we want to find out
To read the full article click on the 'post' link at the top.