HTTP-Date
view release on metacpan or search on metacpan
'1994-02-02T23:00:00-01:00',
'1994-02-03T00:00:00 Z',
'19940203T000000Z',
'199402030000',
# A few tests with extra space at various places
' 03/Feb/1994 ',
' 03 Feb 1994 0:00 ',
# Tests a commonly used (faulty?) date format of php cms systems
'Thu, 03 Feb 1994 00:00:00 +0000 GMT'
);
my $time = 760233600; # assume broken POSIX counting of seconds
for (@tests) {
my $t;
if (/GMT/i) {
$t = str2time($_);
}
else {
$t = str2time( $_, "GMT" );
}
my $t2 = str2time( lc($_), "GMT" );
my $t3 = str2time( uc($_), "GMT" );
note "\n'$_'";
is( $t, $time );
is( $t2, $time );
is( $t3, $time );
}
# test time2str
is( time2str($time), 'Thu, 03 Feb 1994 00:00:00 GMT' );
# test the 'ls -l' format with missing year$
# round to nearest minute 3 days ago.
my $passed = 0;
# Put in a hack to make the test pass due to daylight savings time affecting
# the result
for my $day ( 3 .. 4 ) {
$time = int( ( time - $day * 24 * 60 * 60 ) / 60 ) * 60;
my ( $min, $hr, $mday, $mon ) = ( localtime $time )[ 1, 2, 3, 4 ];
$mon = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
my $str = sprintf( "$mon %02d %02d:%02d", $mday, $hr, $min );
my $t = str2time($str);
if ( $t == $time ) {
$passed = 1;
last;
}
}
ok($passed);
# try some garbage.
for (
undef, '', 'Garbage',
'Mandag 16. September 1996',
'12 Arp 2003',
# 'Thu Feb 3 00:00:00 CET 1994',
# 'Thu, 03 Feb 1994 00:00:00 CET',
# 'Wednesday, 31-Dec-69 23:59:59 GMT',
'1980-00-01',
'1980-13-01',
'1980-01-00',
'1980-01-32',
'1980-01-01 25:00:00',
'1980-01-01 00:61:00',
'1980-01-01 00:00:61',
) {
my $bad = 0;
eval {
if ( defined str2time $_) {
print "str2time($_) is not undefined\n";
$bad++;
}
};
note defined($_) ? "\n'$_'" : "undef";
ok( !$@ );
ok( !$bad );
}
note "Testing AM/PM gruff...";
# Test the str2iso routines
use HTTP::Date qw(time2iso time2isoz);
note "Testing time2iso functions";
my $t = time2iso( str2time("11-12-96 0:00AM") );
is( $t, "1996-11-12 00:00:00" );
$t = time2iso( str2time("11-12-96 12:00AM") );
is( $t, "1996-11-12 00:00:00" );
$t = time2iso( str2time("11-12-96 0:00PM") );
is( $t, "1996-11-12 12:00:00" );
$t = time2iso( str2time("11-12-96 12:00PM") );
is( $t, "1996-11-12 12:00:00" );
$t = time2iso( str2time("11-12-96 1:05AM") );
is( $t, "1996-11-12 01:05:00" );
$t = time2iso( str2time("11-12-96 12:05AM") );
is( $t, "1996-11-12 00:05:00" );
$t = time2iso( str2time("11-12-96 1:05PM") );
is( $t, "1996-11-12 13:05:00" );
$t = time2iso( str2time("11-12-96 12:05PM") );
is( $t, "1996-11-12 12:05:00" );
$t = time2iso( str2time("11-12-01 12:00PM") );
is( $t, "2001-11-12 12:00:00" );
$t = time2iso( str2time("11-12-1996 12:00AM") );
is( $t, "1996-11-12 00:00:00" );
$t = time2iso( str2time("11-12-2022 12:00AM") );
( run in 2.505 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )