summaryrefslogtreecommitdiff
path: root/lib/ctime.pl
diff options
context:
space:
mode:
authorLarry Wall <lwall@jpl-devvax.jpl.nasa.gov>1990-03-27 04:26:14 +0000
committerLarry Wall <lwall@jpl-devvax.jpl.nasa.gov>1990-03-27 04:26:14 +0000
commitb1248f16cd8cccfb12ae16cd8e7e93dd53dc52bf (patch)
tree1fdfdda5e27fc0097610165787c59a4238b5fcf1 /lib/ctime.pl
parent21d892ea46b4eaa5d8ae1c8cd325d9940deef5b3 (diff)
downloadperl-b1248f16cd8cccfb12ae16cd8e7e93dd53dc52bf.tar.gz
perl 3.0 patch #17 patch #16, continued
See patch #16.
Diffstat (limited to 'lib/ctime.pl')
-rw-r--r--lib/ctime.pl36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/ctime.pl b/lib/ctime.pl
new file mode 100644
index 0000000000..d3b03545ca
--- /dev/null
+++ b/lib/ctime.pl
@@ -0,0 +1,36 @@
+;# 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 to better handle timezones
+;# $Id: ctime.pl,v 1.3 90/03/22 10:49:10 hakanson Exp $
+;# Marion Hakanson (hakanson@cse.ogi.edu)
+;# Oregon Graduate Institute of Science and Technology
+;#
+;# usage:
+;#
+;# #include <ctime.pl> # see the -P and -I option in perl.man
+;# $Date = do ctime(time);
+
+@DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
+@MoY = ('Jan','Feb','Mar','Apr','May','Jun',
+ 'Jul','Aug','Sep','Oct','Nov','Dec');
+
+sub ctime {
+ local($time) = @_;
+ 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';
+ ($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 ? $' : $`;
+ }
+ $TZ .= " " unless $TZ eq "";
+ $year += ($year < 70) ? 2000 : 1900;
+ sprintf("%s %s %2d %2d:%02d:%02d %s%4d\n",
+ $DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZ, $year);
+}
+1;