;# ctime.pl is a simple Perl emulation for the well known ctime(3C) function.
;#
;# Waldemar Kebsch, Federal Republic of Germany, November 1988
;# kebsch.pad@nixpbe.UUCP
;# Modified March 1990, Feb 1991 to properly handle timezones
;#  $RCSfile: ctime.pl,v $$Revision: 1.1.1.1 $$Date: 1994/09/10 06:27:52 $
;#   Marion Hakanson (hakanson@cse.ogi.edu)
;#   Oregon Graduate Institute of Science and Technology
;# Modified November 1996 by Andre Hahn (ahahn@zedat.fu-berlin.de)
;#   x translated to the german date format $$Date: 
;#   x example: Dienstag, 18. November 1996 (12:14:45 Uhr)
;#
;# usage:
;#
;#     include "ctime.pl":          # see the -P and -I option in perl.man
;#     $Date = &ctime(time);

sub ctime {
    @DoW = ('Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag');
    @MoY = ('Januar','Februar','M&auml;rz','April','Mai','Juni',
	    'Juli','August','September','Oktober','November','Dezember');
    local($time) = @_;
    local($[) = 0;
    local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
    # Determine what time zone is in effect.
    # Use GMT if TZ is defined as null, local time if TZ undefined.
    # There's no portable way to find the system default timezone.
    $TZ = defined($ENV{'TZ'}) ? ( $ENV{'TZ'} ? $ENV{'TZ'} : 'GMT' ) : '';
    ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
        ($TZ eq 'GMT') ? gmtime($time) : localtime($time);
    # Hack to deal with 'PST8PDT' format of TZ
    # Note that this can't deal with all the esoteric forms, but it
    # does recognize the most common: [:]STDoff[DST[off][,rule]]
    if($TZ=~/^([^:\d+\-,]{3,})([+-]?\d{1,2}(:\d{1,2}){0,2})([^\d+\-,]{3,})?/){
        $TZ = $isdst ? $4 : $1;
    }
    $TZ .= ' ' unless $TZ eq '';
    $year += ($year < 70) ? 2000 : 1900;
    sprintf("%s, %2d. %s %4d (%2d:%02d:%02d Uhr) %s\n",
      $DoW[$wday], $mday, $MoY[$mon], $year, $hour, $min, $sec, $TZ);
}
1;
