~ubuntu-branches/ubuntu/wily/libwww-perl/wily

« back to all changes in this revision

Viewing changes to t/base/date.t

  • Committer: Bazaar Package Importer
  • Author(s): Nicholas Bamber
  • Date: 2011-04-02 15:13:32 UTC
  • mfrom: (1.4.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20110402151332-tpkr18gfx51ccjn2
Tags: 6.01-1
* New upstream release 
  - Modules not in the LWP namespace have been made into separate modules
  - In particular IPv6 issues now handled by libnet-http-perl,
    see #306914, (Closes: #614948) 
  - Packages using HTTP::Daemon should declare the appropriate
    dependency on libhttp-daemon-perl | libwww-perl (<< 6).
  - Packages using HTML::Form should declare the appropriate
    dependency on libhtml-form-perl | libwww-perl (<< 6).
  - Other depending packages can safely continue to depend on libwww-perl,
    but in some cases may be able to tighten up their dependencies.
  - LWP::Protocol::https will be split off in the next release
    so now liblwp-protocol-https-perl is Provided.
* Updated dependencies
* New upstream release
* Removed unnecessary versioned dependency on libio-compress-perl
* Patched LWP::Protocol::https to use ca-certificates rather than 
  Mozilla::CA (Closes: #619059)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!perl -w
2
 
 
3
 
use strict;
4
 
use Test;
5
 
 
6
 
plan tests => 133;
7
 
 
8
 
use HTTP::Date;
9
 
 
10
 
require Time::Local if $^O eq "MacOS";
11
 
my $offset = ($^O eq "MacOS") ? Time::Local::timegm(0,0,0,1,0,70) : 0;
12
 
 
13
 
# test str2time for supported dates.  Test cases with 2 digit year
14
 
# will probably break in year 2044.
15
 
my(@tests) =
16
 
(
17
 
 'Thu Feb  3 00:00:00 GMT 1994',        # ctime format
18
 
 'Thu Feb  3 00:00:00 1994',            # same as ctime, except no TZ
19
 
 
20
 
 'Thu, 03 Feb 1994 00:00:00 GMT',       # proposed new HTTP format
21
 
 'Thursday, 03-Feb-94 00:00:00 GMT',    # old rfc850 HTTP format
22
 
 'Thursday, 03-Feb-1994 00:00:00 GMT',  # broken rfc850 HTTP format
23
 
 
24
 
 '03/Feb/1994:00:00:00 0000',   # common logfile format
25
 
 '03/Feb/1994:01:00:00 +0100',  # common logfile format
26
 
 '02/Feb/1994:23:00:00 -0100',  # common logfile format
27
 
 
28
 
 '03 Feb 1994 00:00:00 GMT',    # HTTP format (no weekday)
29
 
 '03-Feb-94 00:00:00 GMT',      # old rfc850 (no weekday)
30
 
 '03-Feb-1994 00:00:00 GMT',    # broken rfc850 (no weekday)
31
 
 '03-Feb-1994 00:00 GMT',       # broken rfc850 (no weekday, no seconds)
32
 
 '03-Feb-1994 00:00',           # VMS dir listing format
33
 
 
34
 
 '03-Feb-94',    # old rfc850 HTTP format    (no weekday, no time)
35
 
 '03-Feb-1994',  # broken rfc850 HTTP format (no weekday, no time)
36
 
 '03 Feb 1994',  # proposed new HTTP format  (no weekday, no time)
37
 
 '03/Feb/1994',  # common logfile format     (no time, no offset)
38
 
 
39
 
 #'Feb  3 00:00',     # Unix 'ls -l' format (can't really test it here)
40
 
 'Feb  3 1994',       # Unix 'ls -l' format
41
 
 
42
 
 "02-03-94  12:00AM", # Windows 'dir' format
43
 
 
44
 
 # ISO 8601 formats
45
 
 '1994-02-03 00:00:00 +0000',
46
 
 '1994-02-03',
47
 
 '19940203',
48
 
 '1994-02-03T00:00:00+0000',
49
 
 '1994-02-02T23:00:00-0100',
50
 
 '1994-02-02T23:00:00-01:00',
51
 
 '1994-02-03T00:00:00 Z',
52
 
 '19940203T000000Z',
53
 
 '199402030000',
54
 
 
55
 
 # A few tests with extra space at various places
56
 
 '  03/Feb/1994      ',
57
 
 '  03   Feb   1994  0:00  ',
58
 
);
59
 
 
60
 
my $time = (760233600 + $offset);  # assume broken POSIX counting of seconds
61
 
for (@tests) {
62
 
    my $t;
63
 
    if (/GMT/i) {
64
 
        $t = str2time($_);
65
 
    }
66
 
    else {
67
 
        $t = str2time($_, "GMT");
68
 
    }
69
 
    my $t2 = str2time(lc($_), "GMT");
70
 
    my $t3 = str2time(uc($_), "GMT");
71
 
 
72
 
    print "\n# '$_'\n";
73
 
 
74
 
    ok($t, $time);
75
 
    ok($t2, $time);
76
 
    ok($t3, $time);
77
 
}
78
 
 
79
 
# test time2str
80
 
ok(time2str($time), 'Thu, 03 Feb 1994 00:00:00 GMT');
81
 
 
82
 
# test the 'ls -l' format with missing year$
83
 
# round to nearest minute 3 days ago.
84
 
$time = int((time - 3 * 24*60*60) /60)*60;
85
 
my ($min, $hr, $mday, $mon) = (localtime $time)[1,2,3,4];
86
 
$mon = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
87
 
my $str = sprintf("$mon %02d %02d:%02d", $mday, $hr, $min);
88
 
my $t = str2time($str);
89
 
ok($t, $time);
90
 
 
91
 
# try some garbage.
92
 
for (undef, '', 'Garbage',
93
 
     'Mandag 16. September 1996',
94
 
     '12 Arp 2003',
95
 
#     'Thu Feb  3 00:00:00 CET 1994',
96
 
#     'Thu, 03 Feb 1994 00:00:00 CET',
97
 
#     'Wednesday, 31-Dec-69 23:59:59 GMT',
98
 
 
99
 
     '1980-00-01',
100
 
     '1980-13-01',
101
 
     '1980-01-00',
102
 
     '1980-01-32',
103
 
     '1980-01-01 25:00:00',
104
 
     '1980-01-01 00:61:00',
105
 
     '1980-01-01 00:00:61',
106
 
    )
107
 
{
108
 
    my $bad = 0;
109
 
    eval {
110
 
        if (defined str2time $_) {
111
 
            print "str2time($_) is not undefined\n";
112
 
            $bad++;
113
 
        }
114
 
    };
115
 
    print defined($_) ? "\n# '$_'\n" : "\n# undef\n";
116
 
    ok(!$@);
117
 
    ok(!$bad);
118
 
}
119
 
 
120
 
print "Testing AM/PM gruff...\n";
121
 
 
122
 
# Test the str2iso routines
123
 
use HTTP::Date qw(time2iso time2isoz);
124
 
 
125
 
print "Testing time2iso functions\n";
126
 
 
127
 
$t = time2iso(str2time("11-12-96  0:00AM"));
128
 
ok($t, "1996-11-12 00:00:00");
129
 
 
130
 
$t = time2iso(str2time("11-12-96 12:00AM"));
131
 
ok($t, "1996-11-12 00:00:00");
132
 
 
133
 
$t = time2iso(str2time("11-12-96  0:00PM"));
134
 
ok($t, "1996-11-12 12:00:00");
135
 
 
136
 
$t = time2iso(str2time("11-12-96 12:00PM"));
137
 
ok($t, "1996-11-12 12:00:00");
138
 
 
139
 
 
140
 
$t = time2iso(str2time("11-12-96  1:05AM"));
141
 
ok($t, "1996-11-12 01:05:00");
142
 
 
143
 
$t = time2iso(str2time("11-12-96 12:05AM"));
144
 
ok($t, "1996-11-12 00:05:00");
145
 
 
146
 
$t = time2iso(str2time("11-12-96  1:05PM"));
147
 
ok($t, "1996-11-12 13:05:00");
148
 
 
149
 
$t = time2iso(str2time("11-12-96 12:05PM"));
150
 
ok($t, "1996-11-12 12:05:00");
151
 
 
152
 
$t = str2time("2000-01-01 00:00:01.234");
153
 
print "FRAC $t = ", time2iso($t), "\n";
154
 
ok(abs(($t - int($t)) - 0.234) < 0.000001);
155
 
 
156
 
$a = time2iso;
157
 
$b = time2iso(500000);
158
 
print "LOCAL $a  $b\n";
159
 
my $az = time2isoz;
160
 
my $bz = time2isoz(500000);
161
 
print "GMT   $az $bz\n";
162
 
 
163
 
for ($a,  $b)  { ok(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/);  }
164
 
for ($az, $bz) { ok(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/); }
165
 
 
166
 
# Test the parse_date interface
167
 
use HTTP::Date qw(parse_date);
168
 
 
169
 
my @d = parse_date("Jan 1 2001");
170
 
 
171
 
ok(!defined(pop(@d)));
172
 
ok("@d", "2001 1 1 0 0 0");
173
 
 
174
 
# This test will break around year 2070
175
 
ok(parse_date("03-Feb-20"), "2020-02-03 00:00:00");
176
 
 
177
 
# This test will break around year 2048
178
 
ok(parse_date("03-Feb-98"), "1998-02-03 00:00:00");
179
 
 
180
 
print "HTTP::Date $HTTP::Date::VERSION\n";