NAME
DateTime::Parser - Locale aware Parser for DateTime
SYNOPSIS
$obj = new DateTime::Parser();
OR
$obj = new DateTime::Parser('%d. %B %Y');
OR
$obj = new DateTime::Parser('%d. %B %Y','de-AT');
my $date1 = $obj->get_time('5. Oktober 2007');
DESCRIPTON
This module provides a convenient function to parse localized date time stings into DateTime objects. You just need to supply the used locale and a strftime string describing the pattern.
USAGE
new([LOCALE])
my $obj = DateTime::Parser->new();
my $obj = DateTime::Parser->new('%d. %B %Y');
my $obj = DateTime::Parser->new('%d. %B %Y','de-AT');
my $locale = DateTime::Locale->get_locale('de-AT');
my $obj = Config::Class->new('%d. %B %Y',$locale);
Creates a DateTime::Parser object and returns it. Takes the strftime format string and the locale as an optional argument. If no locale is provided it will be taken from DateTime-
DefaultLocale()>. If the format string is omitted then the medium_date_format
from the currently used locale will be used.
The locale may be a DateTime::Locale object or a locale name as supplied to DateTime::Locale-
get_locale>
get_locale()
Returns the currently used DateTime::Locale object.
set_locale(LOCALE)
Sets the currently used locale. Accepts the name of the locale or a DateTime::Locale object.
set_pattern(PATTERN)
Sets the pattern. The format string can be any string containing DateTime "strftime Specifiers"
get_time(TIMESTRING)
my $datetime = $obj->get_time('5. Oktober 2007')
Parses the given datetime strings and returns a datetime object. If the string cannot be parsed the method returns undef.
strftime Specifiers
This module can parse all existing strftime specifiers and also a couple of method specifiers (%{method_name}
), but it can only use some of them to construct a DateTime object, since not all specifiers are easily (or event at all) reversible.
Supported DateTime Methods
* item ce_year * item year * item month, mon * item day,mday * item hour * item minute * item second * item time * item ymd * item mdy * item dmy * item month_name * item month_abbr * item day_name * item day_abbr * item hour_12 * item quarter * item quarter_name * item quarter_abbr * item millisecond * item microsecond * item nanosecond * item datetime * item iso8601 * item hms * item offset * item epoch * item time_zone_long_name
Unsupported DateTime Methods
* item era_abbr * item christian_era * item secular_era * item day_of_quarter * item doq * item year_with_era * item year_with_christian_era * item year_with_secular_era * item hour_1 * item hour_12_0 * item fractional_second * item week * item week_year * item week_number * item jd * item mjd * item hires_epoch
Reversible Strftime Specifiers
Only the specifiers clearly indicating a single time zone, year, month, day, hour, minute, second or nanosecond can be used to construct a DateTime object. Time using the 1-12 hour range is fine as long the %P (or %p) sepecifier is used.
Sanity Checks
Although the module cannot construct a date from a weekday, quarter or week number it used this data to perform sanity checks. The module will throw an exception if a 'Tuesday, October 1, 2007' will be parsed since this day was a Monday.
Sanity checks are performed on all specifiers clearly indicating a week number, quarter, weekday or day of year. They are not performed on week of month, week year, day of quarter values.
KNOWN BUGS & LIMITATIONS
This module can only work with dates from the current and last millennium. This could be changed if deemed necessary.
AUTHOR
Maroš Kollár
CPAN ID: MAROS
maros [at] k-1.com
http://www.k-1.com
COPYRIGHT
DateTime::Parser is Copyright (c) 2006,2007 Maroš Kollár. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
SEE ALSO
The DateTime module by Dave Rolsky.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 597:
Non-ASCII character seen before =encoding in 'Maroš'. Assuming CP1252