File: 004_locale_defaults.t

package info (click to toggle)
libdatetime-format-strptime-perl 1.5600-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 284 kB
  • ctags: 15
  • sloc: perl: 1,453; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!perl -w

# t/004_locale_defaults.t - check module dates in various formats

use utf8;

use Test::More 0.88;
use DateTime::Format::Strptime;
use DateTime;
use DateTime::TimeZone;
use DateTime::Locale;

my $object = DateTime::Format::Strptime->new(
    pattern    => '%c',
    diagnostic => 0,
    on_error   => sub { warn @_ },
);

my @tests = (

    # Australian English
    [ 'en_AU', '%x', '31/12/98' ],
    [ 'en_AU', '%X', '13:34:56' ],
    [ 'en_AU', '%c', 'Thu 31 Dec 1998 13:34:56 AEDT' ],

    # US English
    [ 'en_US', '%x', '12/31/1998' ],
    [ 'en_US', '%X', '01:34:56 PM' ],
    [ 'en_US', '%c', 'Thu 31 Dec 1998 01:34:56 PM MST' ],

    # UK English
    [ 'en_GB', '%x', '31/12/98' ],
    [ 'en_GB', '%X', '13:34:56' ],
    [ 'en_GB', '%c', 'Thu 31 Dec 1998 13:34:56 GMT' ],

    # French French
    [ 'fr_FR', '%x', '31/12/1998' ],
    [ 'fr_FR', '%X', '13:34:56' ],
    [ 'fr_FR', '%c', 'jeu. 31 Déc 1998 13:34:56 CEST' ],

    # French Generic - inherits from root locale for glibc formats
    [ 'fr', '%x', '12/31/98' ],
    [ 'fr', '%X', '13:34:56' ],
    [ 'fr', '%c', 'jeu. Déc 31 13:34:56 1998' ],
);

foreach (@tests) {
    my ( $locale, $pattern, $data ) = @$_;
    $object->locale($locale);
    $object->pattern($pattern);
    my $datetime = $object->parse_datetime($data);

    unless ($datetime) {
        fail("Could not parse $data with $pattern for $locale") for 1..3;
        next;
    }

    if ( $pattern eq '%x' or $pattern eq '%c' ) {
        is( $datetime->year,  1998, $locale . ' : ' . $pattern . ' : year' );
        is( $datetime->month, 12,   $locale . ' : ' . $pattern . ' : month' );
        is( $datetime->day,   31,   $locale . ' : ' . $pattern . ' : day' );
    }
    if ( $pattern eq '%X' or $pattern eq '%c' ) {
        is( $datetime->hour,   13, $locale . ' : ' . $pattern . ' : hour' );
        is( $datetime->minute, 34, $locale . ' : ' . $pattern . ' : minute' );
        is( $datetime->second, 56, $locale . ' : ' . $pattern . ' : second' );
    }
}

done_testing();