Date::PeriodParser - Turns English descriptions into time periods
use Date::PeriodParser; my ($midnight, $midday) = parse_period("this morning"); my ($monday_am, $sunday_pm) = parse_period("this week"); ... parse_period("sometime this afternoon"); ... parse_period("around two weeks ago");
Date::PeriodParser provides a means of interpreting vague descriptions of dates as actual, meaningful date values by taking a shot at interpreting the meaning of the supplied descriptive phrase, generating a best-guess estimate of the time period described.
parse_period attempts to turn the English description of a time period into a pair of Unix epoch times. As a famous man once said, "Of course, this is a heuristic, which is a fancy way of saying that it doesn't work".
Returns full range of dates from the epoch to the latest-possible date (currently "Mon Jan 18 19:14:07 2038").
Returns the current date and time.
Supported, with "the day before" and "the day after" accepted as modifiers. This means you can say relatively meaningless things like "the day after yesterday" and "the day before tomorrow", but they work.
These are all supported with "this" and "in the" as modifiers; relative times specified with "in the" (for morning, afternoon, and evening) disambiguate relative to the current time. For instance, if it's afternoon and "in the morning" is specified, this implies "tomorrow morning".
"This" means the week or month which includes the current day. Weeks begin on Monday and end of Sunday. "Last" means the week or month preceeding "this week/month".
A month name followed by a four-digit year.
Offsets in days and "a week" are accepted; you cannot cross a month boundary in this release.
Offsets in days are supported; again, crossing month boundaries does not yet work.
If you enter something it can't parse, it'll return an error code and an explanation instead of two epoch time values. Error code -1 means "You entered gibberish", error code -2 means "you entered something ambiguous", and the explanation will tell you how to disambiguate it.
Any of the phrases that use an English word for a number require that Lingua::EN::Words2Nums be installed. If those phrases are not used, the module is optional.
Used to do all that messy date math.
Parsing is limited. Some relatively complicated things work fine, but some simple things do not.
email@example.com Joe McMahon,
firstname.lastname@example.org Major contributions by Michael Hendrix (email@example.com) (Thanks!)
Copyright (C) 2002 by Simon Cozens; Copyright (c) 2005-2007 by Joe McMahon
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.