erlware/erlware_commons — pull request #34 by choptastic (2013-02-18 04:10:19+00:00)
Title: Disambiguate parsing "Aug 12" and "12 Aug", tag "Hinted Months", Also fix ordinal suffixes for 21-23 and 31.

I'm sorry for the pull request from out of the blue:

This started with just trying to parse the date format:

December 21st, 2013 7:00pm, which was failing with a bad_date error.

The solution involved setting up "Hinted Months", which was just a term
I used to indicate that a month was specified by name (ie "December"),
rather than by number (ie, "12"). Previously, named months were simply
replaced by their respective numbers in the parser. This tags those
named months so that the parser will unambiguously parse them correctly.

A tagged "Hinted Month" is simply a tuple with the tag `?MONTH_TAG`. For
example: "December" gets converted to `{?MONTH_TAG, 12}`

For example: "Aug 12" and "12 Aug". It's clear to the *reader* what is
meant, but when converted to simply 8 and 12, the parser has no way of
knowing which is which.

Doing this was aided with the addition of some macros to help it
along, since doing just straight comparisons with the hinted months was
yielding unexpected results. For example: `{mon, 1} > 31` returns
true, so changing that comparison to an ?is_year/1 macro that does:
`is_integer(Y) andalso Y > 31`.

It might not be a bad idea to help the parser be *very* unambiguous by
putting these macros on all comparisons.

Also, while I realize this should probably be a separate PR since it's a completely separate issue, this includes a simple fix fixing the ordinal suffixes for 21, 22, 23, and 31 (which previously all did "th")

Thanks. Please let me know if anything needs changing, or doesn't live up to some coding standards or expectations.

-Jesse