Natural Language Date Parser

Came across a situation where I needed to parse strings as dates, string likes “yesterday” “last week” and so on.

First thought was to find an existing CF method for this, didn’t exist.  Next was to find a Java class… a couple exist, Natty which seems awesome, but relies too heavily on ANTLR, then there’s JChronic.  Both seemed great, but a little overkill.  Next was to find a JS version, but then I remembered how annoying it was to run server-side javascript using Rhino.

So, I took an hour or two to write this up:

At the moment, it’ll accept things like “(Number or Text) (Day,Week,Month,Quarter,Year) ago” [3 days ago], “last week” “last month” “yesterday” and a few more ways.  Very simple, still needs expanding for “a couple weeks ago” / “a week ago” etc, but for now it works great on simple things, it needs a lil work to make it more versatile.


Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>