#!/usr/bin/perl

use strict;
use warnings;

print <<EOF;
Content-type: text/html;Charset=utf-8

<html lang="en">

<head>
  <title>Epoch translator</title>
</head>

<body>

<h1>Epoch - Local time translator/converter</h1>
EOF

my $lEpochString = substr($ENV{'QUERY_STRING'}, -10);
my $lEpoch = 0;

if ( $lEpochString =~ m/^\d+$/ ) {
  $lEpoch = $lEpochString;
}
else {
  $lEpoch = time();
}

print "<p>Local time is: " . localtime($lEpoch) . " from epoche: $lEpoch</p>";
print "<p>To convert enter URL like this: cgi-bin/test.pl?$lEpoch</p>";

print <<EOF;
</body>

</html>
EOF
