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