package ReportCommon;

use Time::Local;

sub start_date {
    my( $date ) = @_;

    my $now = time-24*3600;
    $date =~ s/[\s\t]//g;
    if( $date =~ /^-(\d+)day/ ) {
	$now = time - $1*24*3600;
	undef $date;
    }
    if( $date =~ /^-(\d+)week/ ) {
	$now = time - $1*7*24*3600;
	undef $date;
    }

    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now); 
    my ($myyear, $mymon, $myday );
    if( ! $date ) { ; }
    elsif( $date =~ /-/ ) {
	 ($myyear, $mymon, $myday) = split( "-", $date );
    }
    elsif( $date =~ /\./ ) {
	 ($myday, $mymon, $myyear) = split( /\./, $date );
    }
    elsif( $date =~ /\// ) {
	 ($mymon, $myday, $myyear) = split( /\//, $date );
    }
    $mon = $mymon-1 if( $mymon );
    $mday = $myday if( $myday );
    if( $myyear ) {
	if( $myyear > 1900 ) { $myyear -= 1900; }
	else { $myyear += $year - $year%100; }
	$year = $myyear;
    }
    return( timelocal(0,0,0,$mday,$mon,$year),
    	    timelocal(0,59,23,$mday,$mon,$year) + 60 );
}

1;
