![]() |
![]()
| ![]() |
![]()
NAMEDate::Extract - Extract probable dates from strings VERSIONversion 0.07 SYNOPSISmy $parser = Date::Extract->new(); my $dt = $parser->extract($arbitrary_text) or die "No date found."; return $dt->ymd; MOTIVATIONThere are already a few modules for getting a date out of a string. DateTime::Format::Natural should be your first choice. There's also Time::ParseDate which fits many formats. Finally, you can coerce Date::Manip to do your bidding. But I needed something that will take an arbitrary block of text, search it for something that looks like a date string, and extract it. This module fills this niche. By design it will produce few false positives. This means it will not catch nearly everything that looks like a date string. So if you have the string "do homework for class 2019" it won't return a DateTime object with the year set to 2019. This is what your users would probably expect. METHODSnew(PARAMHASH) => "Date::Extract"arguments
"extract(text, ARGS) =" datesTakes an arbitrary amount of text and extracts one or more dates from it. The return value will be zero or more dates, which by default are DateTime objects (but can be customized with the "format" argument). If called in scalar context, only one will be returned, even if the "returns" argument specifies multiple possible return values. See the documentation of "new" for the configuration of this method. Any arguments passed into this method will trump those from the constructor. You may reuse a parser for multiple calls to "extract". You do not need to have an instantiated "Date::Extract" object to call this method. Just "Date::Extract->extract($foo)" will work. FORMATS HANDLED
CAVEATSThis module is intentionally very simple. Surprises are not welcome here. SEE ALSODateTime::Format::Natural, Time::ParseDate, Date::Manip ACKNOWLEDGEMENTSThanks to Steven Schubiger for writing the fine DateTime::Format::Natural. We still use it, but it doesn't quite fill all the particular needs we have. SUPPORTBugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Date-Extract> (or bug-Date-Extract@rt.cpan.org <mailto:bug-Date-Extract@rt.cpan.org>). I am also usually active on irc, as 'ether' at "irc.perl.org" and "irc.libera.chat". AUTHORShawn M Moore, <sartak@gmail.com> CONTRIBUTORS
COPYRIGHT AND LICENCEThis software is copyright (c) 2007 by Best Practical Solutions. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
|