#!/usr/bin/perl

use Time::Local;

my $time1="Thu Jun 14 10:03:53 CST 2018";

my $time2="Thu Jun 14 03:07:09 2018";


sub get_mon

{

($p1)=@_;

my $mon=0;

my $num=-1;

my $monstr="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec";

my @monlist= split / /, $monstr;

foreach $m (@monlist){

$num=$num+1;

if ($p1 eq $m){

$mon=$num;

}

}

return $mon;

}

   

sub get_istat_time

{

my $TIME1 = "";

   ($p)=@_;

   #my $time1="Thu Jun 14 10:03:53 CST 2018";

   #my $time2="Thu Jun 14 03:07:09 2018";

   if ($p=~/(\w{3})(\s+)(\w{3})(\s+)(\d{2})(\s+)(\d{2})(\:)(\d{2})(\:)(\d{2})(\s+)(\d{4})(.*)/)

      {

        #my $p1="$1";

        #printf "$1,$3,$5,$7,$9,$11,$13,$15\n";

$sec=$11;

$min=$9;

$hour=$7;

$day=$5;

$mon=get_mon $3;

$year=$13;

#printf "$sec, $min, $hour, $day, $mon, $year\n";

      }

elsif ($p=~/(\w{3})(\s+)(\w{3})(\s+)(\d{2})(\s+)(\d{2})(\:)(\d{2})(\:)(\d{2})(\s+)(\w{3})(\s+)(\d{4})(.*)/)

      {

        #my $p1="$1";

        #printf "$1,$3,$5,$7,$9,$11,$13,$15\n";

$sec=$11;

$min=$9;

$hour=$7;

$day=$5;

$mon=get_mon $3;

$year=$15;

#printf "$sec, $min, $hour, $day, $mon, $year\n";

      }

  

   $TIME1 = timelocal($sec, $min, $hour, $day, $mon, $year);

   

   return $TIME1;

}


sub help()

{

  print "usage:\n";

  print "get_time \"Thu Jun 14 10:03:53 CST 2018\"\n";

  print "get_time \"Thu Jun 14 03:07:09 2018\"\n";

  exit 1;

}



sub main()

{

        if(@ARGV<1)

  {

          help();

  }

       

printf(get_istat_time($ARGV[0]));

printf("\n");    

}


main