Gossamer Forum
Home : Products : Links 2.0 : Installation -- Unix :

still getting date field error

Quote Reply
still getting date field error
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
Quote Reply
Re: still getting date field error In reply to
What is the error message you are getting and when does it occur?

------------------
Bob Connors
bobsie@orphanage.com
www.orphanage.com/goodstuff/
Quote Reply
Re: still getting date field error In reply to
oops...my mistake. That is the links.cfg
file.

Here is what is in the add.cgi referencing
the date function:

# Set date variable to today's date.
$in{$db_cols[$db_modified]} = &get_date;

open (ID, "<$db_links_id_file_name") or &cgierr("error in process_form. unable to open id file: $db_links_id_file_name. Reason: $!");
$in{$db_key} = <ID> + 1; # Get next ID number
close ID;

Cynthia