Gossamer Forum
Home : Products : Links 2.0 : Customization :

German Date Format?

Quote Reply
German Date Format?
Hi all,

i try to change the date-format from 22-Aug-2000 to 22.08.00

I always get a invalid date format error. I´ve found an article here that did not solve exactly my problem (was from user AnthroRules).

Is there anybody out there who could give me a detailed solution ??

Thanx, Joe

Quote Reply
Re: German Date Format? In reply to
Hope that helps:

in links.cfg...

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";
}

sub long_date {
# --------------------------------------------------------
# This routine is for printing a nicer date format on the what's new page. It should
# take in a date in your current format and return a new one.
my $time = shift;
$time = &date_to_unix ($time);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime $time;
my @months = qw!January February March April May June July August September October November December!;
my @days = qw!Sunday Monday Tuesday Wednesday Thursday Friday Saturday!;
$year = $year + 1900;
return "$days[$dweek], $months[$mon] $day $year";
}

# -------------------------------------------------------------
# Extra Paths -- unless you feel the need to rename files, you
# can leave this as is.

Change to the following...

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 %months = map { $_ => $i++ } qw!Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez!;
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!;
my @months = qw!Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez!;
$year = $year + 1900;
return "$day-$months[$mon]-$year";
}

sub long_date {
# --------------------------------------------------------
# This routine is for printing a nicer date format on the what's new page. It should
# take in a date in your current format and return a new one.
my $time = shift;
$time = &date_to_unix ($time);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $tz) = localtime $time;
# my @months = qw!January February March April May June July August September October November December!;
my @months = qw!Januar Februar März April Mai Juni Juli August September Oktober November Dezember!;
# my @days = qw!Sunday Monday Tuesday Wednesday Thursday Friday Saturday!;
my @days = qw!Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag!;
$year = $year + 1900;
# return "$days[$dweek], $months[$mon] $day $year";
return "$days[$dweek], $day. $months[$mon] $year";
}

# -------------------------------------------------------------
# Extra Paths -- unless you feel the need to rename files, you
# can leave this as is.

Del.

Quote Reply
Re: German Date Format? In reply to
Hi Del Pierro,

thanx for your detailed reply, but it fixes the problem not complete. I want the date as 24.08.2000, not as 24-Aug-2000. In an earlier topic, someone explained, that you have to change site_html_template.pl. This didn´t work for me.

It is not enough to change the "-" to "." in links.cfg

It would be fine, if someone could help!

Joe

Quote Reply
Re: German Date Format? In reply to
I wonder what will happen if you change
my @months = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
to
my @months = qw!01 02 03 04 05 06 07 08 09 10 11 12!;

John


Quote Reply
Re: German Date Format? In reply to
This will not change the "-" in 24-Aug-2000 ;-)



Quote Reply
Re: German Date Format? In reply to
No, but I assumed you were using Del's mod, which will.

Quote Reply
Re: German Date Format? In reply to
Search for: "JPDeni - Date Translator"

- Chris