File: format-with-locale.t

package info (click to toggle)
libdatetime-format-strptime-perl 1.7900-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,812 kB
  • sloc: perl: 1,400; sh: 23; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 645 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;

use Test::More 0.96;
use Test::Fatal;

use DateTime::Format::Strptime;
use DateTime;

my $code_meth = DateTime::Locale->load('en')->can('code') ? 'code' : 'id';

my $strptime = DateTime::Format::Strptime->new(
    pattern  => '%B %Y',
    locale   => 'pt',
    on_error => 'croak',
);

my $dt = DateTime->new(
    year   => 2015,
    month  => 8,
    locale => 'en',
);

is(
    $strptime->format_datetime($dt),
    'agosto 2015',
    'formatted output is in locale of formatter (Portugese)'
);

is(
    $dt->locale->$code_meth,
    'en',
    q{formatter leaves DateTime object's locale unchanged}
);

done_testing();