In Chronic 0.9.1, when parsing Febr 2013 I'm getting a result June 2013. Feb 2013 is parsed fine but Febr 2013 is not.
I think the issue is when the month abvreviation has four letters.
I need to:
- Parse
Febr 2013toFebruary 2013, or - Invalidate
Febr 2013.
To validate a date I use:
Chronic.parse(params[:date]).blank?
Is this a bug? Can I do a work arround? Or, there is a right way to validate this?
Technically it's a bug, but I'm more inclined to call it a hole in their logic. Here's how Chronic::Repeater.scan_for_month_names decides what a month is:
Month names are either three letters, or the entire name.
You could extract that method from the source, modify the patterns to fit your needs, then overwrite that method, along with submitting it as a patch so the tweak gets added to future revisions of the gem. Or, you could modify the incoming string by searching for the three-letter abbreviations at the beginning of a word, and trimming extraneous characters.
OK, here's something to chew on:
Which outputs:
In other words,
jisn't unique, so there isn't a hit.jais unique and is associated withjanuary, as are the rest of theja...tests.fis unique so it hits, as do all the rest of thef...tests.What does
Abbrev.abbrevdo? It breaks the words passed in, into the minimum unique strings used to identify the whole word. Here's what it looks like if I only use four months:Resulting in:
Those make wonderful seed values for a regular expression.
Where did I get
MONTHS_REGEX? Heh... it's some magical Perl code using a little known module called Regexp::Assemble, that I dearly miss in Ruby. It's skanky... no, it's... diabolically good and closely tied to how Perl does things, and makes my head hurt when I read through it, otherwise I'd have ported it.