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