Author image Michael Aquilina

NAME

Date::RangeParser::EN - Parser for plain English date/time range strings

SYNOPSIS

    use Date::RangeParser::EN;

    my $parser = Date::RangeParser::EN->new;
    my ($begin, $end) = $parser->parse_range("this week");

DESCRIPTION

Parses plain-English strings representing date/time ranges

METHODS

new

Returns a new instance of Date::RangeParser::EN.

Takes an optional hash of parameters:

  • datetime_class

    By default, Date::RangeParser::EN returns two DateTime objects representing the beginning and end of the range. If you use a subclass of DateTime (or another module that implements the DateTime API), you may pass the name of this class to use it instead.

  • now_callback

    By default, Date::RangeParser::EN uses DateTime->now to determine the current date/time for calculations. If you need to work with a different time (for instance, if you need to adjust for time zones), you may pass a callback (code reference) which returns a DateTime object.

parse_range

Accepts a string representing a plain-English date range, for instance:

  • today

  • this week

  • the past 2 months

  • next Tuesday

  • two weeks ago

  • the next 3 hours

  • the 3rd of next month

  • the end of this month

Returns two DateTime objects, reprensenting the beginning and end of the range.

TO DO

There's a lot more that this module could handle. A few items that come to mind:

  • allow full words instead of digits ("two weeks ago" vs "2 weeks ago")

  • allow simple, easily-parsable ranges ("1/1/2012-12/31/2012")

  • allow larger ranges ("between last February and this Friday")

DEPENDENCIES

DateTime, Date::Manip

AUTHORS

This module was authored by Grant Street Group (http://grantstreet.com), which was kind enough to give it back to the Perl community.

The CPAN distribution is maintained by Michael Aquilina (aquilina@cpan.org).

COPYRIGHT AND LICENSE

Copyright (C) 2012 Grant Street Group.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.