Maroš Kollár > DateTime-Format-CLDR-1.08 > DateTime::Format::CLDR

Download:
DateTime-Format-CLDR-1.08.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 1.80.0   Source   Latest Release: DateTime-Format-CLDR-1.09

NAME ^

DateTime::Format::CLDR - Parse and format CLDR time patterns

SYNOPSIS ^

    use DateTime::Format::CLDR;
    
    my $cldr = new DateTime::Format::CLDR(
        pattern     => 'HH:mm:ss',
        locale      => 'de_AT',
        time_zone   => 'Europe/Vienna',
    );
    
    my $dt = $cldr->parse_datetime('23:16:42');
    
    $cldr->format_datetime($dt);
    # 23:16:42
    
    # Get pattern from selected locale
    my $cldr = new DateTime::Format::CLDR(
        locale      => 'de_AT',
    );
    
    # pattern is taken from 'date_format_medium' in DateTime::Locale::de_AT
    my $dt = $cldr->parse_datetime('23.11.2007');
    
    # Croak when things go wrong:
    my $cldr = new DateTime::Format::CLDR(
        locale      => 'de_AT',
        on_error    => 'croak',
    );
    
    # This will croak
    $cldr->parse_datetime('23.33.2007');

DESCRIPTION ^

This module provides a parser (and also a formater) for datetime strings using patterns as defined by the Unicode CLDR Project (Common Locale Data Repository). http://unicode.org/cldr/.

CLDR format is supported by DateTime and DateTime::Locale starting with version 0.40.

METHODS ^

Constructor

new

 DateTime::Format::CLDR->new(%PARAMS);

The following parameters are used by DateTime::Format::CLDR:

Accessors

pattern

Get/set pattern. See "CLDR Patterns" in DateTime for details about patterns.

time_zone

Get/set time_zone. Returns a DateTime::TimeZone object.

Accepts either a timezone name or a DateTime::TimeZone object.

locale

Get/set a locale. Returns a DateTime::Locale object.

Accepts either a locale name or a DateTime::Locale::* object.

on_error

Get/set the error behaviour.

Accepts the following values

incomplete

Set the behaviour how to handle incomplete Date information.

Accepts the following values

Public Methods

parse_datetime

 my $datetime = $cldr->parse_datetime($string);

Parses a string and returns a DateTime object on success (If you provide incomplete data and set the incomplete attribute accordingly it will return a DateTime::Incomplete object). If the string cannot be parsed an error will be thrown (depending on the on_error attribute).

format_datetime

 my $string = $cldr->format_datetime($datetime);

Formats a DateTime object using the set locale and pattern. (not the time_zone)

errmsg

 my $string = $cldr->errmsg();

Stores the last error message. Usefull if the on_error behavior of the object is 'undef', so you can work out why things went wrong.

Exportable functions

There are no methods exported by default, however the following are available:

cldr_format

 &cldr_format($pattern,$datetime);

cldr_parse

 &cldr_format($pattern,$string);
 OR
 &cldr_format($pattern,$string,$locale);

Default locale is 'en'.

CLDR PATTERNS ^

Parsing

Some patterns like day of week, quarter, ect. cannot be used to construct a date. However these patterns can be parsed, and a warning will be issued if they do not match the parsed date.

Ambigous patterns (eg. narrow day of week formats for many locales) will be parsed but ignored in datetime calculation.

Supported CLDR Patterns

See "CLDR Patterns" in DateTime.

CLDR provides the following pattenrs:

CAVEATS ^

y and y{3} patterns can only parse four digit years (1000 -> 9999)

Patterns without separators (like 'dMy' or 'yMd') are ambigous for some dates and might fail.

Quote from the Author of DateTime::Format::Strptime which also applies to this module:

 "If your module uses this module to parse a known format: stop it. This module 
 is clunky and slow because it can parse almost anything. Parsing a known 
 format is not so difficult, is it? You'll make your module faster if you do. 
 And you're not left at the whim of my potentially broken code."

SUPPORT ^

Please report any bugs or feature requests to datetime-format-cldr@rt.cpan.org, or through the web interface at http://rt.cpan.org/Public/Bug/Report.html?Queue=DateTime::Format::CLDR. I will be notified and then you'll automatically be notified of the progress on your report as I make changes.

AUTHOR ^

    Maroš Kollár
    CPAN ID: MAROS
    maros [at] k-1.com
    
    L<http://www.revdev.at>

ACKNOWLEDGEMENTS ^

This module was written for Revdev http://www.revdev.at, a nice litte software company I run with Koki and Domm (http://search.cpan.org/~domm/).

COPYRIGHT ^

DateTime::Format::CLDR is Copyright (c) 2008 Maroš Kollár - http://www.revdev.at

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 ^

datetime@perl.org mailing list

http://datetime.perl.org/

DateTime, DateTime::Locale, DateTime::TimeZone and DateTime::Format::Strptime