X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fctime.pl;h=14e122adda0bdab0a009aaf8acc6ac456e8846c0;hb=054b02d6604bb3beeebed2d8a040d025b131c9a6;hp=f910db757d878cccdbec01999322c38d355f558c;hpb=ff8e2863486f651339834bc9e3e0bd49d61ff4e1;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/ctime.pl b/lib/ctime.pl index f910db7..14e122a 100644 --- a/lib/ctime.pl +++ b/lib/ctime.pl @@ -2,8 +2,8 @@ ;# ;# Waldemar Kebsch, Federal Republic of Germany, November 1988 ;# kebsch.pad@nixpbe.UUCP -;# Modified March 1990 to better handle timezones -;# $Id: ctime.pl,v 1.3 90/03/22 10:49:10 hakanson Exp $ +;# Modified March 1990, Feb 1991 to properly handle timezones +;# $RCSfile: ctime.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:23:47 $ ;# Marion Hakanson (hakanson@cse.ogi.edu) ;# Oregon Graduate Institute of Science and Technology ;# @@ -12,24 +12,39 @@ ;# #include # see the -P and -I option in perl.man ;# $Date = &ctime(time); -@DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); -@MoY = ('Jan','Feb','Mar','Apr','May','Jun', - 'Jul','Aug','Sep','Oct','Nov','Dec'); +CONFIG: { + package ctime; + + @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); + @MoY = ('Jan','Feb','Mar','Apr','May','Jun', + 'Jul','Aug','Sep','Oct','Nov','Dec'); +} sub ctime { + package ctime; + local($time) = @_; + local($[) = 0; local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst); - # Use GMT if can't find local TZ - $TZ = defined($ENV{'TZ'}) ? $ENV{'TZ'} : 'GMT'; + # 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 - if ( $TZ =~ /-?\d+/ ) { - $TZ = $isdst ? $' : $`; + # 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; + $TZ .= ' ' unless $TZ eq ''; + + $year += 1900; sprintf("%s %s %2d %2d:%02d:%02d %s%4d\n", $DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZ, $year); }