Date::Parse example program
Jason Spence
thalakan at frys.com
Wed Jan 24 00:19:02 PST 2001
Hi -
I'm doing work with the billing script right now, and had to write a
sample program to see what kinds of dates Date::Parse wants. I've
attached the program to this email.
Just pass it a string to hand to Date::Parse on the command line. It
will output the results in UNIX epoch and localtime format.
- Jason
-------------- next part --------------
#!/usr/bin/perl -Tw
use Getopt::Long;
use Date::Parse;
use vars qw($opt_help $opt_version $ret);
my $opt_h = undef;
my $opt_v = undef;
my @options = (
"help" => 0,
"version" => 0
);
GetOptions(@options);
if($opt_help) {
usage();
}
if($opt_version) {
version();
}
$ret = str2time($ARGV[0]);
if(!defined($ret)) {
warn "Date::Parse says that is not a valid date.\n";
exit(1);
}
print("UNIX date (seconds since Jan. 1 1970 GMT): $ret\n");
print("Human-readable date: " . localtime($ret) . "\n");
##############################################################################
# usage: prints out the program's usage message.
#
# arguments: none
#
# side effects: kills the program.
##############################################################################
sub usage {
print STDERR ("Usage: date_parse [date]\n" .
"Prints out the results of parsing a string with Date::Parse.\n\n" .
"--help Print this help message\n" .
"--version Print the program version\n" .
"Please send bugs to Jason Spence <thalakan\@technologist.com>"
);
exit(1);
}
##############################################################################
# version: prints out the program's version message.
#
# arguments: none
#
# side effects: kills the program.
##############################################################################
sub version {
print STDERR ("date_parse 1.0");
exit(1);
}
More information about the freeside-users
mailing list