File: 003_every.t

package info (click to toggle)
libdatetime-format-strptime-perl 1.5600-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 284 kB
  • ctags: 15
  • sloc: perl: 1,453; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 2,762 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# t/002_basic.t - check module dates in various formats

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

{
    my $object = DateTime::Format::Strptime->new(
        pattern    => '%D',
        time_zone  => 'America/New_York',
        locale     => 'en_US',
        diagnostic => 0,
    );

    my $epoch = DateTime->new(
        year      => 2003, month  => 11, day    => 5,
        hour      => 23,   minute => 34, second => 45,
        time_zone => 'America/New_York'
    )->epoch;

    my @tests = (

        # Compound Patterns
        [ '%T', '23:34:45',    '24-hour Time' ],
        [ '%r', '11:34:45 PM', '12-hour Time' ],
        [ '%R', '23:34',       'Simple 24-hour Time' ],
        [ '%D', '11/30/03',    'American Style Date' ],
        [ '%F', '2003-11-30',  'ISO Style Date' ],

        [
            '%a %b %B %C %d %e %h %H %I %j %k %l %m %M %n %N %O %p %P %S %U %u %w %W %y %Y %s %G %g %z %Z %%Y %%',
            "Wed Nov November 20 05  5 Nov 23 11 309 23 11 11 34 \n 123456789 America/New_York PM pm 45 44 3 3 44 03 2003 $epoch 2003 03 -0500 EST %Y %",
            "Every token at once"
        ],

        [ '%{year}', '2003', 'Extended strftime %{} matching' ],

    );

    foreach (@tests) {
        my ( $pattern, $data, $name ) = @$_;
        $name ||= $pattern;

        $object->pattern($pattern);

        is( $object->format_datetime( $object->parse_datetime($data) ), $data,
            $name );
    }
}

{
    my $object = DateTime::Format::Strptime->new(
        pattern    => '%D',
        time_zone  => 'America/New_York',
        locale     => 'en_US',
        diagnostic => 0,
    );

    my $epoch = DateTime->new(
        year      => 2003, month  => 11, day    => 5,
        hour      => 23,   minute => 34, second => 45,
        time_zone => 'America/New_York'
    )->epoch;

    my @tests = (

        # Compound Patterns
        [ '%T', '23:34:45',    '24-hour Time' ],
        [ '%r', '11:34:45 PM', '12-hour Time' ],
        [ '%R', '23:34',       'Simple 24-hour Time' ],
        [ '%D', '11/30/03',    'American Style Date' ],
        [ '%F', '2003-11-30',  'ISO Style Date' ],

        [
            '%a %b %B %C %d %e %h %H %I %j %k %l %m %M %n %N %p %P %S %U %u %w %W %y %Y %s %G %g %z %Z %%',
            "Wed Nov November 20 05  5 Nov 23 11 309 23 11 11 34 \n 123456789 PM pm 45 44 3 3 44 03 2003 $epoch 2003 03 -0500 EST %",
            "Every token at once"
        ],

        [ '%{year}', '2003', 'Extended strftime %{} matching' ],

    );

    foreach (@tests) {
        my ( $pattern, $data, $name ) = @$_;
        $name ||= $pattern;
        $object->pattern($pattern);
        is( $object->format_datetime( $object->parse_datetime($data) ), $data,
            $name );
    }
}

done_testing();