Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Import error Links 2.0

Quote Reply
Import error Links 2.0
While importing my Links2.0-DB there occure the following errors:

Import error: WARNING: Invalid date for link with ID 1002432. Link skipped.
Import error: WARNING: Invalid date `8-02-2001' encountered.
Import error: WARNING: Invalid date for link with ID 1002433. Link skipped.
Import error: WARNING: Invalid date `8-02-2001' encountered.
Import error: WARNING: Invalid date for link with ID 1002434. Link skipped.
Import error: WARNING: Invalid date `8-02-2001' encountered.
Import error: WARNING: Invalid date for link with ID 1002436. Link skipped.
Import error: WARNING: Invalid date `8-02-2001' encountered.
Import error: WARNING: Invalid date for link with ID 1002437. Link skipped.

... for every link (categoryies are imported well)

I have changed my date routines in links.cfg as followed and that works fine with Links2.0

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 = shift; my $i;
my %months = map { $_ => $i++ } qw!01 02 03 04 05 06 07 08 09 10 11 12!;
my ($day, $mon, $year) = split(/-/, $date);

exists $months{$mon} or return undef;
$day = int($day); $year = $year - 1900;

require Time::Local;
my $time = 0;
eval {
$time = &Time::Local::timelocal(0,0,0, $day, $months{$mon}, $year);
};
if ($@) { die "invalid date format: $date - parsed as (day: $day, month: $months{$mon}, year: $year). Reason: $@"; }
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 = shift;
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime $time;
my @months = qw!01 02 03 04 05 06 07 08 09 10 11 12!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}


Whats wrong?

Cheers,
Chris

Quote Reply
Re: Import error Links 2.0 In reply to
Your going to need to edit L2S2.pm in the Links/Import directory and change:

Code:
# Converts a date. Returns false if the date is invalid.
sub convert_date ($) {
my $in = shift;
my ($day, $mon, $year) = split /-/, $in, 3;
my %months = qw(Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12);
# Any extra fields needed should be set like this:
# $months{Okt} = "10";
# $months{Mai} = "05";
# $months{Dez} = "12";
#
if ($year and $months{$mon} and $day) {
return sprintf("d-$months{$mon}-d", $year, $day);
} else {
warning "Invalid date `$in' encountered.";
return;
}
}
So that it accepts your custom format.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Import error Links 2.0 In reply to
How do I make this?

My date-format is 'DD-MM-YYYY'

Regards,
Chris

Quote Reply
Re: Import error Links 2.0 In reply to
Try:

Code:
sub convert_date ($) {
my $in = shift;
my ($day, $mon, $year) = split /-/, $in, 3;
if ($year and $mon and $day) {
return sprintf("%0d-%0d-%0d", $year, $mon, $day);
}
else {
warning "Invalid date `$in' encountered.";
return;
}
}
Hope that helps,

Alex

--
Gossamer Threads Inc.

Last edited by:

Alex: Jun 13, 2003, 11:05 AM
Quote Reply
Re: Import error Links 2.0 In reply to
Thanks, that works fine !!!

Chris

Quote Reply
Re: [Alex] Import error Links 2.0 In reply to
Hi, I changed the code proposed by Alex but during the import, links sql convert all dates to 0000-00-00.
My date format in links 2.0 is dd-mm-aa, translated the name of the days and months to others languages.

Links sql can import correctly the dates?
Anyone can help me?

Last edited by:

pedroguerra: Jan 16, 2002, 9:42 AM
Quote Reply
Re: [pedroguerra] Import error Links 2.0 In reply to
upWink this post.
Quote Reply
Re: [Alex] Import error Links 2.0 In reply to
Hi Alex,

I import from links2 (no sql)

In the add date field I have this filled in:
| 15-9-2000 0:00:00 |

When I import into links-sql the add_date is filled with 0000-00-00

I already used your modification because of import errors. (change of L2S2.pm) That worked fine, except what I mentioned above.

Can you help me??
BlushBlush

thanks,
Ron.
Quote Reply
Re: [sahertianr] Import error Links 2.0 In reply to
Hi,

I updated the global for you (it didn't get converted properly when we switched forum software). Can you try the new one?

Cheers,

Alex
--
Gossamer Threads Inc.