#!/usr/bin/perl

use DateTime;
use DateTime::TimeZone;

local ($buffer, @pairs, $pair, $name, $value, %FORM);
# Read in text
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;

if ($ENV{'REQUEST_METHOD'} eq "GET") {
   $buffer = $ENV{'QUERY_STRING'};
}

# Split information into name/value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);
   $value =~ tr/+/ /;
   $value =~ s/%(..)/pack("C", hex($1))/eg;
   $FORM{$name} = $value;
}

$first_name = $FORM{first_name};
$last_name  = $FORM{last_name};

$dt = DateTime->now;    # same as ( epoch => time )

$dttz = DateTime::TimeZone->new( name => 'local' )->name();

$dt->set_time_zone( $dttz );
 
$year  = $dt->year;
$month = $dt->month;        # 1-12
 
$day = $dt->day;            # 1-31
 
$dow = $dt->day_of_week;    # 1-7 (Monday is 1)
 
$hour   = $dt->hour;        # 0-23
$minute = $dt->minute;      # 0-59
 
$second = $dt->second;      # 0-61 (leap seconds!)
 
$doy = $dt->day_of_year;    # 1-366 (leap years)
 
$doq = $dt->day_of_quarter; # 1..
 
$qtr = $dt->quarter;        # 1-4

$dmy = $dt->dmy('/');    # 06/12/2002
 
$hms = $dt->hms;         # 14:02:29

print "Content-type:text/html\r\n\r\n";
print "<html>";
print "<head>";
print "<title>Hello - Second CGI Program</title>";
print "<script type=text/javascript>";
print " function loctime() { ";
print "   var qwr='' + Intl.DateTimeFormat().resolvedOptions().timeZone; ";
print "   var d = new Date(); ";
print "   d.toLocaleString('en-US', { timeZone: qwr }); ";
print "   var ns=document.getElementById('mystime').innerHTML.split(':')[2].split(' ')[0]; ";
print "   var ls=('' + d.toLocaleString()).replace(',','') + ' GMT' + d.toString().split(' GMT')[1]; ";
print "   document.getElementById('mytime').innerHTML=ls.replace(':' + ls.split(':')[2].split(' ')[0] + ' ', ':' + ns + ' '); ";
print " } ";
print "</script>";
print "</head>";
print "<body onload=loctime();>";
print "<h2 style='font-family:Courier New;'>Hello $first_name $last_name <br>&nbsp;Local: <span id=mytime></span><br>Server: <span id=mystime>$dmy $hms</span> $dttz </h2>";
print "<br><br><iframe src='/hello_get.html' style='width:100%; height:1500px;'></iframe></body>";
print "</html>";

1;