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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
use strict;
use warnings;
BEGIN {
# Windows can't change timezone inside Perl script
if (($ENV{TZ}||'') ne 'GMT') {
$ENV{TZ} = 'GMT';
exec $^X, (map { "-I\"$_\"" } @INC), $0;
};
}
use Test::More;
use POSIX::strftime::Compiler;
use Time::Local;
my %format = (
a => 'Sun',
A => 'Sunday',
b => 'Jul',
B => 'July',
c => 'Sun Jul 6 21:03:54 2008',
C => '20',
d => '06',
D => '07/06/08',
e => ' 6',
EC => '20',
Ex => '07/06/08',
EX => '21:03:54',
EY => '2008',
Ey => '08',
F => '2008-07-06',
G => '2008',
g => '08',
h => 'Jul',
H => '21',
I => '09',
j => '188',
k => '21',
l => ' 9',
m => '07',
M => '03',
n => "\n",
N => '123456000',
Od => '06',
Oe => ' 6',
OH => '21',
OI => '09',
Om => '07',
OM => '03',
OS => '54',
Ou => '7',
OU => '27',
OV => '27',
Ow => '0',
Oy => '08',
p => 'PM',
P => 'pm',
r => '09:03:54 PM',
R => '21:03',
s => '1215378234',
S => '54',
t => "\t",
T => '21:03:54',
u => '7',
U => '27',
V => '27',
w => '0',
W => '26',
x => '07/06/08',
X => '21:03:54',
y => '08',
Y => '2008',
z => '+0000',
Z => qr/^(GMT|UTC)$/,
'%' => '%',
Q => '%Q', #unknown
q => '%q', #unknown
);
my @t = localtime timelocal(54, 3, 21, 6, 6, 108);
$t[0] += 0.123456;
foreach my $f (sort keys %format) {
if ( ref $format{$f} ) {
like( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f);
}
else {
is( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f);
is( POSIX::strftime::Compiler::strftime('%'.$f.'foo',@t), $format{$f}.'foo', '%'.$f);
is( POSIX::strftime::Compiler::strftime('%'.$f.' foo',@t), $format{$f}.' foo', '%'.$f);
}
}
@t = (54.123456, 3, 21, 6, 6, 108);
foreach my $f (sort keys %format) {
if ( ref $format{$f} ) {
like( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f.'=6');
}
else {
is( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f. '=6');
is( POSIX::strftime::Compiler::strftime('%'.$f.'foo',@t), $format{$f}.'foo', '%'.$f.'foo=6');
is( POSIX::strftime::Compiler::strftime('%'.$f.' foo',@t), $format{$f}.' foo', '%'.$f.' foo=6');
}
}
#last single %
is( POSIX::strftime::Compiler::strftime('foo %',@t), 'foo %', 'last %');
#last single %
is( POSIX::strftime::Compiler::strftime('foo %',(54.123456, 3, 21, 6, 6, 108)), 'foo %', 'last % =6');
done_testing();
|