#!/usr/bin/perl -w ############################################################################## # Create a string representing an old date # Author: Chris Rouch # Date: 10/2001 # Changelog: # Copyright (c) Chris Rouch 2001 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # or see http://www.gnu.org/licenses/gpl.txt ############################################################################## use strict; use Getopt::Long; use Date::Format; use constant HOURSECS=> 60 * 60; use constant DAYSECS=> 24 * HOURSECS; # general global variables my ($PROG,$USAGE,$OPTIONS); use vars qw (@times); # command line variables my $days=0; # how many days ago my $hours=0; # how many hours ago my $verbose; # make some noise my $format="%Y%m%d"; # default format my $time=time; # default to now # command line switch my %opts= ( "d|days=s" => \$days, "h|hours=s" => \$hours, "f|format=s" => \$format, "t|time=s" => \$time, "v|verbose" => \$verbose, ); ($PROG=$0) =~ s#.*/##; SetUsage(\%opts,\$OPTIONS); $USAGE="Usage: $PROG $OPTIONS"; die "$USAGE\n" unless GetOptions(%opts); # program begins here if ($hours) { print time2str("$format",$time - $days * DAYSECS - $hours * HOURSECS), "\n"; } else { print time2str("$format",$time - $days * DAYSECS), "\n"; } ############### end of main ############# sub SetUsage { my ($ropts,$rstr) = @_; foreach my $key (keys %$ropts) { if ($key =~ /\|/) { $key=~ s!^.*\|!!; } if ($key =~ /=/) { $key =~ s!=.*$! value!; } $key = '-' . $key; $$rstr .= '[' . $key . '] '; } } ############### end of file #############