1Date::Extract(3)      User Contributed Perl Documentation     Date::Extract(3)
2
3
4

NAME

6       Date::Extract - Extract probable dates from strings
7

VERSION

9       version 0.07
10

SYNOPSIS

12           my $parser = Date::Extract->new();
13           my $dt = $parser->extract($arbitrary_text)
14               or die "No date found.";
15           return $dt->ymd;
16

MOTIVATION

18       There are already a few modules for getting a date out of a string.
19       DateTime::Format::Natural should be your first choice. There's also
20       Time::ParseDate which fits many formats. Finally, you can coerce
21       Date::Manip to do your bidding.
22
23       But I needed something that will take an arbitrary block of text,
24       search it for something that looks like a date string, and extract it.
25       This module fills this niche. By design it will produce few false
26       positives. This means it will not catch nearly everything that looks
27       like a date string. So if you have the string "do homework for class
28       2019" it won't return a DateTime object with the year set to 2019. This
29       is what your users would probably expect.
30

METHODS

32   new(PARAMHASH) => "Date::Extract"
33       arguments
34
35       format
36           Choose what format the extracted date(s) will be. The default is
37           "DateTime", which will return DateTime object(s). Other option
38           include "verbatim" (return the original text), or "epoch" (return
39           Unix timestamp).
40
41       time_zone
42           Only relevant when "format" is set to "DateTime".
43
44           Forces a particular time zone to be set (this actually matters, as
45           "tomorrow" on Monday at 11 PM means something different than
46           "tomorrow" on Tuesday at 1 AM).
47
48           By default it will use the "floating" time zone. See the
49           documentation for DateTime.
50
51           This controls both the input time zone and output time zone.
52
53       prefers
54           This argument decides what happens when an ambiguous date appears
55           in the input. For example, "Friday" may refer to any number of
56           Fridays. The valid options for this argument are:
57
58           nearest
59               Prefer the nearest date. This is the default.
60
61           future
62               Prefer the closest future date.
63
64           past
65               Prefer the closest past date. NOT YET SUPPORTED.
66
67       returns
68           If the text has multiple possible dates, then this argument
69           determines which date will be returned. By default it's 'first'.
70
71           first
72               Returns the first date found in the string.
73
74           last
75               Returns the final date found in the string.
76
77           earliest
78               Returns the date found in the string that chronologically
79               precedes any other date in the string.
80
81           latest
82               Returns the date found in the string that chronologically
83               follows any other date in the string.
84
85           all Returns all dates found in the string, in the order they were
86               found in the string.
87
88           all_cron
89               Returns all dates found in the string, in chronological order.
90
91   "extract(text, ARGS) =" dates
92       Takes an arbitrary amount of text and extracts one or more dates from
93       it. The return value will be zero or more dates, which by default are
94       DateTime objects (but can be customized with the "format" argument). If
95       called in scalar context, only one will be returned, even if the
96       "returns" argument specifies multiple possible return values.
97
98       See the documentation of "new" for the configuration of this method.
99       Any arguments passed into this method will trump those from the
100       constructor.
101
102       You may reuse a parser for multiple calls to "extract".
103
104       You do not need to have an instantiated "Date::Extract" object to call
105       this method. Just "Date::Extract->extract($foo)" will work.
106

FORMATS HANDLED

108       •   "today"; "tomorrow"; "yesterday"
109
110       •   "last Friday"; "next Monday"; "previous Sat"
111
112       •   "Monday"; "Mon"
113
114       •   "November 13th, 1986"; "Nov 13, 1986"
115
116       •   "13 November 1986"; "13 Nov 1986"
117
118       •   "November 13th"; "Nov 13"
119
120       •   "13 Nov"; "13th November"
121
122       •   "1986/11/13"; "1986-11-13"
123
124       •   "11-13-86"; "11/13/1986"
125

CAVEATS

127       This module is intentionally very simple. Surprises are not welcome
128       here.
129

SEE ALSO

131       DateTime::Format::Natural, Time::ParseDate, Date::Manip
132

ACKNOWLEDGEMENTS

134       Thanks to Steven Schubiger for writing the fine
135       DateTime::Format::Natural.  We still use it, but it doesn't quite fill
136       all the particular needs we have.
137

SUPPORT

139       Bugs may be submitted through the RT bug tracker
140       <https://rt.cpan.org/Public/Dist/Display.html?Name=Date-Extract> (or
141       bug-Date-Extract@rt.cpan.org <mailto:bug-Date-Extract@rt.cpan.org>).
142
143       I am also usually active on irc, as 'ether' at "irc.perl.org" and
144       "irc.libera.chat".
145

AUTHOR

147       Shawn M Moore, <sartak@gmail.com>
148

CONTRIBUTORS

150       •   Karen Etheridge <ether@cpan.org>
151
152       •   Steven Haryanto <stevenharyanto@gmail.com>
153
154       •   Jim Brandt <jbrandt@bestpractical.com>
155
156       •   Alex Vandiver <alex@chmrr.net>
157
158       •   Jesse Vincent <jesse@bestpractical.com>
159
160       •   Thomas Sibley <trs@bestpractical.com>
161
163       This software is copyright (c) 2007 by Best Practical Solutions.
164
165       This is free software; you can redistribute it and/or modify it under
166       the same terms as the Perl 5 programming language system itself.
167
168
169
170perl v5.36.0                      2023-01-20                  Date::Extract(3)
Impressum