#!/usr/bin/perl -w
use strict;
##########################################################################
# $Id: applydate,v 1.2 2005/05/03 19:33:39 bjorn Exp $
##########################################################################

use POSIX qw(strftime);
#use Logwatch ':dates';

my ($SearchDate, $SearchNewDate, $ThisLine);

my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;

my $time = time;

#$SearchDate = TimeFilter('%m/%d/%y %H:%M:%S');
#$SearchNewDate = TimeFilter('%b %d %H:%M:%S');

if ($ENV{'LOGWATCH_DATE_RANGE'} eq 'yesterday') {
   $SearchDate = strftime("%m/%d/%y", localtime($time-86400));
   $SearchNewDate = strftime("%b %d", localtime($time-86400));
}
elsif ($ENV{'LOGWATCH_DATE_RANGE'} eq 'today') {
   $SearchDate = strftime("%m/%d/%y", localtime($time));
   $SearchNewDate = strftime("%b %d", localtime($time));
}
elsif ($ENV{'LOGWATCH_DATE_RANGE'} eq 'all') {
   $SearchDate = '../../..';
   $SearchNewDate = '... ..';
}


if ( $Debug > 5 ) {
   print STDERR "DEBUG: Inside ApplyDate (yum)...\n";
   print STDERR "DEBUG: Looking For: " . $SearchDate . " or " . $SearchNewDate . "\n";
}

while (defined($ThisLine = <STDIN>)) {
    # Convert new (yum 2.1) format to old, as yum service script expects that
    if ($ThisLine =~ s/$SearchNewDate /$SearchDate /o ||
        $ThisLine =~ m/$SearchDate /o) {
      print $ThisLine;
    }
}



