DateTime-Format-Japanese
view release on metacpan or search on metacpan
lib/DateTime/Format/Japanese/Traditional.pm view on Meta::CPAN
DateTime::Format::Japanese::Common::_make_utf8_re(
$HOUR_NO_QUARTER_MARKER);
$RE_HOUR_WITH_QUARTER_MARKER =
DateTime::Format::Japanese::Common::_make_utf8_re(
$HOUR_WITH_QUARTER_MARKER);
$RE_ZODIAC_HOUR = DateTime::Format::Japanese::Common::_make_re( join( '|', map {
DateTime::Format::Japanese::Common::_make_utf8_re_str($_) } @ZODIAC_HOURS) );
}
my %NewValidate = (
output_encoding => { default => 'utf8' },
input_encoding => { default => 'utf8' },
number_format => {
type => SCALAR,
default => FORMAT_KANJI
},
month_format => {
type => SCALAR,
default => FORMAT_NUMERIC_MONTH
},
with_traditional_marker => {
type => BOOLEAN,
default => 1
}
);
sub new
{
my $class = shift;
my %hash = validate(@_, \%NewValidate);
my $self = bless \%hash, $class;
}
sub input_encoding
{
my $self = shift;
my $ret = $self->{input_encoding};
if (@_) {
$self->{input_encoding} = shift;
}
return $ret;
}
sub output_encoding
{
my $self = shift;
my $ret = $self->{output_encoding};
if (@_) {
$self->{output_encoding} = shift;
}
return $ret;
}
sub number_format
{
my $self = shift;
my $current = $self->{number_format};
if (@_) {
my($val) = validate_pos(@_, {
type => SCALAR,
callbacks => {
'is valid number_format' => \&DateTime::Format::Japanese::Common::_valid_number_format
}
});
$self->{number_format} = $val;
}
return $current;
}
sub month_format
{
my $self = shift;
my $current = $self->{month_format};
if (@_) {
my($val) = validate_pos(@_, {
type => SCALAR,
callbacks => {
'is valid month_format' => sub {
$_[0] eq FORMAT_NUMERIC_MONTH ||
$_[0] eq FORMAT_WAREKI_MONTH
}
}
});
$self->{month_format} = $val;
}
return $current;
}
sub with_traditional_marker
{
my $self = shift;
my $current = $self->{with_traditional_marker};
if (@_) {
my($val) = validate_pos(@_, { type => BOOLEAN });
$self->{with_traditional_marker} = $val;
}
return $current;
}
my @FmtBasicValidate = (
{ isa => 'DateTime::Calendar::Japanese' },
);
sub format_datetime
{
my $self = shift;
my ($dt) = validate_pos(@_, @FmtBasicValidate);
return $self->format_ymd($dt) .
$self->format_time($dt);
}
sub format_year
{
my $self = shift;
my ($dt) = validate_pos(@_, @FmtBasicValidate);
my $era_name = $dt->era->name;
my $rv = '';
if ($self->with_traditional_marker) {
$rv .= $DateTime::Format::Japanese::Common::TRADITIONAL_MARKER;
}
$rv .= $era_name .
DateTime::Format::Japanese::Common::_format_number(
$dt->era_year, $self->number_format) .
$DateTime::Format::Japanese::Common::YEAR_MARKER;
return Encode::encode($self->{output_encoding}, $rv);
}
sub format_month
{
my $self = shift;
my ($dt) = validate_pos(@_, @FmtBasicValidate);
my $ret;
if ($self->month_format eq FORMAT_WAREKI_MONTH) {
( run in 0.574 second using v1.01-cache-2.11-cpan-39bf76dae61 )