I'd love to know if there is a module to parse "human formatted" dates in Perl. I mean things like "tomorrow", "Tuesday", "next week", "1 hour ago".
My research with CPAN suggest that there is no such module, so how would you go about creating one? NLP is way over the top for this.
Date::Manip does exactly this.
Here is an example program:
Which results in the following output:
UnixDate is one of the functions provided by
Date::Manip
, the first argument is a date/time in any format that the module supports, the second argument describes how to format the date/time. There are other functions that just parse these "human" dates, without formatting them, to be used in delta calculations, etc.you may also find it interesting to look at the
DateTime::Format
family, specifically DateTime::Format::Natural. once you've parsed your date/time into a DateTime object, you can manipulate and evaluate it in a whole bunch of different ways.here's a sample program:
output:
TMTOWTDI :)
-steve
Personally, I've always used Time::ParseDate for this. It understands pretty much every format I've tried.
Absolute date formats
Relative date formats:
Absolute time formats:
Relative time formats:
Timezone formats:
Special formats:
I assume you have context. how could NLP help here ? as a wild guess you could just find the nearest date that is an exact date(not relative to today) and use today/tommorow/yesterday to relate to that.