jquery/globalize — pull request #270 by rxaviers (2014-05-31 19:51:13+00:00)
Title: Date: Parse date within month's boundaries when needed

Fix #269

Date parsing has a component based on today's context. So, it properly parses stuff like `"Jan 1st"` into the Jan 1st of the current year; or `"12:00pm"` into 12:00pm of today.

It happens that if today is "May 31" and we want to parse "Sep 15, 2010", the parsing algorithm first creates a date instance of today/now. Then, as a next step, it sets this date to "Sep". Although, "Sep 31" becomes "Oct 1" according to native date.setMonth(). Then, as a next step, it sets the day and year. The final result becomes erroneously a "Oct 15 2010" date instance.

You may be wondering why don't we parse the given string and keep each component in a separate variable, then assemble a date instance using new Date( each component ). Yes, in this case, it's the easiest thing to do. Although, it would make other date patterns harder to parse, eg. `D` (day of year), in which case we do make use of the native date.setDate() feature that correctly adjusts month and date accordingly when a number is bigger than a month's boundaries.

Anyway, considering the above, this fix that takes special care when setting months so the scenario is handled.