Sunday, 8 January 2012

CodeSOD: Nondeterministic Months

CodeSOD: Nondeterministic Months:

"There's been a lot of talk that 2012 will exclude the month of December," writes Jon-Paul Murrow, "you know, end of world, Mayan calendar, Nostradamus, and all that. Even if this doesn't happen, there's no guarantee that future years will have twelve months."


"Fortunately, I found this snippet of JavaScript in our codebase at work that will find the number of months in any given year (that's right, any, year)."



function getMonthCountForSelectedYear()
{
return 12;
}


Jon-Paul continues, "I particularly like the way you don't even have to pass in the selected year to still get the correct return value. It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped."



No comments:

Post a Comment