more robust testing platform, #37340
[freeside.git] / FS / FS / cdr / earthlink.pm
1 package FS::cdr::earthlink;
2
3 use strict;
4 use vars qw( @ISA %info $date);
5 use Time::Local;
6 use FS::cdr qw(_cdr_min_parser_maker);
7 use Date::Parse;
8
9 @ISA = qw(FS::cdr);
10
11 my ($tmp_mday, $tmp_mon, $tmp_year);
12
13 %info = (
14   'name'          => 'Earthlink',
15   'weight'        => 120,
16   'header'        => 1,
17   'import_fields' => [
18
19         skip(3),                        #Account number/ SERVICE LOC / BILL NUMBER 
20         sub { my($cdr, $date) = @_;
21         $date =~ /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/
22         or die "unparseable date: $date";
23         ($tmp_mon, $tmp_mday, $tmp_year) = ($1, $2, $3);
24         },                              #date       
25         sub { my($cdr, $time) = @_;
26                   $time =~ /^(\d{1,2}):(\d{1,2}):(\d{1,2}) (AM|PM)$/
27                   or die "unparsable time: $time"; #maybe we shouldn't die...
28           my $hour = $1;
29           $hour += 12 if $4 eq 'PM' && $hour != 12;
30           $hour = 0 if $4 eq 'AM' && $hour == 12;
31
32              my $dt = DateTime->new(
33                 year    => $tmp_year,
34                 month   => $tmp_mon,
35                 day     => $tmp_mday,
36                 hour    => $hour,
37                 minute  => $2,
38                 second  => $3,
39                 time_zone => 'local',
40       );
41               $cdr->set('startdate', $dt->epoch);
42
43         },
44         skip(1),                        #TollFreeNumber
45         sub { my($cdr, $src) = @_;      
46         $src =~ s/\D//g;
47         $cdr->set('src', $src);
48         },                              #ORIG NUMBER
49         skip(2),                        #ORIG CITY/ORIGSTATE
50         sub { my($cdr, $dst) = @_;
51         $dst =~ s/\D//g;
52         $cdr->set('dst', $dst);
53         },                              #TERM NUMBER
54         skip(2),                        #TERM CITY / TERM STATE
55         _cdr_min_parser_maker,          #MINUTES
56         skip(1),                        #AMOUNT
57         'disposition',                  #Call Type
58         skip(1),                        #Seq
59         'accountcode',                  #AcctCode
60   ],
61 );
62
63 sub skip { map {''} (1..$_[0]) }
64
65 1;
66