use strict;

my $startTime;
my $lastTime;
my $clientName;

my $state = 'starting';
while ( my $line = <STDIN> ) {
    chomp $line;

    if ( 'starting' eq $state ) {
        if ( $line =~ /------------/ ) {
            $state     = 'scanning';
            $startTime = _getTime($line);

            # read the next line for the client name;
            $line = <STDIN>;
            chomp $line;

            my @chunks = split( / /, $line );
            $clientName = $chunks[7];
            next;
        }
    }

    if ( 'scanning' eq $state ) {
        my $mightBeLastTime = _getTime($line);
        $lastTime = $mightBeLastTime if $mightBeLastTime > 0;

        #        $lastTime = _getTime($line);
        if ( $line =~ /------------/ ) {
            _printClientTime( $startTime, $lastTime, $clientName );
            $startTime = $lastTime;

            # read the next line for the client name;
            $line = <STDIN>;
            chomp $line;

            my @chunks = split( / /, $line );
            $clientName = $chunks[7];
            next;
        }
    }

    #Mon Sep 15 14:34:28 2008 ------------
    #Mon Sep 15 14:34:28 2008 client 73 C_ALPHAPUP

}

_printClientTime( $startTime, $lastTime, $clientName );

sub _getTime {
    my ($line) = @_;

    my @chunks = split( / /, $line );
    return $chunks[3];
}

sub _printClientTime {
    my ( $startTime, $lastTime, $clientName ) = @_;

    my $delta = _calcDelta( $startTime, $lastTime );
    print "$clientName\t$delta\n";
}

sub _calcDelta {
    my ( $start, $end ) = @_;

    my $startSeconds = _toSeconds($start);
    my $endSeconds   = _toSeconds($end);
    my $deltaSeconds = $endSeconds - $startSeconds;

    my $hours = int( ( $deltaSeconds / ( 60 * 60 ) ) );
    $hours = 0 unless $hours > 1;
    my $hourSeconds = $hours * 60 * 60;

    my $minutes = int( ( $deltaSeconds - $hourSeconds ) / 60 );
    $minutes = 0 unless $minutes > 0;
    my $minuteSeconds = $minutes * 60;

    my $seconds = $deltaSeconds - $hourSeconds - $minuteSeconds;
    $seconds = 0 unless $seconds > 0;

    return sprintf( "%02d:%02d:%02d", $hours, $minutes, $seconds );
}

sub _toSeconds {
    my ($time) = @_;

    my ( $hours, $minutes, $seconds ) = split( ':', $time );

    return $seconds + ( $minutes * 60 ) + ( $hours * 60 * 60 );
}
