Gossamer Forum
Home : Products : DBMan : Customization :

Auto-Delete Mod with Different Date Format

Quote Reply
Auto-Delete Mod with Different Date Format
 
I am having a little trouble getting the auto-delete script to run and I think it may be because I have the dates in the default.db set to "04/04/00" instead of the normal setting "4-Apr-2000".

I need to know how to set the sub get_date and sub date_to_unix section correctly.



------------------
Michael Liimatta, Director of Education
International Union of Gospel Missions
1045 Swift, Kansas City, MO 64116 USA
Phone: 816.471.8020 - FAX 816.471.3718
http://www.iugm.org/michael.html
Quote Reply
Re: Auto-Delete Mod with Different Date Format In reply to
It's a very bad idea to use two-digit years. It's hard to convert "00" to "2000."

However, I might have a solution for you. I just did some more work on my "universal date translator" mod last night. Are you willing to test it for me?

You can pick up the mod at
http://www.jpdeni.com/.../date_translator.txt .

It will do more than you need, but it won't hurt anything to have it the extra stuff there.

BTW, just last night I added code to allow for two-digit years. Smile

Be sure you save copies of all your files in a safe place before you install the mod, in case it doesn't work!!

------------------
JPD






Quote Reply
Re: Auto-Delete Mod with Different Date Format In reply to
 
Thanks for the response!!

I am a little unclear about how this relates to the auto-delete script.

PS - The dates I am referring to look like this - "04/04/2000"

<a href="http://www.kcphilnet.org/jobsourc/jobs.html">KCPhilanthroNET Job Source</a>

------------------
Michael Liimatta, Director of Education
International Union of Gospel Missions
1045 Swift, Kansas City, MO 64116 USA
Phone: 816.471.8020 - FAX 816.471.3718
http://www.iugm.org/michael.html
Quote Reply
Re: Auto-Delete Mod with Different Date Format In reply to
I'm a little confused. In your first post you said

Quote:
I have the dates in the default.db set to "04/04/00"

and in your more recent one, you said

Quote:
The dates I am referring to look like this - "04/04/2000"

The structure of the dates makes a huge difference.

I'm assuming that your change in the date structure is in sub get_date. Did you also change sub date_to_unix to match?

(BTW, don't worry about using the mod. If your dates have 4-digit years, we can work out the problem.)


------------------
JPD






Quote Reply
Re: Auto-Delete Mod with Different Date Format In reply to
 
Actually, the first post had a typo! The year is in fact 4-digit.

I did change both sections of db.cgi as you mentioned. I am not sure, though, of how the date sections in the DBman script relate to the auto-delete script.

Isn't it a stand-alone process that you can execute through a web browser to delete listings older than, say, 90 days?

Anyway, here's how I set these sections you noted in a script called deljobs.cgi:
sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yyyy".
# Warning: If you change the default format, you must also modify the
# date_to_unix subroutine below which converts your date format into a # unix time in seconds for sorting purposes.

my ($time1) = $_[0];
($time1) or ($time1 = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$mon += 1;
($mon < 10) and ($mon = "0$mon");
$year += 1900;
return "$mon\/$day\/$year";
}

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

my ($date) = $_[0];

my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($day and $mon and $year) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$day, $mon, $year);
};

if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}



------------------
Michael Liimatta, Director of Education
International Union of Gospel Missions
1045 Swift, Kansas City, MO 64116 USA
Phone: 816.471.8020 - FAX 816.471.3718
http:// www.iugm.org/michael.html

Quote Reply
Re: Auto-Delete Mod with Different Date Format In reply to
I do understand about typos. I make them all the time. Smile

Your date routines look good. You'll need to replace sub date_to_unix in the auto delete script as well. Then it will be able to translate your dates.


------------------
JPD






Quote Reply
Re: Auto-Delete Mod with Different Date Format In reply to
 
Actually, these are the rountines from the auto-delete script!

Maybe I'm doing something else wrong?

See anything else in here that's out of kilter:

# Required Files to make this file work.

# Required Files to make this file work.

require "/web/hosted/philnet/cgi-bin/db/default.cfg";

# Change to the correct field number

my $removeby_field = 22;

# Change to the correct field number

my $dateadded_field = 20;

my $today = &date_to_unix(&get_date);
my (@lines, @values);

print "Content-type: text/plain\n\n";
open (DB, $db_file_name) or ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) {
flock (DB, 1);
}
@lines = <DB>;
close DB;

open (DB, ">$db_file_name") or ("Can't open:$db_file_name. Reason: $!");
if ($db_use_flock) {
flock (DB, 2);
}
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
print "Comparing: '$today' vs '$values[$removeby_field]' ... \n";
if ($today > (&date_to_unix($values[$dateadded_field]) + (86400 * $values[$removeby_field]))) {
print "Record(s) Deleted\n";
next;
}
print DB $_, "\n";
}
close DB;

sub get_date {
# --------------------------------------------------------
# Returns the date in the format "dd-mmm-yyyy".
# Warning: If you change the default format, you must also modify the
# date_to_unix subroutine below which converts your date format into a # unix time in seconds for sorting purposes.

my ($time1) = $_[0];
($time1) or ($time1 = time());

my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$mon += 1;
($mon < 10) and ($mon = "0$mon");
$year += 1900;
return "$mon\/$day\/$year";
}

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

my ($date) = $_[0];

my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
unless ($day and $mon and $year) { return undef; }

use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900; $mon = int($mon) - 1;
$time = timelocal(0,0,0,$day, $mon, $year);
};

if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}

sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.

my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}


------------------
Michael Liimatta, Director of Education
International Union of Gospel Missions
1045 Swift, Kansas City, MO 64116 USA
Phone: 816.471.8020 - FAX 816.471.3718
http:// www.iugm.org/michael.html