1*0Sstevel@tonic-gate;# ctime.pl is a simple Perl emulation for the well known ctime(3C) function. 2*0Sstevel@tonic-gate# 3*0Sstevel@tonic-gate# This library is no longer being maintained, and is included for backward 4*0Sstevel@tonic-gate# compatibility with Perl 4 programs which may require it. 5*0Sstevel@tonic-gate# 6*0Sstevel@tonic-gate# In particular, this should not be used as an example of modern Perl 7*0Sstevel@tonic-gate# programming techniques. 8*0Sstevel@tonic-gate# 9*0Sstevel@tonic-gate# Suggested alternative: the POSIX ctime function 10*0Sstevel@tonic-gate;# 11*0Sstevel@tonic-gate;# Waldemar Kebsch, Federal Republic of Germany, November 1988 12*0Sstevel@tonic-gate;# kebsch.pad@nixpbe.UUCP 13*0Sstevel@tonic-gate;# Modified March 1990, Feb 1991 to properly handle timezones 14*0Sstevel@tonic-gate;# $RCSfile: ctime.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:23:47 $ 15*0Sstevel@tonic-gate;# Marion Hakanson (hakanson@cse.ogi.edu) 16*0Sstevel@tonic-gate;# Oregon Graduate Institute of Science and Technology 17*0Sstevel@tonic-gate;# 18*0Sstevel@tonic-gate;# usage: 19*0Sstevel@tonic-gate;# 20*0Sstevel@tonic-gate;# #include <ctime.pl> # see the -P and -I option in perl.man 21*0Sstevel@tonic-gate;# $Date = &ctime(time); 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gateCONFIG: { 24*0Sstevel@tonic-gate package ctime; 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); 27*0Sstevel@tonic-gate @MoY = ('Jan','Feb','Mar','Apr','May','Jun', 28*0Sstevel@tonic-gate 'Jul','Aug','Sep','Oct','Nov','Dec'); 29*0Sstevel@tonic-gate} 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gatesub ctime { 32*0Sstevel@tonic-gate package ctime; 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate local($time) = @_; 35*0Sstevel@tonic-gate local($[) = 0; 36*0Sstevel@tonic-gate local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst); 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate # Determine what time zone is in effect. 39*0Sstevel@tonic-gate # Use GMT if TZ is defined as null, local time if TZ undefined. 40*0Sstevel@tonic-gate # There's no portable way to find the system default timezone. 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate $TZ = defined($ENV{'TZ'}) ? ( $ENV{'TZ'} ? $ENV{'TZ'} : 'GMT' ) : ''; 43*0Sstevel@tonic-gate ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = 44*0Sstevel@tonic-gate ($TZ eq 'GMT') ? gmtime($time) : localtime($time); 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate # Hack to deal with 'PST8PDT' format of TZ 47*0Sstevel@tonic-gate # Note that this can't deal with all the esoteric forms, but it 48*0Sstevel@tonic-gate # does recognize the most common: [:]STDoff[DST[off][,rule]] 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate if($TZ=~/^([^:\d+\-,]{3,})([+-]?\d{1,2}(:\d{1,2}){0,2})([^\d+\-,]{3,})?/){ 51*0Sstevel@tonic-gate $TZ = $isdst ? $4 : $1; 52*0Sstevel@tonic-gate } 53*0Sstevel@tonic-gate $TZ .= ' ' unless $TZ eq ''; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate $year += 1900; 56*0Sstevel@tonic-gate sprintf("%s %s %2d %2d:%02d:%02d %s%4d\n", 57*0Sstevel@tonic-gate $DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZ, $year); 58*0Sstevel@tonic-gate} 59*0Sstevel@tonic-gate1; 60