line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 1995-2009 Graham Barr. This program is free |
2
|
|
|
|
|
|
|
# software; you can redistribute it and/or modify it under the same terms |
3
|
|
|
|
|
|
|
# as Perl itself. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Date::Format; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
73354
|
use strict; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
147
|
|
8
|
4
|
|
|
4
|
|
25
|
use vars qw(@EXPORT @ISA $VERSION); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
941
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = "2.24"; |
12
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
@EXPORT = qw(time2str strftime ctime asctime); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub time2str ($;$$) |
16
|
|
|
|
|
|
|
{ |
17
|
150
|
|
|
150
|
1
|
942
|
Date::Format::Generic->time2str(@_); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub strftime ($\@;$) |
21
|
|
|
|
|
|
|
{ |
22
|
1
|
|
|
1
|
1
|
121
|
Date::Format::Generic->strftime(@_); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub ctime ($;$) |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
1
|
0
|
my($t,$tz) = @_; |
28
|
0
|
|
|
|
|
0
|
Date::Format::Generic->time2str("%a %b %e %T %Y\n", $t, $tz); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub asctime (\@;$) |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
0
|
1
|
0
|
my($t,$tz) = @_; |
34
|
0
|
|
|
|
|
0
|
Date::Format::Generic->strftime("%a %b %e %T %Y\n", $t, $tz); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## |
38
|
|
|
|
|
|
|
## |
39
|
|
|
|
|
|
|
## |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
package Date::Format::Generic; |
42
|
|
|
|
|
|
|
|
43
|
4
|
|
|
4
|
|
28
|
use vars qw($epoch $tzname); |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
211
|
|
44
|
4
|
|
|
4
|
|
1423
|
use Time::Zone; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
305
|
|
45
|
4
|
|
|
4
|
|
1038
|
use Time::Local; |
|
4
|
|
|
|
|
4585
|
|
|
4
|
|
|
|
|
10454
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ctime |
48
|
|
|
|
|
|
|
{ |
49
|
4
|
|
|
4
|
|
47
|
my($me,$t,$tz) = @_; |
50
|
4
|
|
|
|
|
19
|
$me->time2str("%a %b %e %T %Y\n", $t, $tz); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub asctime |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
0
|
|
0
|
my($me,$t,$tz) = @_; |
56
|
0
|
|
|
|
|
0
|
$me->strftime("%a %b %e %T %Y\n", $t, $tz); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _subs |
60
|
|
|
|
|
|
|
{ |
61
|
377
|
|
|
377
|
|
488
|
my $fn; |
62
|
377
|
|
|
|
|
2465
|
$_[1] =~ s/ |
63
|
|
|
|
|
|
|
%(O?[%a-zA-Z]) |
64
|
|
|
|
|
|
|
/ |
65
|
1182
|
|
100
|
4
|
|
6262
|
($_[0]->can("format_$1") || sub { $1 })->($_[0]); |
|
4
|
|
|
|
|
17
|
|
66
|
|
|
|
|
|
|
/sgeox; |
67
|
|
|
|
|
|
|
|
68
|
377
|
|
|
|
|
1579
|
$_[1]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub strftime |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
1
|
|
1
|
my($pkg,$fmt,$time); |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
3
|
($pkg,$fmt,$time,$tzname) = @_; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
4
|
my $me = ref($pkg) ? $pkg : bless []; |
78
|
|
|
|
|
|
|
|
79
|
1
|
50
|
|
|
|
3
|
if(defined $tzname) |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
0
|
$tzname = uc $tzname; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
0
|
$tzname = sprintf("%+05d",$tzname) |
84
|
|
|
|
|
|
|
unless($tzname =~ /\D/); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
$epoch = timegm(@{$time}[0..5]); |
|
0
|
|
|
|
|
0
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
@$me = gmtime($epoch + tz_offset($tzname) - tz_offset()); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else |
91
|
|
|
|
|
|
|
{ |
92
|
1
|
|
|
|
|
2
|
@$me = @$time; |
93
|
1
|
|
|
|
|
2
|
undef $epoch; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
3
|
_subs($me,$fmt); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub time2str |
100
|
|
|
|
|
|
|
{ |
101
|
356
|
|
|
356
|
|
108386
|
my($pkg,$fmt,$time); |
102
|
|
|
|
|
|
|
|
103
|
356
|
|
|
|
|
808
|
($pkg,$fmt,$time,$tzname) = @_; |
104
|
|
|
|
|
|
|
|
105
|
356
|
100
|
|
|
|
1017
|
my $me = ref($pkg) ? $pkg : bless [], $pkg; |
106
|
|
|
|
|
|
|
|
107
|
356
|
|
|
|
|
549
|
$epoch = $time; |
108
|
|
|
|
|
|
|
|
109
|
356
|
100
|
|
|
|
610
|
if(defined $tzname) |
110
|
|
|
|
|
|
|
{ |
111
|
351
|
|
|
|
|
632
|
$tzname = uc $tzname; |
112
|
|
|
|
|
|
|
|
113
|
351
|
50
|
|
|
|
1332
|
$tzname = sprintf("%+05d",$tzname) |
114
|
|
|
|
|
|
|
unless($tzname =~ /\D/); |
115
|
|
|
|
|
|
|
|
116
|
351
|
|
|
|
|
936
|
$time += tz_offset($tzname); |
117
|
351
|
|
|
|
|
1891
|
@$me = gmtime($time); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else |
120
|
|
|
|
|
|
|
{ |
121
|
5
|
|
|
|
|
176
|
@$me = localtime($time); |
122
|
|
|
|
|
|
|
} |
123
|
356
|
|
|
|
|
904
|
$me->[9] = $time; |
124
|
356
|
|
|
|
|
777
|
_subs($me,$fmt); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my(@DoW,@MoY,@DoWs,@MoYs,@AMPM,%format,@Dsuf); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
@DoW = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
@MoY = qw(January February March April May June |
132
|
|
|
|
|
|
|
July August September October November December); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
@DoWs = map { substr($_,0,3) } @DoW; |
135
|
|
|
|
|
|
|
@MoYs = map { substr($_,0,3) } @MoY; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
@AMPM = qw(AM PM); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
@Dsuf = (qw(th st nd rd th th th th th th)) x 3; |
140
|
|
|
|
|
|
|
@Dsuf[11,12,13] = qw(th th th); |
141
|
|
|
|
|
|
|
@Dsuf[30,31] = qw(th st); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
%format = ('x' => "%m/%d/%y", |
144
|
|
|
|
|
|
|
'C' => "%a %b %e %T %Z %Y", |
145
|
|
|
|
|
|
|
'X' => "%H:%M:%S", |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my @locale; |
149
|
|
|
|
|
|
|
my $locale = "/usr/share/lib/locale/LC_TIME/default"; |
150
|
|
|
|
|
|
|
local *LOCALE; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
if(open(LOCALE,"$locale")) |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
chop(@locale = ); |
155
|
|
|
|
|
|
|
close(LOCALE); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
@MoYs = @locale[0 .. 11]; |
158
|
|
|
|
|
|
|
@MoY = @locale[12 .. 23]; |
159
|
|
|
|
|
|
|
@DoWs = @locale[24 .. 30]; |
160
|
|
|
|
|
|
|
@DoW = @locale[31 .. 37]; |
161
|
|
|
|
|
|
|
@format{"X","x","C"} = @locale[38 .. 40]; |
162
|
|
|
|
|
|
|
@AMPM = @locale[41 .. 42]; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub wkyr { |
166
|
8
|
|
|
8
|
|
22
|
my($wstart, $wday, $yday) = @_; |
167
|
8
|
|
|
|
|
33
|
$wday = ($wday + 7 - $wstart) % 7; |
168
|
8
|
|
|
|
|
88
|
return int(($yday - $wday + 13) / 7 - 1); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
## |
172
|
|
|
|
|
|
|
## these 6 formatting routins need to be *copied* into the language |
173
|
|
|
|
|
|
|
## specific packages |
174
|
|
|
|
|
|
|
## |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
my @roman = ('',qw(I II III IV V VI VII VIII IX)); |
177
|
|
|
|
|
|
|
sub roman { |
178
|
48
|
|
|
48
|
|
93
|
my $n = shift; |
179
|
|
|
|
|
|
|
|
180
|
48
|
|
|
|
|
155
|
$n =~ s/(\d)$//; |
181
|
48
|
|
|
|
|
129
|
my $r = $roman[ $1 ]; |
182
|
|
|
|
|
|
|
|
183
|
48
|
100
|
|
|
|
142
|
if($n =~ s/(\d)$//) { |
184
|
35
|
|
|
|
|
89
|
(my $t = $roman[$1]) =~ tr/IVX/XLC/; |
185
|
35
|
|
|
|
|
71
|
$r = $t . $r; |
186
|
|
|
|
|
|
|
} |
187
|
48
|
100
|
|
|
|
121
|
if($n =~ s/(\d)$//) { |
188
|
8
|
|
|
|
|
20
|
(my $t = $roman[$1]) =~ tr/IVX/CDM/; |
189
|
8
|
|
|
|
|
17
|
$r = $t . $r; |
190
|
|
|
|
|
|
|
} |
191
|
48
|
100
|
|
|
|
95
|
if($n =~ s/(\d)$//) { |
192
|
4
|
|
|
|
|
12
|
(my $t = $roman[$1]) =~ tr/IVX/M../; |
193
|
4
|
|
|
|
|
9
|
$r = $t . $r; |
194
|
|
|
|
|
|
|
} |
195
|
48
|
|
|
|
|
148
|
$r; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
149
|
|
|
149
|
|
616
|
sub format_a { $DoWs[$_[0]->[6]] } |
199
|
1
|
|
|
1
|
|
5
|
sub format_A { $DoW[$_[0]->[6]] } |
200
|
149
|
|
|
149
|
|
526
|
sub format_b { $MoYs[$_[0]->[4]] } |
201
|
1
|
|
|
1
|
|
5
|
sub format_B { $MoY[$_[0]->[4]] } |
202
|
1
|
|
|
1
|
|
5
|
sub format_h { $MoYs[$_[0]->[4]] } |
203
|
5
|
100
|
|
5
|
|
34
|
sub format_p { $_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0] } |
204
|
0
|
0
|
|
0
|
|
0
|
sub format_P { lc($_[0]->[2] >= 12 ? $AMPM[1] : $AMPM[0]) } |
205
|
|
|
|
|
|
|
|
206
|
20
|
|
|
20
|
|
92
|
sub format_d { sprintf("%02d",$_[0]->[3]) } |
207
|
163
|
|
|
163
|
|
898
|
sub format_e { sprintf("%2d",$_[0]->[3]) } |
208
|
179
|
|
|
179
|
|
581
|
sub format_H { sprintf("%02d",$_[0]->[2]) } |
209
|
12
|
|
50
|
12
|
|
78
|
sub format_I { sprintf("%02d",$_[0]->[2] % 12 || 12)} |
210
|
8
|
|
|
8
|
|
46
|
sub format_j { sprintf("%03d",$_[0]->[7] + 1) } |
211
|
8
|
|
|
8
|
|
42
|
sub format_k { sprintf("%2d",$_[0]->[2]) } |
212
|
8
|
|
50
|
8
|
|
52
|
sub format_l { sprintf("%2d",$_[0]->[2] % 12 || 12)} |
213
|
4
|
|
|
4
|
|
20
|
sub format_L { $_[0]->[4] + 1 } |
214
|
20
|
|
|
20
|
|
117
|
sub format_m { sprintf("%02d",$_[0]->[4] + 1) } |
215
|
183
|
|
|
183
|
|
496
|
sub format_M { sprintf("%02d",$_[0]->[1]) } |
216
|
8
|
|
|
8
|
|
56
|
sub format_q { sprintf("%01d",int($_[0]->[4] / 3) + 1) } |
217
|
|
|
|
|
|
|
sub format_s { |
218
|
6
|
100
|
|
6
|
|
18
|
$epoch = timelocal(@{$_[0]}[0..5]) |
|
1
|
|
|
|
|
4
|
|
219
|
|
|
|
|
|
|
unless defined $epoch; |
220
|
6
|
|
|
|
|
93
|
sprintf("%d",$epoch) |
221
|
|
|
|
|
|
|
} |
222
|
175
|
|
|
175
|
|
701
|
sub format_S { sprintf("%02d",$_[0]->[0]) } |
223
|
4
|
|
|
4
|
|
34
|
sub format_U { wkyr(0, $_[0]->[6], $_[0]->[7]) } |
224
|
4
|
|
|
4
|
|
26
|
sub format_w { $_[0]->[6] } |
225
|
4
|
|
|
4
|
|
14
|
sub format_W { wkyr(1, $_[0]->[6], $_[0]->[7]) } |
226
|
23
|
|
|
23
|
|
140
|
sub format_y { sprintf("%02d",$_[0]->[5] % 100) } |
227
|
166
|
|
|
166
|
|
822
|
sub format_Y { sprintf("%04d",$_[0]->[5] + 1900) } |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub format_Z { |
230
|
157
|
|
|
157
|
|
253
|
my $o = tz_local_offset(timelocal(@{$_[0]}[0..5])); |
|
157
|
|
|
|
|
467
|
|
231
|
157
|
50
|
|
|
|
697
|
defined $tzname ? $tzname : uc tz_name($o, $_[0]->[8]); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub format_z { |
235
|
7
|
|
|
7
|
|
14
|
my $t = timelocal(@{$_[0]}[0..5]); |
|
7
|
|
|
|
|
26
|
|
236
|
7
|
50
|
|
|
|
408
|
my $o = defined $tzname ? tz_offset($tzname, $t) : tz_offset(undef,$t); |
237
|
7
|
|
|
|
|
68
|
sprintf("%+03d%02d", int($o / 3600), int(abs($o) % 3600) / 60); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
4
|
|
|
4
|
|
12
|
sub format_c { &format_x . " " . &format_X } |
241
|
4
|
|
|
4
|
|
10
|
sub format_D { &format_m . "/" . &format_d . "/" . &format_y } |
242
|
4
|
|
|
4
|
|
16
|
sub format_r { &format_I . ":" . &format_M . ":" . &format_S . " " . &format_p } |
243
|
4
|
|
|
4
|
|
10
|
sub format_R { &format_H . ":" . &format_M } |
244
|
159
|
|
|
159
|
|
278
|
sub format_T { &format_H . ":" . &format_M . ":" . &format_S } |
245
|
0
|
|
|
0
|
|
0
|
sub format_t { "\t" } |
246
|
0
|
|
|
0
|
|
0
|
sub format_n { "\n" } |
247
|
2
|
|
|
2
|
|
20
|
sub format_o { sprintf("%2d%s",$_[0]->[3],$Dsuf[$_[0]->[3]]) } |
248
|
8
|
|
|
8
|
|
16
|
sub format_x { my $f = $format{'x'}; _subs($_[0],$f); } |
|
8
|
|
|
|
|
20
|
|
249
|
8
|
|
|
8
|
|
16
|
sub format_X { my $f = $format{'X'}; _subs($_[0],$f); } |
|
8
|
|
|
|
|
16
|
|
250
|
4
|
|
|
4
|
|
14
|
sub format_C { my $f = $format{'C'}; _subs($_[0],$f); } |
|
4
|
|
|
|
|
9
|
|
251
|
|
|
|
|
|
|
|
252
|
4
|
|
|
4
|
|
13
|
sub format_Od { roman(format_d(@_)) } |
253
|
4
|
|
|
4
|
|
17
|
sub format_Oe { roman(format_e(@_)) } |
254
|
4
|
|
|
4
|
|
14
|
sub format_OH { roman(format_H(@_)) } |
255
|
4
|
|
|
4
|
|
13
|
sub format_OI { roman(format_I(@_)) } |
256
|
4
|
|
|
4
|
|
13
|
sub format_Oj { roman(format_j(@_)) } |
257
|
4
|
|
|
4
|
|
18
|
sub format_Ok { roman(format_k(@_)) } |
258
|
4
|
|
|
4
|
|
13
|
sub format_Ol { roman(format_l(@_)) } |
259
|
4
|
|
|
4
|
|
12
|
sub format_Om { roman(format_m(@_)) } |
260
|
4
|
|
|
4
|
|
12
|
sub format_OM { roman(format_M(@_)) } |
261
|
4
|
|
|
4
|
|
17
|
sub format_Oq { roman(format_q(@_)) } |
262
|
4
|
|
|
4
|
|
18
|
sub format_Oy { roman(format_y(@_)) } |
263
|
4
|
|
|
4
|
|
15
|
sub format_OY { roman(format_Y(@_)) } |
264
|
|
|
|
|
|
|
|
265
|
3
|
|
|
3
|
|
21
|
sub format_G { int(($_[0]->[9] - 315993600) / 604800) } |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; |
268
|
|
|
|
|
|
|
__END__ |