A bad date with Little League

A date dropdown only a developer can appreciate….

Little League has some strange rules regarding what division a child can play in. You’d think it’s based on age, and you’d be mostly right, except for the asterisk.

A child’s league age is dependent on what month they were born in. It also depends it they were born before or after Sep 1, 2005, which I think was done to “grandfather” some players in such that they wouldn’t have to move down a level.

This is summed up nicely on our Middletown, NJ little league site:

For boys born on or after September 1, 2005, your player’s Little League age for the 2017 spring season is your player’s age on August 31, 2017. Therefore, a boy born on July 5, 2007, would have a Little League age of 10 for 2017. And, a boy born on September 5, 2007, would have a Little League age of 9 for 2016. For boys born before September 1, 2005, your player’s Little League age for the 2017 spring season is your player’s age on April 30, 2017. Therefore, a boy born on April 8, 2005, would have a Little League age of 12 for the 2016 season. A boy born on May 5, 2005, would have a Little League age of 11 this season.

Sound confusing? It is. So much so that littleleague.org create a handy little calculator to help you determine your child’s league age. Functionally it delivers. What struck me as funny (and honestly slightly amateur, inept and embarrassing) was the order of the months in the drop down - see for yourself.

[caption id=”attachment_695” align=”aligncenter” width=”791”] January, October?, November?, December?, … what?[/caption]

For us (Javascript) developers, the problem is obvious. Javascript sorts alphabetically (not numerically) and since January is month 1, October is month 10, November 11 and December 12… these numbers actually come before 2 (February)! To make matters worse, Jan is actually 0 and Dec is 11. This is the kind of quirkiness developers put up with!

Here’s what sorting an array of strings that look like numbers looks like in Javascript

a = [‘8’, ‘1’, ‘10’, ‘2’, ‘11’, ‘3’, ‘12’]
a.sort();
[“1”, “10”, “11”, “12”, “2”, “3”, “8”]

It’s a really silly mistake to make and easy to correct.

After some further digging, the page uses an iframe that points to this address - http://74.120.127.52/db_browse/leagueage/index.asp. Which is weird that it’s not under the littleleague.org domain. It’s also running ASP which is likely where the bad code is written.

I wonder what else we can find under /db_browse/ …

OK that’s enough for this rabbit hole!