$self->SUPER::check;
}
+=item is_tollfree
+
+ Returns true when the cdr represents a toll free number and false otherwise.
+
+=cut
+
+sub is_tollfree {
+ my $self = shift;
+ ( $self->dst =~ /^(\+?1)?8(8|([02-7])\3)/ ) ? 1 : 0;
+}
+
=item set_charged_party
If the charged_party field is already set, does nothing. Otherwise:
} else {
- if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) {
+ if ( $self->is_tollfree ) {
$self->charged_party($self->dst);
} else {
$self->charged_party($self->src);
sub _cdr_date_parser_maker {
my $field = shift;
+ my %options = @_;
my @fields = ref($field) ? @$field : ($field);
return sub {
my( $cdr, $datestring ) = @_;
- my $unixdate = eval { _cdr_date_parse($datestring) };
+ my $unixdate = eval { _cdr_date_parse($datestring, %options) };
die "error parsing date for @fields from $datestring: $@\n" if $@;
$cdr->$_($unixdate) foreach @fields;
};
sub _cdr_date_parse {
my $date = shift;
+ my %options = @_;
return '' unless length($date); #that's okay, it becomes NULL
return '' if $year == 1900 && $mon == 1 && $day == 1
&& $hour == 0 && $min == 0 && $sec == 0;
- timelocal($sec, $min, $hour, $day, $mon-1, $year);
+ if ($options{gmt}) {
+ timegm($sec, $min, $hour, $day, $mon-1, $year);
+ } else {
+ timelocal($sec, $min, $hour, $day, $mon-1, $year);
+ }
}
=item batch_import HASHREF