DateTime::Format::CLDR 解析长捷克日期的问题
DateTime::Format::CLDR issues parsing long Czech dates
我正在尝试使用 DateTime::Locale::cs_CZ
指定的 CLDR 长格式解析捷克语日期。我看不出它应该失败的明显原因。
my $locale2 = DateTime::Locale->load('cs_CZ');
my $cldr5 = DateTime::Format::CLDR->new(
pattern => $locale2->date_format_long,
locale => $locale2,
);
print $cldr5->pattern, "\n";
print $cldr5->parse_datetime('17. listopad 1989');
输出为
d. MMMM y
Use of uninitialized value in print at ./test-cldr.pl line 54.
我做错了什么?为什么它不解析日期?
更新
这是我实际用来在命令行上测试的内容:
perl -MData::Dumper -MDateTime -MDateTime::Format::CLDR -wle'
local $SIG{__DIE__} = sub { print( Carp::longmess (shift) ); };
$x="19. září 1979";
my $loc = DateTime::Locale->load("cs_CZ");
print Dumper($loc), "\n";
my $cldr = DateTime::Format::CLDR->new(
pattern=>$loc->date_format_long, locale=>$loc, on_error => "croak");
print Dumper($cldr->parse_datetime($x));
'
这是我得到的输出:
$VAR1 = bless( {
'en_language' => 'Czech',
'native_territory' => "\x{10c}esk\x{e1} republika",
'en_territory' => 'Czech Republic',
'native_language' => "\x{10d}e\x{161}tina",
'default_time_format_length' => 'medium',
'id' => 'cs_CZ',
'native_complete_name' => "\x{10d}e\x{161}tina \x{10c}esk\x{e1} republika",
'default_date_format_length' => 'medium',
'en_complete_name' => 'Czech Czech Republic'
}, 'DateTime::Locale::cs_CZ' );
Could not get datetime for 19. září 1979 (Error marked by 'HERE-->'): '19. HERE-->září 1979' at -e line 7.
at /usr/share/perl5/DateTime/Format/CLDR.pm line 965.
DateTime::Format::CLDR::_local_croak(DateTime::Format::CLDR=HASH(0x166bcd8), "Could not get datetime for 19. z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad} 1979 (Error marked by "...) called at /usr/share/perl5/DateTime/Format/CLDR.pm line 558
DateTime::Format::CLDR::__ANON__("z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad} 1979") called at /usr/share/perl5/DateTime/Format/CLDR.pm line 582
DateTime::Format::CLDR::parse_datetime(DateTime::Format::CLDR=HASH(0x166bcd8), "19. z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad} 1979") called at -e line 7
Could not get datetime for 19. září 1979 (Error marked by 'HERE-->'): '19. HERE-->září 1979' at -e line 7.
17。列表 1989
print(Dumper($self->_build_pattern()));
可以一窥模块的期望。在这种情况下它输出以下内容。
$VAR1 = [
[
qr/(3[01]|[12]\d|0?[1-9])/,
'd',
1
],
'\.',
'\s+',
[
"(listopadu|\x{10d}ervence|prosince|b\x{159}ezna|kv\x{11b}tna|\x{10d}ervna|ledna|\x{fa}nora|dubna|srpna|\x{159}\x{ed}jna|z\x{e1}\x{159}\x{ed})",
'M',
4
],
'\s+',
[
qr/(-?\d{1,4})/,
'y',
1
]
];
它期望 listopadu
,而不是 listopad
。我对捷克语一无所知,但模块的行为似乎是 correct。您可以 "fix up" 在解析它们之前的日期。
$date_string =~ s/\blistopad\b\K/u/;
19。扎日 1979
你实际上并没有超过 září
("z\x{e1}\x{159}\x{ed}"
)。您正在传递其 UTF-8 编码 ("z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad}"
)。添加 use utf8;
以告诉 Perl 源代码使用 UTF-8 编码。
我正在尝试使用 DateTime::Locale::cs_CZ
指定的 CLDR 长格式解析捷克语日期。我看不出它应该失败的明显原因。
my $locale2 = DateTime::Locale->load('cs_CZ');
my $cldr5 = DateTime::Format::CLDR->new(
pattern => $locale2->date_format_long,
locale => $locale2,
);
print $cldr5->pattern, "\n";
print $cldr5->parse_datetime('17. listopad 1989');
输出为
d. MMMM y
Use of uninitialized value in print at ./test-cldr.pl line 54.
我做错了什么?为什么它不解析日期?
更新
这是我实际用来在命令行上测试的内容:
perl -MData::Dumper -MDateTime -MDateTime::Format::CLDR -wle'
local $SIG{__DIE__} = sub { print( Carp::longmess (shift) ); };
$x="19. září 1979";
my $loc = DateTime::Locale->load("cs_CZ");
print Dumper($loc), "\n";
my $cldr = DateTime::Format::CLDR->new(
pattern=>$loc->date_format_long, locale=>$loc, on_error => "croak");
print Dumper($cldr->parse_datetime($x));
'
这是我得到的输出:
$VAR1 = bless( {
'en_language' => 'Czech',
'native_territory' => "\x{10c}esk\x{e1} republika",
'en_territory' => 'Czech Republic',
'native_language' => "\x{10d}e\x{161}tina",
'default_time_format_length' => 'medium',
'id' => 'cs_CZ',
'native_complete_name' => "\x{10d}e\x{161}tina \x{10c}esk\x{e1} republika",
'default_date_format_length' => 'medium',
'en_complete_name' => 'Czech Czech Republic'
}, 'DateTime::Locale::cs_CZ' );
Could not get datetime for 19. září 1979 (Error marked by 'HERE-->'): '19. HERE-->září 1979' at -e line 7.
at /usr/share/perl5/DateTime/Format/CLDR.pm line 965.
DateTime::Format::CLDR::_local_croak(DateTime::Format::CLDR=HASH(0x166bcd8), "Could not get datetime for 19. z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad} 1979 (Error marked by "...) called at /usr/share/perl5/DateTime/Format/CLDR.pm line 558
DateTime::Format::CLDR::__ANON__("z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad} 1979") called at /usr/share/perl5/DateTime/Format/CLDR.pm line 582
DateTime::Format::CLDR::parse_datetime(DateTime::Format::CLDR=HASH(0x166bcd8), "19. z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad} 1979") called at -e line 7
Could not get datetime for 19. září 1979 (Error marked by 'HERE-->'): '19. HERE-->září 1979' at -e line 7.
17。列表 1989
print(Dumper($self->_build_pattern()));
可以一窥模块的期望。在这种情况下它输出以下内容。
$VAR1 = [
[
qr/(3[01]|[12]\d|0?[1-9])/,
'd',
1
],
'\.',
'\s+',
[
"(listopadu|\x{10d}ervence|prosince|b\x{159}ezna|kv\x{11b}tna|\x{10d}ervna|ledna|\x{fa}nora|dubna|srpna|\x{159}\x{ed}jna|z\x{e1}\x{159}\x{ed})",
'M',
4
],
'\s+',
[
qr/(-?\d{1,4})/,
'y',
1
]
];
它期望 listopadu
,而不是 listopad
。我对捷克语一无所知,但模块的行为似乎是 correct。您可以 "fix up" 在解析它们之前的日期。
$date_string =~ s/\blistopad\b\K/u/;
19。扎日 1979
你实际上并没有超过 září
("z\x{e1}\x{159}\x{ed}"
)。您正在传递其 UTF-8 编码 ("z\x{c3}\x{a1}\x{c5}\x{99}\x{c3}\x{ad}"
)。添加 use utf8;
以告诉 Perl 源代码使用 UTF-8 编码。