line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::HTTP;
|
2
|
3
|
|
|
3
|
|
302566
|
use strict;
|
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
127
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings;
|
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
113
|
|
4
|
3
|
|
|
3
|
|
23
|
use vars qw( $VERSION );
|
|
3
|
|
|
|
|
27
|
|
|
3
|
|
|
|
|
201
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.42';
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2962
|
use DateTime;
|
|
3
|
|
|
|
|
392661
|
|
|
3
|
|
|
|
|
89
|
|
9
|
3
|
|
|
3
|
|
2948
|
use HTTP::Date qw();
|
|
3
|
|
|
|
|
15313
|
|
|
3
|
|
|
|
|
100
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
23
|
use vars qw( @MoY %MoY);
|
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
2379
|
|
12
|
|
|
|
|
|
|
@MoY = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
13
|
|
|
|
|
|
|
@MoY{@MoY} = (1..12);
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub format_datetime
|
16
|
|
|
|
|
|
|
{
|
17
|
4
|
|
|
4
|
1
|
3910
|
my ($self, $dt) = @_;
|
18
|
4
|
100
|
|
|
|
23
|
$dt = DateTime->now unless defined $dt;
|
19
|
4
|
|
|
|
|
275
|
$dt = $dt->clone->set_time_zone( 'GMT' );
|
20
|
4
|
|
|
|
|
868
|
return $dt->strftime( "%a, %d %b %Y %H:%M:%S GMT" );
|
21
|
|
|
|
|
|
|
}
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub parse_datetime
|
25
|
|
|
|
|
|
|
{
|
26
|
120
|
|
|
120
|
1
|
108377
|
my ($self, $str, $zone) = @_;
|
27
|
120
|
|
|
|
|
163
|
local $_;
|
28
|
120
|
100
|
|
|
|
313
|
die "No input string!" unless defined $str;
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# fast exit for strictly conforming string
|
31
|
119
|
100
|
|
|
|
251
|
if ($str =~ /^
|
32
|
|
|
|
|
|
|
[SMTWF][a-z][a-z],
|
33
|
|
|
|
|
|
|
\ (\d\d)
|
34
|
|
|
|
|
|
|
\ ([JFMAJSOND][a-z][a-z])
|
35
|
|
|
|
|
|
|
\ (\d\d\d\d)
|
36
|
|
|
|
|
|
|
\ (\d\d):(\d\d):(\d\d)
|
37
|
|
|
|
|
|
|
\ GMT$/x) {
|
38
|
1
|
|
|
|
|
11
|
return DateTime->new(
|
39
|
|
|
|
|
|
|
day => $1,
|
40
|
|
|
|
|
|
|
month => $MoY{$2},
|
41
|
|
|
|
|
|
|
year => $3,
|
42
|
|
|
|
|
|
|
hour => $4,
|
43
|
|
|
|
|
|
|
minute => $5,
|
44
|
|
|
|
|
|
|
second => $6,
|
45
|
|
|
|
|
|
|
time_zone => 'GMT'
|
46
|
|
|
|
|
|
|
);
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
118
|
|
|
|
|
276
|
my %d = $self->_parse_date($str);
|
50
|
|
|
|
|
|
|
|
51
|
113
|
100
|
|
|
|
328
|
unless (defined $d{time_zone})
|
52
|
|
|
|
|
|
|
{
|
53
|
60
|
100
|
|
|
|
140
|
$d{time_zone} = defined $zone ? $zone : 'floating';
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
113
|
|
|
|
|
167
|
my $frac = $d{second}; $frac -= ($d{second} = int($frac));
|
|
113
|
|
|
|
|
229
|
|
57
|
113
|
|
|
|
|
164
|
my $nano = 1_000_000_000 * $frac; $d{nanosecond} = int($nano + 0.5);
|
|
113
|
|
|
|
|
222
|
|
58
|
113
|
|
|
|
|
551
|
return DateTime->new( %d );
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _parse_date
|
63
|
|
|
|
|
|
|
{
|
64
|
118
|
|
|
118
|
|
151
|
my ($self, $str) = @_;
|
65
|
118
|
|
|
|
|
301
|
my @fields = qw( year month day hour minute second time_zone );
|
66
|
118
|
|
|
|
|
136
|
my %d;
|
67
|
118
|
|
|
|
|
316
|
my @values = HTTP::Date::parse_date( $str );
|
68
|
118
|
100
|
|
|
|
5523
|
die "Could not parse date [$str]\n" unless @values;
|
69
|
113
|
|
|
|
|
1885
|
@d{@fields} = @values;
|
70
|
|
|
|
|
|
|
|
71
|
113
|
100
|
|
|
|
283
|
if (defined $d{time_zone}) {
|
72
|
53
|
100
|
|
|
|
266
|
$d{time_zone} = "GMT" if $d{time_zone} =~ /^(Z|GMT|UTC?|[-+]?0+)$/ix;
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
113
|
|
|
|
|
978
|
return %d;
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub format_iso
|
80
|
|
|
|
|
|
|
{
|
81
|
12
|
|
|
12
|
1
|
3177
|
my ($self, $dt) = @_;
|
82
|
12
|
100
|
|
|
|
34
|
$dt = DateTime->now unless defined $dt;
|
83
|
12
|
|
|
|
|
273
|
sprintf("%04d-%02d-%02d %02d:%02d:%02d",
|
84
|
|
|
|
|
|
|
$dt->year, $dt->month, $dt->day,
|
85
|
|
|
|
|
|
|
$dt->hour, $dt->min, $dt->sec
|
86
|
|
|
|
|
|
|
);
|
87
|
|
|
|
|
|
|
}
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub format_isoz
|
91
|
|
|
|
|
|
|
{
|
92
|
4
|
|
|
4
|
1
|
28025
|
my ($self, $dt) = @_;
|
93
|
4
|
100
|
|
|
|
17
|
$dt = DateTime->now unless defined $dt;
|
94
|
4
|
|
|
|
|
173
|
$dt = $dt->clone->set_time_zone( 'UTC' );
|
95
|
4
|
|
|
|
|
281
|
sprintf("%04d-%02d-%02d %02d:%02d:%02dZ",
|
96
|
|
|
|
|
|
|
$dt->year, $dt->month, $dt->day,
|
97
|
|
|
|
|
|
|
$dt->hour, $dt->min, $dt->sec
|
98
|
|
|
|
|
|
|
);
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1;
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__
|