Gossamer Forum
Home : Products : Links 2.0 : Customization :

Re: Date Modification - I found!!!

Quote Reply
Re: Date Modification - I found!!! In reply to
Here is how to change the date formats the way you want them (Year-Month-Day):

Code:
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!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
my ($year, $mon, $day) = 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!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
$year = $year + 1900;
return "$year-$months[$mon]-$day";
}

Now, go into nph-build.cgi and find and change all occurances of "1-Jan-1990" (there are 3 of them) to "1990-Jan-1" and you will be all set.

If your links.db already has the dates in it in the dd-mmm-yyyy format, use the following script to change those dates. Just put the script in your admin/data directory, chmod the data directory to 777 (if it is not already) and the script to 755, then execute the script. It will create a file called links_new.db which should contain the new date format. Just rename that file to links.db (I highly recommend you save the original links.db first).

Code:
#!/usr/bin/perl
# -------------------------------------------
require "../links.cfg";
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";

$ENV{'REQUEST_METHOD'} and (print "Content-type: text/plain\n\n");
open (DB, "<links.db")
or print "Unable to open links database 'links.db'. Reason: $!" and exit;
open (DBOUT, ">links_new.db")
or print "Unable to open output database. Reason: $!" and exit;
LINE: while (<DB> )
{
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
($d, $m, $y) = split(/-/,$rec[$db_modified]);
$rec[$db_modified] = "$y-$m-$d";
print DBOUT &join_encode(&array_to_hash(0, @rec));
}
close DB;
close DBOUT;
# ---------------------------------------------

I hope this helps.

[This message has been edited by Bobsie (edited May 01, 1999).]
Subject Author Views Date
Thread Date Modification - I found!!! tmoretti 2941 Apr 29, 1999, 9:14 PM
Post Re: Date Modification - I found!!!
Alex 2891 Apr 30, 1999, 1:58 PM
Post Re: Date Modification - I found!!!
sofine 2869 Apr 30, 1999, 4:16 PM
Post Re: Date Modification - I found!!!
Bobsie 2876 Apr 30, 1999, 7:04 PM
Post Re: Date Modification - I found!!!
almas 2897 May 1, 1999, 6:57 PM
Post Re: Date Modification - I found!!!
tmoretti 2866 May 2, 1999, 5:04 AM
Post Re: Date Modification - I found!!!
Bobsie 2867 May 2, 1999, 11:49 AM
Post Re: Date Modification - I found!!!
sofine 2884 May 2, 1999, 9:31 PM
Post Re: Date Modification - I found!!!
YellowKard 2861 May 9, 2000, 2:10 PM
Post Re: Date Modification - I found!!!
Stealth 2859 May 9, 2000, 5:23 PM
Post Re: Date Modification - I found!!!
YellowKard 2888 May 11, 2000, 4:45 PM
Post Re: Date Modification - I found!!!
webmaster33 2865 May 12, 2000, 3:41 AM