DateTime-Format-JP
view release on metacpan or search on metacpan
lib/DateTime/Format/JP.pm view on Meta::CPAN
{
my $opts = {};
@$opts{qw( year month day )} = @$ref;
@$opts{qw( hour minute second )} = (0,0,0);
$opts->{time_zone} = ( HAS_LOCAL_TZ ? 'local' : 'UTC' );
return( DateTime::Lite->new( %$opts ) );
}
else
{
return( DateTime::Lite->now( time_zone => ( HAS_LOCAL_TZ ? 'local' : 'UTC' ) ) );
}
};
if( $@ )
{
return( $self->error( $@ ) );
}
return( $rv );
}
}
1;
# NOTE: POD
__END__
=encoding utf-8
=head1 NAME
DateTime::Format::JP - Japanese DateTime Parser and Formatter
=head1 SYNOPSIS
use DateTime::Format::JP;
my $fmt = DateTime::Format::JP->new(
hankaku => 1,
pattern => '%c', # default
traditional => 0,
kanji_number => 0,
zenkaku => 0,
time_zone => 'local',
);
my $dt = DateTime->now or DateTime::Lite->now;
$dt->set_formatter( $fmt );
# set the encoding in and out to utf8
use open ':std' => ':utf8';
print "$dt\n"; # will print something like 令å3å¹´7æ12æ¥åå¾2:30:20
my $dt = $fmt->parse_datetime( "令åï¼å¹´ï¼æï¼ï¼æ¥åå¾ï¼æï¼ï¼å" );
my $str = $fmt->format_datetime( $dt );
print "$str\n";
=head1 VERSION
v0.1.7
=head1 DESCRIPTION
This module is used to parse and format Japanese date and time. It is lightweight and yet versatile.
It implements 2 main methods: L</parse_datetime> and L</format_datetime> both expect and return decoded utf8 string.
You can use L<Encode> to decode and encode from perl internal utf8 representation to real utf8 and vice versa.
=head1 METHODS
=head2 new
The constructor accepts the following parameters:
=over 4
=item I<hankaku> boolean
If true, the digits used will be "half-size" (åè§), or roman numbers like 1, 2, 3, etc.
The opposite is I<zenkaku> (å
¨è§) or full-width. This will enable the use of double-byte Japanese numbers that still look like roman numbers, such as: ï¼, ï¼, ï¼, etc.
Defaults to true.
=item I<pattern> string
The pattern to use to format the date and time. See below the available L</"PATTERN TOKENS"> and their meanings.
Defaults to C<%c>
=item I<traditional> boolean
If true, then it will use a more traditional date/time representation. The effect of this parameter on the formatting is documented in L</"PATTERN TOKENS">
=item I<kanji_number> boolean
If true, this will have L</format_datetime> use numbers in kanji, such as: ä¸, äº, ä¸, å, etc.
=item I<zenkaku> boolean
If true, this will use full-width, ie double-byte Japanese numbers that still look like roman numbers, such as: ï¼, ï¼, ï¼, etc.
=item I<time_zone> string
The time zone to use when creating a L<DateTime::Lite> object. Defaults to C<local> if L<DateTime::Lite::TimeZone> supports it, otherwise it will fallback on C<UTC>
=back
=head2 error
Returns the latest error set, if any.
All method in this module return C<undef> upon error and set an error that can be retrieved with this method.
=head2 format_datetime
Takes a L<DateTime::Lite> or L<DateTime> object and returns a formatted date and time based on the pattern specified, which defaults to C<%c>.
You can call this method directly, or you can set this formatter object in L<DateTime::Lite/set_formatter> so that ie will be used for stringification of the L<DateTime::Lite> object.
See below L</"PATTERN TOKENS"> for the available tokens and their meanings.
=head2 hankaku
Sets or gets the boolean value for I<hankaku>.
( run in 2.883 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )