Commit | Line | Data |
b1248f16 |
1 | ;# ctime.pl is a simple Perl emulation for the well known ctime(3C) function. |
2 | ;# |
3 | ;# Waldemar Kebsch, Federal Republic of Germany, November 1988 |
4 | ;# kebsch.pad@nixpbe.UUCP |
5 | ;# Modified March 1990 to better handle timezones |
6 | ;# $Id: ctime.pl,v 1.3 90/03/22 10:49:10 hakanson Exp $ |
7 | ;# Marion Hakanson (hakanson@cse.ogi.edu) |
8 | ;# Oregon Graduate Institute of Science and Technology |
9 | ;# |
10 | ;# usage: |
11 | ;# |
12 | ;# #include <ctime.pl> # see the -P and -I option in perl.man |
ff8e2863 |
13 | ;# $Date = &ctime(time); |
b1248f16 |
14 | |
7e1cf235 |
15 | CONFIG: { |
16 | package ctime; |
17 | |
18 | @DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); |
19 | @MoY = ('Jan','Feb','Mar','Apr','May','Jun', |
20 | 'Jul','Aug','Sep','Oct','Nov','Dec'); |
21 | } |
b1248f16 |
22 | |
23 | sub ctime { |
7e1cf235 |
24 | package ctime; |
25 | |
b1248f16 |
26 | local($time) = @_; |
27 | local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst); |
28 | |
29 | # Use GMT if can't find local TZ |
30 | $TZ = defined($ENV{'TZ'}) ? $ENV{'TZ'} : 'GMT'; |
31 | ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = |
32 | ($TZ eq 'GMT') ? gmtime($time) : localtime($time); |
33 | # Hack to deal with 'PST8PDT' format of TZ |
34 | if ( $TZ =~ /-?\d+/ ) { |
35 | $TZ = $isdst ? $' : $`; |
36 | } |
37 | $TZ .= " " unless $TZ eq ""; |
38 | $year += ($year < 70) ? 2000 : 1900; |
39 | sprintf("%s %s %2d %2d:%02d:%02d %s%4d\n", |
40 | $DoW[$wday], $MoY[$mon], $mday, $hour, $min, $sec, $TZ, $year); |
41 | } |
42 | 1; |