- WHAT'S CURRENTLY SUPPORTED
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 before-and-after estimate of the time period described.
parse_period attempts to turn an 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.
today, tomorrow, yesterday
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.
day, morning, lunchtime, afternoon, evening, night
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 week, last week, this month, last month
"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".
january 2007, dec 2005, jul 1982
A month name followed by a four-digit year.
"ago" and "from now"
Offsets in days, weeks, months, and years are accepted.
"in xxx (unit)(s)" and "in xxx (units) time"
Offsets in days, weeks, months, and years are supported.
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.
The time-of-day words ("morning", "afternoon", "evening", "night", and "lunchtime") should accept relative modifiers (e.g., "lunchtime tomorrow", "yesterday evening"), but don't.
The API is much too C-like. We should probably throw a structured exception instead of returning a failure code.
firstname.lastname@example.org Joe McMahon,
email@example.com Major contributions by Michael Hendrix (firstname.lastname@example.org) (Thanks!)
Copyright (C) 2002 by Simon Cozens; Copyright (c) 2005-2013 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.