EMIUCP.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 24 / 24 CC 2 SCAR 2.9
CC
2
Cov
100%
_fix_year
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary EMIUCP/DDT.pm »
1 package DateTime::Format::EMIUCP;
2  
3 =head1 NAME
4  
5 DateTime::Format::EMIUCP - Parse time formats for EMI-UCP protocol
6  
7 =head1 SYNOPSIS
8  
9 use DateTime::Format::EMIUCP;
10  
11 my $scts = DateTime::Format::EMIUCP->parse_datetime('030212065530');
12 print $scts->ymd; # 2012-02-03
13 print $scts->hms; # 06:55:30
14  
15 my $vp = DateTime::Format::EMIUCP->parse_datetime('0302120655');
16 print $vp->ymd; # 2012-02-03
17 print $vp->hms; # 06:55:00
18  
19 =head1 DESCRIPTION
20  
21 These formats are part of EMI-UCP protocol message. EMI-UCP protocol is
22 primarily used to connect to short message service centers (SMSCs) for mobile
23 telephones.
24  
25 SCTS is a string of 12 numeric characters which represents Service Center
26 time-stamp in ddMMyyHHmmss format.
27  
28 DSCTS is a string of 12 numeric characters which represents Delivery
29 time-stamp in ddMMyyHHmmss format.
30  
31 DDT is a string of 10 numeric characters which represents deferred delivery
32 time in ddMMyyHHmm format.
33  
34 VP is a string of 10 numeric characters which represents validity period time
35 in ddMMyyHHmm format.
36  
37 See EMI-UCP Interface 5.2 Specification for further explanations.
38  
39 =for readme stop
40  
41 =cut
42  
43 14 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 14 our $VERSION = '0.0300';
49  
50 =head1 METHODS
51  
52 =over
53  
54 =item DateTime I<$dt> = $fmt->parse_datetime(Str I<$scts>)
55  
56 Given a string in the pattern specified in the constructor, this method will
57 return a new DateTime object.
58  
59 Year number below 70 means the date before year 2000.
60  
61 If given a string that doesn't match the pattern, the formatter will croak.
62  
63 =back
64  
65 =cut
66  
67 14 ▶use DateTime::Format::Builder (
Subroutine BEGIN: called CC=1 SCAR=0.0
68 14 parsers => {
69 parse_datetime => [
70 {
71 params => [qw( day month year hour minute second )],
72 regex => qr/^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
73 postprocess => \&_fix_year,
74 },
75 {
76 params => [qw( day month year hour minute )],
77 regex => qr/^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/,
78 postprocess => \&_fix_year,
79 },
80 ]
81 }
82 14 );
83  
84  
85 30 ▶sub _fix_year {
Subroutine _fix_year: called CC=2 SCAR=6.9
86 30 my %args = @_;
87 30 my ($date, $p) = @args{qw( input parsed )};
88 30 ▶ $p->{year} += $p->{year} > 69 ? 1900 : 2000;
Branch: 1 branch
BranchTrueFalseTotal
$p->{'year'} > 69 ? : 10 20 30
89 30 return 1;
90 };
91  
92  
93 14 1;
94  
95 __END__
↑ Summary EMIUCP/DDT.pm »