#!/usr/bin/perl
# Input: pt, en, es, fr (default pt)
# Output: 10:05 - Quinta-feira, 8 de junho de 2006

use CGI;
use Class::Date qw(date localdate now);
use strict;

my $date = new Class::Date (time);

my $query = new CGI;
my $lang = $query->param('lang');

print $query->header;
print
'<html>
<head>
<title></title>
<style type=\'text/css\' media=\'all\'>@import
"http://www.igfbrazil2007.br/igf.css";</style>
</head>
<body class=\'datatop\'>
';


# $date->_wday --> 0 = Sunday | $date->_month --> month 0..11
# $date->wday  --> 1 = Sunday | $date->month  --> month 1..12
print dateFormat($lang, $date->hour, $date->min, $date->_wday, $date->day, $date->_month, $date->year);

print "\n</body></html>";

exit;

# -------------------------------------------------------------

sub dateFormat {
	my ($lang, $hour, $min, $wd, $day, $mon, $yr) = @_;

	$min = ($min < 10) ? "0$min" : $min;

	my (@wdayname, @monthname) = ();
	my $date;

	if ($lang eq 'en') {
		@wdayname = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		@monthname = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
		
		#$day .= ($day == 1) ? 'st' : ($day == 2) ? 'nd' : 'th';
		my $m;
		if ($hour >= 12) {
			$hour = abs(12 - $hour);
			$m = 'pm';
		} else {
			$m = 'am';
		}

		if (length($hour) < 2) {
			$hour = "0" . $hour;
		}
		
		$date = "Local time: $hour:$min$m - $wdayname[$wd], $monthname[$mon] $day, $yr";

	} elsif ($lang eq 'es') {
		@wdayname = ('Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado');
		@monthname = ('Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
		
		$date = "Hora local: $hour:$min - $wdayname[$wd] $day de $monthname[$mon], $yr";

	} elsif ($lang eq 'fr') {
		@wdayname = ('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
		@monthname = ('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
		
		$date = " Heure locale $hour:$min - $wdayname[$wd], $day $monthname[$mon] $yr";

	} else { # default 'pt'
		@wdayname = ('Domingo', 'Segunda-Feira', 'Terça-Feira', 'Quarta-Feira', 'Quinta-Feira', 'Sexta-Feira', 'Sábado');
		@monthname = ('Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
	
		if ($day == 1) { $day .= '°'; }
		$date = "Hora local: $hour:$min - $wdayname[$wd], $day de $monthname[$mon] de $yr";
	}

	return $date;
}

exit;

