#!/usr/bin/perl

use POSIX;

my (
    $wday,
    $year,
    $month,
    $date,
    $time,
    $zone,
    @wdays,
    @months,
);

#
# Days in a week, as appears in the output of unix shell command "date"
#
@wdays = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

#
# Months in a year, as appears in the output of unix shell command "date"
#
@months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");


#
# the date commands output is passed as the input here (by the RunScript.sh)
#
$inputDate = <STDIN>;

#
# storing the different words in the output
#
@words = split (/\s+/, $inputDate);


$wday  = $words[0];
$month = $words[1];
$date  = $words[2];
$time  = $words[3];
$zone  = $words[4];
$year  = $words[5];

print "\ndate commands output:\n"
      . "~~~~~~~~~~~~~~~~~~~~~\n\t\t$inputDate\n";


for($i = 0; $i <= $#wdays; $i++) {
  if ("$wday" eq "$wdays[$i]") {
    $wday = $i;
#   print "$wday = $wdays[$i]\n";
    last;
  }
}

for($i = 0; $i <= $#months; $i++) {
  if ("$month" eq "$months[$i]") {
    $month = $i;
#   print "$month = $months[$i]\n";
    last;
  }
}

@time_components = split (/\:/, $time);
$hour  = $time_components[0];
$min  = $time_components[1];
$sec  = $time_components[2];
$year = $year - 1900;

print "arguments to the mktime() method:\n"
  .   "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
print "sec = $sec, min = $min, hour = $hour,\ndate = $date, month = $month, "
  . "year (this yr. - 1900) = $year, day = $wday \n\n";


$timestamp = mktime($sec, $min, $hour, $date, $month, $year, $wday, 0, -1);

print "********************************\n";
print "CALCULATED TIMESTAMP = ";
print "$timestamp \n";
print "********************************\n";

print "PRESENT TIMESTAMP    = ";
print (time());
print "\n";
print "********************************\n\n";

