File Coverage

blib/lib/DateTime/Format/XMLTV.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 34 34 100.0


line stmt bran cond sub pod time code
1             #---------------------------------------------------------------------
2             package DateTime::Format::XMLTV;
3             #
4             # Copyright 2011 Christopher J. Madsen
5             #
6             # Author: Christopher J. Madsen
7             # Created: 28 Dec 2010
8             #
9             # This program is free software; you can redistribute it and/or modify
10             # it under the same terms as Perl itself.
11             #
12             # This program is distributed in the hope that it will be useful,
13             # but WITHOUT ANY WARRANTY; without even the implied warranty of
14             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
15             # GNU General Public License or the Artistic License for more details.
16             #
17             # ABSTRACT: Parse and format XMLTV dates and times
18             #---------------------------------------------------------------------
19              
20 3     3   91805 use 5.008;
  3         12  
  3         118  
21 3     3   16 use strict;
  3         5  
  3         102  
22 3     3   15 use warnings;
  3         6  
  3         853  
23              
24             our $VERSION = '1.001';
25             # This file is part of DateTime-Format-XMLTV 1.001 (March 8, 2014)
26              
27             #=====================================================================
28             use DateTime::Format::Builder 0.80 (
29 3         122 parsers => {
30             parse_datetime => [
31             [ preprocess => \&_parse_tz ],
32             {
33             length => 14,
34             params => [ qw( year month day hour minute second ) ],
35             regex => qr/^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
36             },
37             {
38             length => 12,
39             params => [ qw( year month day hour minute ) ],
40             regex => qr/^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
41             },
42             {
43             length => 10,
44             params => [ qw( year month day hour ) ],
45             regex => qr/^(\d\d\d\d)(\d\d)(\d\d)(\d\d)$/,
46             },
47             {
48             length => 8,
49             params => [ qw( year month day ) ],
50             regex => qr/^(\d\d\d\d)(\d\d)(\d\d)$/,
51             },
52             {
53             length => 6,
54             params => [ qw( year month ) ],
55             regex => qr/^(\d\d\d\d)(\d\d)$/,
56             },
57             {
58             length => 4,
59             params => [ qw( year ) ],
60             regex => qr/^(\d\d\d\d)$/,
61             },
62             ],
63             },
64 3     3   3127 );
  3         700603  
65              
66             *parse_date = \&parse_datetime;
67             *parse_time = \&parse_datetime; # XMLTV has no time-only format
68              
69             #---------------------------------------------------------------------
70             sub _parse_tz
71             {
72 32     32   32437 my %args = @_;
73 32         69 my ($date, $p) = @args{qw( input parsed )};
74              
75 32         94 $date =~ s/\s+\z//; # Strip any trailing whitespace
76              
77 32 100       136 if ($date =~ s/\s+(\S+)\z//) {
78 21         65 $p->{time_zone} = $1;
79             } else {
80 11         21 $p->{time_zone} = 'UTC';
81             }
82              
83 32         112 return $date;
84             } # end _parse_tz
85              
86             #---------------------------------------------------------------------
87             sub format_date
88             {
89 5     5 1 3061 my ($self, $dt) = @_;
90              
91 5         19 return $dt->ymd('');
92             }
93              
94             sub format_datetime
95             {
96 5     5 1 4377 my ($self, $dt) = @_;
97              
98 5         17 return($dt->ymd('') . $dt->hms('') . ' ' .
99             DateTime::TimeZone->offset_as_string($dt->offset));
100             }
101              
102             *format_time = \&format_datetime; # XMLTV has no time-only format
103              
104             #=====================================================================
105             # Package Return Value:
106              
107             1;
108              
109             __END__