#==============================================================================
# libdate.pl librairi date
#==============================================================================
@GLB_month = ("January","February","March","April","May","June","July","August","September","October","November","December");
@GLB_day=("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");

@GLB_mois=("janvier","fevrier","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","decembre");
@GLB_jour=("lundi","mardi","mercredi","jeudi","vendredi","samedi","dimanche");

#-------------------------------------------------------------------------------
sub getdate()
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;

$year += 1900;
$mon +=1;

$v = sprintf("%2.2d/%2.2d/%2.4d",$mday,$mon,$year);
return $v;
}

#-------------------------------------------------------------------------------
sub getdate_en()
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;

$year += 1900;
$mon +=1;

$v = sprintf("%2.4d/%2.2d/%2.2d",$year,$mon,$mday);
return $v;
}

#-------------------------------------------------------------------------------
sub tagdate()
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime time;

$year += 1900;
$mon +=1;

$v = sprintf("%2.4d%2.2d%2.2d",$year,$mon,$mday,$mon);
return $v;
}

#-------------------------------------------------------------------------------
sub gettime
{
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	if ($hour < 10) { $hour = "0"."$hour"; }
	if ($min < 10) { $min = "0"."$min"; }
	if ($sec < 10) { $sec = "0"."$sec"; }

return "$hour:$min:$sec\n";
}
#-------------------------------------------------------------------------------
sub ordinal_en()
{
  my ($v)=@_;
  if ($v == 1) { $r="1st"; }
  elsif ($v == 2) { $r="2nd"; }
  elsif ($v == 3) { $r="3rd"; }
  else
  {
    $r=$v."th";
  }
  return $r;
}
#-------------------------------------------------------------------------------
sub show_date_fr()
{
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

}
#-------------------------------------------------------------------------------
sub show_date_en()
{
  my($v);
  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  if ($year <= 99) { $year = "19"."$year"; }
  if ($year > 99) { $year = $year-100; if($year < 10) { $year = "0".$year; }$year = "20"."$year"; }
  $v=&ordinal_en($mday);
  return "$GLB_month[$mon]$m $v $year";
}
#-------------------------------------------------------------------------------
sub show_date_long_en()
{
   my($v);
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  if ($year <= 99) { $year = "19"."$year"; }
  if ($year > 99) { $year = $year-100; if($year < 10) { $year = "0".$year; }$year = "20"."$year"; }
  $v=&ordinal_en($mday);
  return $GLB_day[$wday].", "."$GLB_month[$mon] $v $year";
}
#-------------------------------------------------------------------------------
sub show_date()
{
  my($v);
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  if ($year <= 99) { $year = "19"."$year"; }
  if ($year > 99) { $year = $year-100; if($year < 10) { $year = "0".$year; }$year = "20"."$year"; }
  return "$mday $GLB_mois[$mon] $year";
}
#-------------------------------------------------------------------------------

sub show_date_long()
{
  my($v);
  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  if ($year <= 99) { $year = "19"."$year"; }
  if ($year > 99) { $year = $year-100; if($year < 10) { $year = "0".$year; }$year = "20"."$year"; }
  return "$GLB_jour[$wday], $mday $GLB_mois[$mon] $year";
}
#-------------------------------------------------------------------------------

# test
print getdate();
print "\n";
print gettime();

print &show_date();
print &show_date_long();
print &show_date_en();
print &show_date_long_en();

#
# Documentation
#

__END__


=head1 NAME

libdate - librairie de manipulation de date

=head1 SYNOPSIS

=over 4

=item getdate

affiche la date au format jj/mm/yyyy

=item getdate_en

affiche la date au format yyyy/mm/jj

=item gettime

affiche l'heure au format hh:mm:ss

=item tagdate

retourne un tag de la date YYYYMMDD

=item &show_date()

affiche la date en Français sans le jour

=item &show_date_long()

affiche la date en Français avec le jour

=item &show_date_en()

affiche la date en Anglais sans le jour

=item &show_date_long_en()

affiche la date en Anglais avec le jour

=head1 DESCRIPTION

=head2 variables globales

=over 4

=item B<@GLB_month>

description des mois en anglais.

=item B<@GLB_day>

description des jours en anglais.

=item B<@GLB_mois>

description des mois en français.

=item B<@GLB_jour>

description des jours en français.

=head2 functions locales

B<ordinal_en> retourne le nombre en ordinal version anglaise

=head1 EXAMPLE

  1. print &show_date_long();

  2. $v=&show_date_en();

=head1 AUTHOR

  jean-Louis BICQUELET
  version 1.0
  15 fevrier 2006

=cut
