#!/usr/local/bin/perl

use POSIX;

$ENV{'TZ'}="GMT";
tzset();

$RECORD_DATE_FMT = "DAY MON MDAY HH:MM:SS YEAR";

$recdate = "Mon Feb  9 22:59:13 1998";
$recdate =~ s/ +/ /g;
$recdate =~ s/:/ /g;
my @recdates = split(/ /, $recdate);
my $stdfmt = $RECORD_DATE_FMT;
$stdfmt =~ s/:/ /g;
my @stds = split(/ /, $stdfmt);
while ($foo = shift (@stds)) {
  $val = shift(@recdates);
  $$foo = $val;
}
$Timestamp = calendar_time( $DAY, $MON, $MDAY, $HH, $MM, $SS, $YEAR );
if ($Timestamp eq 884386753) {
  print "$recdate -> $Timestamp (GMT)\n";
  print "Successful, POSIX mktime() is available and working.\n";
} else {
  if ($Timestamp eq 0) {
    print "$recdate -> $Timestamp\nFailed.\n";
  } else {
    print "$recdate -> $Timestamp ($ENV{'TZ'})\n";
    print "ERROR: POSIX mktime() is exists but is returning wrong results.\n";
  }
}

sub calendar_time {
  my $day = shift;
  my $month = shift;
  my $mday = shift;
  my $hour = shift;
  my $min = shift;
  my $sec = shift;
  my $year = shift;
  $year -= 1900 if ($year >= 1900);
  my $cal = mktime($sec, $min, $hour,  $mday, $monthshash{$month}, $year,
                $weekhash{$day}, 0, 0);
  return $cal;
}

