NAME
CatalystX::I18N::Role::DateTime - Support for I18N datetime
SYNOPSIS
package MyApp::Catalyst;
use Catalyst qw/MyPlugins
+CatalystX::I18N::Role::Base
+CatalystX::I18N::Role::DateTime/;
package MyApp::Catalyst::Controller::Main;
use strict;
use warnings;
use parent qw/Catalyst::Controller/;
sub action : Local {
my ($self,$c) = @_;
$c->stash->{timestamp} = $c->i18n_datetime_format_date->format_datetime($datetime);
}
DESCRIPTION
This role add support for localised datetime to your Catalyst application.
Most methods are lazy. This means that the values will be only calculated upon the first call of the method.
Most settings will be taken from DateTime::Locale but can be overdriven in your Catalyst I18N configuration:
# Add I18N configuration
__PACKAGE__->config(
name => 'MyApp',
I18N => {
default_locale => 'de_AT',
locales => {
'de_AT' => {
timezone => 'Europe/Vienna', # default 'floating'
format_date => 'dd.MM.yyyy', # default date_format_medium from DateTime::Locale
format_datetime => 'dd.MM.yyyy uma HH:mm', # default datetime_format_medium from DateTime::Locale
},
}
},
);
METHODS
i18n_datetime_today
my $dt = $c->i18n_datetime_today
say $dt->dmy;
Returns the current date as a DateTime object with the current timezone and locale set.
i18n_datetime_now
my $dt = $c->i18n_datetime_now
say $dt->hms;
Returns the current timestamp as a DateTime object with the current timezone and locale set.
i18n_datetime_timezone
Returns/sets the current timezone as a DateTime::TimeZone object. The timezone for each locale can be defined in the I18N configuration.
If no timezone is set DateTime::TimeZone::Floating will be used.
i18n_datetime_locale
Returns/sets the current datetime locale as a DateTime::Locale object.
i18n_datetime_format_date
my $date = $c->i18n_datetime_format_date->format_datetime($date);
Returns a DateTime::Format::CLDR object for parsing and printig localised date data.
The format for each locale can either be set via the format_date
coniguration key, or will be taken from the date_format_medium
method in the current DateTime::Locale object.
i18n_datetime_format_datetime
my $datetime = $c->i18n_datetime_format_datetime->format_datetime($datetime);
Returns a DateTime::Format::CLDR object for parsing and printig localised datetime data.
The format for each locale can either be set via the format_datetime
coniguration key, or will be taken from the datetime_format_medium
method in the current DateTime::Locale object.
SEE ALSO
DateTime::Format::CLDR, DateTime::Locale, DateTime::TimeZone and DateTime
AUTHOR
Maroš Kollár
CPAN ID: MAROS
maros [at] k-1.com
L<http://www.k-1.com>