DateTime-Format-Japanese
view release on metacpan or search on metacpan
lib/DateTime/Format/Japanese.pm view on Meta::CPAN
Carp::croak("Invalid input format: Year $g_year is after the end of era " . $era->id);
} elsif ($g_year == $era->end->year) {
if ($era->start->month < $args{parsed}->{month}) {
Carp::croak("Invalid input format: Month " .
$era->id .
" is after the end of era '$era_name'");
} elsif ($era->start->day >= $args{parsed}->{day}) {
Carp::croak("Invalid input format: Day " .
$era->id .
" is after the end of era '$era_name'");
}
}
$args{parsed}->{year} = $g_year;
1;
}
require DateTime::Format::Builder;
DateTime::Format::Builder->create_class(
parsers => {
parse_datetime => [
$parse_with_era, $parse_gregorian, $parse_gregorian_bc
]
}
);
1;
__END__
=head1 NAME
DateTime::Format::Japanese - A Japanese DateTime Formatter
=head1 SYNOPSIS
use DateTime::Format::Japanese;
my $fmt = DateTime::Format::Japanese->new();
# or if you want to set options,
my $fmt = DateTime::Format::Japanese->new(
number_format => FORMAT_KANJI,
year_format => FORMAT_ERA,
with_gregorian_marker => 1,
with_bc_marker => 1,
with_ampm_marker => 1,
with_day_of_week => 1,
input_encoding => $enc_name,
output_encoding => $enc_name
);
my $str = $fmt->format_datetime($dt);
my $dt = $fmt->parse_datetime("å¹³æï¼ï¼å¹´ï¼æï¼ï¼æ¥ååï¼æï¼ï¼å");
=head1 DESCRIPTION
This module implements a DateTime::Format module that can read Japanese
date notations and create a DateTime object, and vice versa.
All formatting methods will return a decoded utf-8 string, unless otherwise
specified explicitly via the output_encoding parameter.
All parsing methods expect a decoded utf-8 string, unless otherwise specified
explicitly via the input_encoding parameter
=head1 METHODS
=head2 new()
This constructor will create a DateTime::Format::Japanese object.
You may optionally pass any of the following parameters:
number_format - how to format numbers (default: FORMAT_KANJI)
year_format - how to format years (default: FORMAT_ERA)
with_day_of_week - include day of week (default: 0)
with_gregorian_marker - use gregorian marker (default: 0)
with_bc_marker - use B.C. marker (default: 0)
with_am_marker - use A.M/P.M marker (default: 0)
input_encoding - encoding of input strings for parsing (default: utf8)
output_encoding - encoding of output strings for formatting (default: utf8)
Please note that all of the above parameters only take effect for
I<formatting>, and not I<parsing>, except for input_encoding. Parsing
is done in a way such that it accepts any of the known formats that
this module can produce.
=head2 $fmt-E<gt>parse_datetime($string)
This function will parse a Japanese date/time string and convert it to a
DateTime object. If the parsing is unsuccessful, it will croak.
Note that if you didn't provide a input_encoding parameter, the given
string is assumed to be decoded utf-8.
This function should be able to parse almost all of the common Japanese
date notations, whether they are written using ascii numerals, double byte
numerals, and kanji numerals. The date components (year, month, day or
era name, era year, month, day) must be present in the string. The time
components are optional.
This method can be called as a class function as well.
my $dt = DateTime::Format::Japanese->parse_datetime($string);
# or
my $fmt = DateTime::Format::Japanese->new();
my $fmt->parse_datetime($string);
=head1 FORMATTING METHODS
All of the following methods accept a single parameter, a DateTime object,
and return the appropriate string representation.
my $dt = DateTime->now();
my $fmt = DateTime::Format::Japanese->new(...);
my $str = $fmt->format_datetime($dt);
=head2 $fmt-E<gt>format_datetime($dt)
Create a complete string representation of a DateTime object in Japanese.
=head2 $fmt-E<gt>format_ymd($dt)
Create a string representation of year, month, and date of a DateTime
object in Japanese
=head2 $fmt-E<gt>format_year($dt)
Create a string representation of the year of a DateTime object in Japanese
=head2 $fmt-E<gt>format_month($dt)
Create a string representation of the month of a DateTime object in Japanese
=head2 $fmt-E<gt>format_day($dt)
Create a string representation of the day (day of month) of a DateTime object
in Japanese
=head2 $fmt-E<gt>format_day_of_week($dt)
Create a string representation of the day of week of a DateTime object in
Japanese
=head2 $fmt-E<gt>format_time($dt)
Create a string representation of the time (hour, minute, second) of a DateTime object in Japanese
=head2 $fmt-E<gt>format_hour($dt)
Create a string representation of the hour of a DateTime object in Japanese
=head2 $fmt-E<gt>format_minute($dt)
( run in 2.180 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )