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