26 Jan 2013 09:46:51 UTC
- Distribution: Date-PeriodParser
- Module version: 0.17
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (18 / 687 / 34)
- KwaliteeBus factor: 1
- 92.80% Coverage
- License: unknown
- Activity24 month
- Download (14.21KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionMCMAHON Joe McMahon
- 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::PeriodParserprovides 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_periodattempts 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.orgMajor contributions by Michael Hendrix (email@example.com) (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.
Module Install Instructions
To install Date::PeriodParser, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Date::PeriodParser
For more information on module installation, please visit the detailed CPAN module installation guide.