Here is what the date routines in add.cgi
look like:
# Date Routines
# --------------------------------------------------------
# Your date format can be whatever you like, as long as the following
# two functions are defined &date_to_unix and &unix_to_date:
# The default is dd-mmm-yyyy.
sub date_to_unix {
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# timelocal does not like to be in array context, don't do my($time) = timelocal (..)
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(/-/, $_[0]);
if (!defined($months{$mon})) { die "invalid date format: $date. Reason: unkown month: $mon"; }
$day = int($day); $year = $year - 1900;
use Time::Local;
eval {
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { die ("invalid date format: $date. Reason: $@"); } # Could return 0 if you want.
return ($time);
}
sub unix_to_date {
# This routine must take a unix time and return your date format
# A much simpler routine, just make sure your format isn't so complex that
# you can't get it back into unix time.
#
my ($time) = $_[0];
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}
sub long_date {
# This routine is for printing a nicer date format on the what's new page. It should
# take in a date in your current format and return a new one.
my ($time) = $_[0];
$time = &date_to_unix ($time);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!January February March April May June July August September October November December!;
my (@days) = qw!Sunday Monday Tuesday Wednesday Thursday Friday Saturday!;
$year = $year + 1900;
return "$days[$dweek], $months[$mon] $day $year";
}
1;
Now am I just supposed to select ONE of
those 3 routines? I am so confused. Please
help )
Cheers,
Cynthia
look like:
# Date Routines
# --------------------------------------------------------
# Your date format can be whatever you like, as long as the following
# two functions are defined &date_to_unix and &unix_to_date:
# The default is dd-mmm-yyyy.
sub date_to_unix {
# This routine must take your date format and return the time a la UNIX time().
# Some things to be careful about..
# timelocal does not like to be in array context, don't do my($time) = timelocal (..)
# int your values just in case to remove spaces, etc.
# catch the fatal error timelocal will generate if you have a bad date..
# don't forget that the month is indexed from 0!
#
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($day, $mon, $year) = split(/-/, $_[0]);
if (!defined($months{$mon})) { die "invalid date format: $date. Reason: unkown month: $mon"; }
$day = int($day); $year = $year - 1900;
use Time::Local;
eval {
$time = timelocal(0,0,0,$day, $months{$mon}, $year);
};
if ($@) { die ("invalid date format: $date. Reason: $@"); } # Could return 0 if you want.
return ($time);
}
sub unix_to_date {
# This routine must take a unix time and return your date format
# A much simpler routine, just make sure your format isn't so complex that
# you can't get it back into unix time.
#
my ($time) = $_[0];
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}
sub long_date {
# This routine is for printing a nicer date format on the what's new page. It should
# take in a date in your current format and return a new one.
my ($time) = $_[0];
$time = &date_to_unix ($time);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time);
my (@months) = qw!January February March April May June July August September October November December!;
my (@days) = qw!Sunday Monday Tuesday Wednesday Thursday Friday Saturday!;
$year = $year + 1900;
return "$days[$dweek], $months[$mon] $day $year";
}
1;
Now am I just supposed to select ONE of
those 3 routines? I am so confused. Please
help )
Cheers,
Cynthia