CatalystX::I18N::Role::DateTime - Support for I18N datetime
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); }
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 }, } }, );
my $dt = $c->i18n_datetime_today say $dt->dmy;
Returns the current date as a DateTime object with the current timezone and locale set.
my $dt = $c->i18n_datetime_now say $dt->hms;
Returns the current timestamp as a DateTime object with the current timezone and locale set.
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.
Returns/sets the current datetime locale as a DateTime::Locale object.
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.
format_date
date_format_medium
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.
format_datetime
datetime_format_medium
DateTime::Format::CLDR, DateTime::Locale, DateTime::TimeZone and DateTime
Maroš Kollár CPAN ID: MAROS maros [at] k-1.com L<http://www.k-1.com>
To install CatalystX::I18N, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::I18N
CPAN shell
perl -MCPAN -e shell install CatalystX::I18N
For more information on module installation, please visit the detailed CPAN module installation guide.