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
|
|
71983
|
use strict; |
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
148
|
|
8
|
4
|
|
|
4
|
|
22
|
use vars qw(@EXPORT @ISA $VERSION); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
951
|
|
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
|
1004
|
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
|
|
29
|
use vars qw($epoch $tzname); |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
218
|
|
44
|
4
|
|
|
4
|
|
1462
|
use Time::Zone; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
318
|
|
45
|
4
|
|
|
4
|
|
1109
|
use Time::Local; |
|
4
|
|
|
|
|
4748
|
|
|
4
|
|
|
|
|
10626
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ctime |
48
|
|
|
|
|
|
|
{ |
49
|
4
|
|
|
4
|
|
48
|
my($me,$t,$tz) = @_; |
50
|
4
|
|
|
|
|
20
|
$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
|
|
502
|
my $fn; |
62
|
377
|
|
|
|
|
2492
|
$_[1] =~ s/ |
63
|
|
|
|
|
|
|
%(O?[%a-zA-Z]) |
64
|
|
|
|
|
|
|
/ |
65
|
1182
|
|
100
|
4
|
|
6563
|
($_[0]->can("format_$1") || sub { $1 })->($_[0]); |
|
4
|
|
|
|
|
18
|
|
66
|
|
|
|
|
|
|
/sgeox; |
67
|
|
|
|
|
|
|
|
68
|
377
|
|
|
|
|
1589
|
$_[1]; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub strftime |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
1
|
|
2
|
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
|
|
|
|
|
3
|
@$me = @$time; |
93
|
1
|
|
|
|
|
2
|
undef $epoch; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
3
|
_subs($me,$fmt); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub time2str |
100
|
|
|
|
|
|
|
{ |
101
|
356
|
|
|
356
|
|
111231
|
my($pkg,$fmt,$time); |
102
|
|
|
|
|
|
|
|
103
|
356
|
|
|
|
|
875
|
($pkg,$fmt,$time,$tzname) = @_; |
104
|
|
|
|
|
|
|
|
105
|
356
|
100
|
|
|
|
968
|
my $me = ref($pkg) ? $pkg : bless [], $pkg; |
106
|
|
|
|
|
|
|
|
107
|
356
|
|
|
|
|
543
|
$epoch = $time; |
108
|
|
|
|
|
|
|
|
109
|
356
|
100
|
|
|
|
639
|
if(defined $tzname) |
110
|
|
|
|
|
|
|
{ |
111
|
351
|
|
|
|
|
634
|
$tzname = uc $tzname; |
112
|
|
|
|
|
|
|
|
113
|
351
|
50
|
|
|
|
1360
|
$tzname = sprintf("%+05d",$tzname) |
114
|
|
|
|
|
|
|
unless($tzname =~ /\D/); |
115
|
|
|
|
|
|
|
|
116
|
351
|
|
|
|
|
884
|
$time += tz_offset($tzname); |
117
|
351
|
|
|
|
|
1580
|
@$me = gmtime($time); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else |
120
|
|
|
|
|
|
|
{ |
121
|
5
|
|
|
|
|
148
|
@$me = localtime($time); |
122
|
|
|
|
|
|
|
} |
123
|
356
|
|
|
|
|
930
|
$me->[9] = $time; |
124
|
356
|
|
|
|
|
818
|
_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
|
|
16
|
my($wstart, $wday, $yday) = @_; |
167
|
8
|
|
|
|
|
39
|
$wday = ($wday + 7 - $wstart) % 7; |
168
|
8
|
|
|
|
|
43
|
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
|
|
104
|
my $n = shift; |
179
|
|
|
|
|
|
|
|
180
|
48
|
|
|
|
|
159
|
$n =~ s/(\d)$//; |
181
|
48
|
|
|
|
|
120
|
my $r = $roman[ $1 ]; |
182
|
|
|
|
|
|
|
|
183
|
48
|
100
|
|
|
|
141
|
if($n =~ s/(\d)$//) { |
184
|
35
|
|
|
|
|
90
|
(my $t = $roman[$1]) =~ tr/IVX/XLC/; |
185
|
35
|
|
|
|
|
73
|
$r = $t . $r; |
186
|
|
|
|
|
|
|
} |
187
|
48
|
100
|
|
|
|
126
|
if($n =~ s/(\d)$//) { |
188
|
8
|
|
|
|
|
17
|
(my $t = $roman[$1]) =~ tr/IVX/CDM/; |
189
|
8
|
|
|
|
|
17
|
$r = $t . $r; |
190
|
|
|
|
|
|
|
} |
191
|
48
|
100
|
|
|
|
93
|
if($n =~ s/(\d)$//) { |
192
|
4
|
|
|
|
|
8
|
(my $t = $roman[$1]) =~ tr/IVX/M../; |
193
|
4
|
|
|
|
|
8
|
$r = $t . $r; |
194
|
|
|
|
|
|
|
} |
195
|
48
|
|
|
|
|
149
|
$r; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
149
|
|
|
149
|
|
676
|
sub format_a { $DoWs[$_[0]->[6]] } |
199
|
1
|
|
|
1
|
|
12
|
sub format_A { $DoW[$_[0]->[6]] } |
200
|
149
|
|
|
149
|
|
537
|
sub format_b { $MoYs[$_[0]->[4]] } |
201
|
1
|
|
|
1
|
|
6
|
sub format_B { $MoY[$_[0]->[4]] } |
202
|
1
|
|
|
1
|
|
5
|
sub format_h { $MoYs[$_[0]->[4]] } |
203
|
5
|
100
|
|
5
|
|
35
|
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
|
|
89
|
sub format_d { sprintf("%02d",$_[0]->[3]) } |
207
|
163
|
|
|
163
|
|
860
|
sub format_e { sprintf("%2d",$_[0]->[3]) } |
208
|
179
|
|
|
179
|
|
609
|
sub format_H { sprintf("%02d",$_[0]->[2]) } |
209
|
12
|
|
50
|
12
|
|
80
|
sub format_I { sprintf("%02d",$_[0]->[2] % 12 || 12)} |
210
|
8
|
|
|
8
|
|
92
|
sub format_j { sprintf("%03d",$_[0]->[7] + 1) } |
211
|
8
|
|
|
8
|
|
49
|
sub format_k { sprintf("%2d",$_[0]->[2]) } |
212
|
8
|
|
50
|
8
|
|
57
|
sub format_l { sprintf("%2d",$_[0]->[2] % 12 || 12)} |
213
|
4
|
|
|
4
|
|
17
|
sub format_L { $_[0]->[4] + 1 } |
214
|
20
|
|
|
20
|
|
118
|
sub format_m { sprintf("%02d",$_[0]->[4] + 1) } |
215
|
183
|
|
|
183
|
|
542
|
sub format_M { sprintf("%02d",$_[0]->[1]) } |
216
|
8
|
|
|
8
|
|
74
|
sub format_q { sprintf("%01d",int($_[0]->[4] / 3) + 1) } |
217
|
|
|
|
|
|
|
sub format_s { |
218
|
6
|
100
|
|
6
|
|
28
|
$epoch = timelocal(@{$_[0]}[0..5]) |
|
1
|
|
|
|
|
4
|
|
219
|
|
|
|
|
|
|
unless defined $epoch; |
220
|
6
|
|
|
|
|
94
|
sprintf("%d",$epoch) |
221
|
|
|
|
|
|
|
} |
222
|
175
|
|
|
175
|
|
707
|
sub format_S { sprintf("%02d",$_[0]->[0]) } |
223
|
4
|
|
|
4
|
|
36
|
sub format_U { wkyr(0, $_[0]->[6], $_[0]->[7]) } |
224
|
4
|
|
|
4
|
|
17
|
sub format_w { $_[0]->[6] } |
225
|
4
|
|
|
4
|
|
13
|
sub format_W { wkyr(1, $_[0]->[6], $_[0]->[7]) } |
226
|
23
|
|
|
23
|
|
128
|
sub format_y { sprintf("%02d",$_[0]->[5] % 100) } |
227
|
166
|
|
|
166
|
|
845
|
sub format_Y { sprintf("%04d",$_[0]->[5] + 1900) } |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub format_Z { |
230
|
157
|
|
|
157
|
|
299
|
my $o = tz_local_offset(timelocal(@{$_[0]}[0..5])); |
|
157
|
|
|
|
|
494
|
|
231
|
157
|
50
|
|
|
|
747
|
defined $tzname ? $tzname : uc tz_name($o, $_[0]->[8]); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub format_z { |
235
|
7
|
|
|
7
|
|
16
|
my $t = timelocal(@{$_[0]}[0..5]); |
|
7
|
|
|
|
|
26
|
|
236
|
7
|
50
|
|
|
|
429
|
my $o = defined $tzname ? tz_offset($tzname, $t) : tz_offset(undef,$t); |
237
|
7
|
|
|
|
|
67
|
sprintf("%+03d%02d", int($o / 3600), int(abs($o) % 3600) / 60); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
4
|
|
|
4
|
|
10
|
sub format_c { &format_x . " " . &format_X } |
241
|
4
|
|
|
4
|
|
11
|
sub format_D { &format_m . "/" . &format_d . "/" . &format_y } |
242
|
4
|
|
|
4
|
|
15
|
sub format_r { &format_I . ":" . &format_M . ":" . &format_S . " " . &format_p } |
243
|
4
|
|
|
4
|
|
12
|
sub format_R { &format_H . ":" . &format_M } |
244
|
159
|
|
|
159
|
|
252
|
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
|
|
19
|
sub format_x { my $f = $format{'x'}; _subs($_[0],$f); } |
|
8
|
|
|
|
|
17
|
|
249
|
8
|
|
|
8
|
|
17
|
sub format_X { my $f = $format{'X'}; _subs($_[0],$f); } |
|
8
|
|
|
|
|
50
|
|
250
|
4
|
|
|
4
|
|
11
|
sub format_C { my $f = $format{'C'}; _subs($_[0],$f); } |
|
4
|
|
|
|
|
9
|
|
251
|
|
|
|
|
|
|
|
252
|
4
|
|
|
4
|
|
10
|
sub format_Od { roman(format_d(@_)) } |
253
|
4
|
|
|
4
|
|
15
|
sub format_Oe { roman(format_e(@_)) } |
254
|
4
|
|
|
4
|
|
18
|
sub format_OH { roman(format_H(@_)) } |
255
|
4
|
|
|
4
|
|
15
|
sub format_OI { roman(format_I(@_)) } |
256
|
4
|
|
|
4
|
|
23
|
sub format_Oj { roman(format_j(@_)) } |
257
|
4
|
|
|
4
|
|
15
|
sub format_Ok { roman(format_k(@_)) } |
258
|
4
|
|
|
4
|
|
18
|
sub format_Ol { roman(format_l(@_)) } |
259
|
4
|
|
|
4
|
|
15
|
sub format_Om { roman(format_m(@_)) } |
260
|
4
|
|
|
4
|
|
13
|
sub format_OM { roman(format_M(@_)) } |
261
|
4
|
|
|
4
|
|
16
|
sub format_Oq { roman(format_q(@_)) } |
262
|
4
|
|
|
4
|
|
16
|
sub format_Oy { roman(format_y(@_)) } |
263
|
4
|
|
|
4
|
|
13
|
sub format_OY { roman(format_Y(@_)) } |
264
|
|
|
|
|
|
|
|
265
|
3
|
|
|
3
|
|
25
|
sub format_G { int(($_[0]->[9] - 315993600) / 604800) } |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; |
268
|
|
|
|
|
|
|
__END__ |