- SEE ALSO
- COPYRIGHT AND LICENSE
Date::Extract::Surprise - extract probable dates from strings *with surprises*
use Date::Extract::Surprise; my $des = Date::Extract::Surprise->new(); my @datetimes = $des->extract( $arbitrary_text ); # or... use Date::Extract::Surprise; my @datetimes = Date::Extract::Surprise->extract( $arbitrary_text ); # or... use Date::Extract::Surprise qw( extract_datetimes ); my @datetimes = extract_datetimes( $arbitrary_text );
This is modeled on Sartak's excellent Date::Extract, a proven and capable module that you can use to extract references to dates and times from otherwise arbitrary text. For example:
"The package will be delivered at 3:15 PM, March 15, 2007, on the dot."
Upon parsing that, you should end up with a DateTime object representing March 15, 2007 at 3:15PM in your timezone.
Date::Extract is designed to try to minimize "false-positives" (ie. detecting things that *aren't* actually dates or times), but at the expense of potentially missing some dates. As its documentation states, "Surprises are not welcome here."
Because I had the opposite need - to find dates in strings even if some were going to be bogus, I created Date::Extract::Surprise which will gladly detect anything that even remotely looks like it could be a date or time.
Bottom line: at least one of the dates this will 'detect' in some text should be what you wanted. It's up to you to figure out which one that is! :-)
Just your basic object constructor.
my $des = Date::Extract::Surprise->new();
Currently takes only one argument:
This is designed to (more or less) mirror the interface of Date::Extract->extract(). However, at this time, it supports almost none of its namesake's extra options, and adds one additional option.
This can be called as either a class method or as a method on an object, as seen in the SYNOPSIS.
If you're old-skool and prefer things to export a function, you can have it.
It takes the same arguments as the extract method and returns the same values.
It will probably take more in the future.
Yes, this code is slow and dumb, but it helped me solve a problem and I hope it may help others, too. Let me know if you need anything changed!
I'm hoping this will work on perl 5.6 and before, because I want to be helpful to as many people as possible, but I am too lazy to test it myself. Bug reports and/or patches please!
Stephen R. Scaffidi <email@example.com>
This software is copyright (c) 2010 by Stephen R. Scaffidi.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.