Gossamer Forum
Home : Products : Links 2.0 : Customization :

Date Modification - I found!!!

Quote Reply
Date Modification - I found!!!
       Hey, i found out how to "manipulate" dates on Links 2. I need it because I live in a
country and my server is in another, so I need to change the date to my country system.
If you have a similar problem you should know how many hours you want to add or
take out from the real date on the server.
For example. In your country is 15:00 pm, and your server date is 18:00 pm, so you want
to take out 3 hours from the serverīs date. Now, you need to calculate how many seconds you does
this hours meand. If 1 hour is 3600 seconds, so 3 hours are 10800 seconds.
Now, go to the file links.cfg and change
Code:
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 Fev Mar Abr Maio Jun Jul Ago Set Out Nov Dez!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}

to

Code:
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 -10800));
my @months = qw!Jan Fev Mar Abr Maio Jun Jul Ago Set Out Nov Dez!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}

Noticed the changes? Now, the localtime calls the $time less 10800 seconds. Ok, this is for
the date. For the time, you should go to db_utils.pl and change

Code:
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my $time = shift;
$time | |= time();
my ($sec, $min, $hour, @junk) = localtime $time;
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

to

Code:
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my $time = shift;
$time &#0124; &#0124;= time();
my ($sec, $min, $hour, @junk) = (localtime ($time-10800));
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

If you need to add a certain number of seconds, just change - to +. Ie. If you need
to add four hours, you change my "- 10800" to "+ 14400".

Isnīt it right Alex???


Thiago Moretti
Webmaster Busca BR
http://www.buscabr.com
webmaster@buscabr.com



Busca BR,
O nosso sistema de busca no Brasil
Quote Reply
Re: Date Modification - I found!!! In reply to
Hi,

Yes, that's exactly what you need to do. Also, if you want to change the format of the date, those are the only two subroutines you need to update.

Cheers,

Alex
Quote Reply
Re: Date Modification - I found!!! In reply to
tmoretti,

did you also find how to change the date format to 1999-Apr-30?

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


when I change every order of $day, $mon, $year in link.cfg to $year, $mon, $day,
it gives me just wrong year and day.

I know that many of you do not have any interest to change the date mode since you live with western culture. However, think about the others...

If anybody knows how to change it, please share the idea.

[This message has been edited by sofine (edited April 30, 1999).]
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).]
Quote Reply
Re: Date Modification - I found!!! In reply to
tmoretti,

It's just what I need.

Thanks.

Almas
Quote Reply
Re: Date Modification - I found!!! In reply to
   It greats isnīt it?
I have never imagined how to do that but I saw it on another script created by a friend and I tried to implement that into Links and I found out how...
Quote Reply
Re: Date Modification - I found!!! In reply to
Sofine,

Have you tried it yet? Any problems with it? The change to YYYY-MMM-DD I mean.

[This message has been edited by Bobsie (edited May 02, 1999).]
Quote Reply
Re: Date Modification - I found!!! In reply to
I just applied it.
Your code works fine.

Thanks, Bobsie.
Quote Reply
Re: Date Modification - I found!!! In reply to
How can I set the date format to 1/1/00 (mm/dd/yy)?

------------------
- YellowKard -

Quote Reply
Re: Date Modification - I found!!! In reply to
That would be complex, because you would have to make dramatic changes to the subs mentioned in this Topic.

The better solution is to use the following format:

mm/day/yy

rather than numbers for the months.

The problem is getting the sub date_to_unix routine to calculate the months with numbers rather than converting from letters to numbers.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Date Modification - I found!!! In reply to
Its know biggy, I checked it out my self and it would take alot of work. I'll just use it if somone comes out with a date format mod.

------------------
- YellowKard -


Quote Reply
Re: Date Modification - I found!!! In reply to
I wrote a few times on the forum, that I wrote a general international date formet mod.
It's finished already, but I will have to write a detailed install tutorial, because it's a difficult mod.
(also I will have to add some features suggested by Eliot, before I release it)
It will take some time, until I can release it, but I can promise I will release it for the public.

Regards,
Webmaster33