Well the game_news database is in and working like a charm. Except for the date/time sort.
www.makeitsimple.com/cgi-bin/dbman/game_news/db.cgi?db=default&uid=default&sb=ID&so=descend&view_records=1&ID=*
I gave it a test run and thought it was ok but apparently not. Everything with the date/time subs works except sorting.
I did make one change when I put in the subs that you gave me JPD. All I did was swap the month and day positions. I did it in both subs and it didn't kick out any errors. Which leads me to think that there is still a snibit of logic missing.
See if you can spot any problems:
sub get_date {
my ($time) = @_;
($time) | | ($time = time());
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!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");
return "$months[$mon]-$day-$year $hour:$min:$sec";
}
*******************
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..
# 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_and_time) = $_[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 ($date, $time) = split(/ /, $_[0]);
my ($mon, $day, $year) = split(/-/, $date);
my ($hour, $min, $sec) = split(/:/, $time);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal($sec,$min,$hour,$day,$months{$mon},$year);
};
if ($@) { return undef;} # Could return 0 if you want.
return (time);
}
I intentionally shortened the long line so it wouldn't mess up UBB.
JPD, I am hitting the sack, I am fried. Maybe you can spot something that I did wrong or come up with another idea.
No hurry, I figured out a way to temporarily get around the problem by advancing the count# to 2000. All of the new posts are 2000 and up, when I want to add the old records I change the count to the last old record and start filling in the gap. That allows sorting by ID without a problem. Tricky eh?
Wishing you luck!
------------------
Larry "NgtCrwlr" Mingus
www.makeitsimple.com
[This message has been edited by NgtCrwlr (edited May 12, 1999).]
[This message has been edited by NgtCrwlr (edited May 12, 1999).]
www.makeitsimple.com/cgi-bin/dbman/game_news/db.cgi?db=default&uid=default&sb=ID&so=descend&view_records=1&ID=*
I gave it a test run and thought it was ok but apparently not. Everything with the date/time subs works except sorting.
Quote:
I forgot to add that the field (PostTime) is where I am using the new date/time sub. So, if you get a chance to try it remember to sort by PostTime.I did make one change when I put in the subs that you gave me JPD. All I did was swap the month and day positions. I did it in both subs and it didn't kick out any errors. Which leads me to think that there is still a snibit of logic missing.
See if you can spot any problems:
sub get_date {
my ($time) = @_;
($time) | | ($time = time());
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!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");
return "$months[$mon]-$day-$year $hour:$min:$sec";
}
*******************
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..
# 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_and_time) = $_[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 ($date, $time) = split(/ /, $_[0]);
my ($mon, $day, $year) = split(/-/, $date);
my ($hour, $min, $sec) = split(/:/, $time);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal($sec,$min,$hour,$day,$months{$mon},$year);
};
if ($@) { return undef;} # Could return 0 if you want.
return (time);
}
I intentionally shortened the long line so it wouldn't mess up UBB.
JPD, I am hitting the sack, I am fried. Maybe you can spot something that I did wrong or come up with another idea.
No hurry, I figured out a way to temporarily get around the problem by advancing the count# to 2000. All of the new posts are 2000 and up, when I want to add the old records I change the count to the last old record and start filling in the gap. That allows sorting by ID without a problem. Tricky eh?
Wishing you luck!
------------------
Larry "NgtCrwlr" Mingus
www.makeitsimple.com
[This message has been edited by NgtCrwlr (edited May 12, 1999).]
[This message has been edited by NgtCrwlr (edited May 12, 1999).]