line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Utils; |
2
|
98
|
|
|
98
|
|
551
|
use strict; |
|
98
|
|
|
|
|
173
|
|
|
98
|
|
|
|
|
2224
|
|
3
|
98
|
|
|
98
|
|
433
|
use utf8; |
|
98
|
|
|
|
|
173
|
|
|
98
|
|
|
|
|
428
|
|
4
|
98
|
|
|
98
|
|
2053
|
use warnings FATAL => 'all'; |
|
98
|
|
|
|
|
170
|
|
|
98
|
|
|
|
|
2516
|
|
5
|
98
|
|
|
98
|
|
430
|
use parent 'Exporter'; |
|
98
|
|
|
|
|
171
|
|
|
98
|
|
|
|
|
382
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Date::Format; |
8
|
|
|
|
|
|
|
require URI::Escape::XS; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# @todo what with timezones? |
15
|
|
|
|
|
|
|
push @EXPORT_OK, 'time2str'; |
16
|
|
|
|
|
|
|
sub time2str |
17
|
|
|
|
|
|
|
{ |
18
|
8
|
|
|
8
|
0
|
16
|
my $format = shift; |
19
|
8
|
|
|
|
|
14
|
my $time = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# TIME_FORMAT, DATE_FORMAT, DATETIME_FORMAT, SHORT_DATE_FORMAT or SHORT_DATETIME_FORMAT |
22
|
|
|
|
|
|
|
|
23
|
8
|
|
|
|
|
29
|
return Date::Format::time2str($format, $time ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
push @EXPORT_OK, 'time2str_php'; |
27
|
|
|
|
|
|
|
# the code below has been taken from Dotiac::DTL and should be re-written on C |
28
|
|
|
|
|
|
|
# would be nice to implement module with this functionality (take from PHP source) |
29
|
|
|
|
|
|
|
#locale stuff |
30
|
|
|
|
|
|
|
our @datemonths = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); |
31
|
|
|
|
|
|
|
our @datemonthl = qw( January February March April May Juni Juli August September October November December ); |
32
|
|
|
|
|
|
|
our @datemontha = qw( Jan. Feb. March April May Juni Juli Aug. Sep. Oct. Nov. Dec. ); |
33
|
|
|
|
|
|
|
our @weekdays = qw/Sun Mon Tue Wed Thu Fri Sat/; |
34
|
|
|
|
|
|
|
our @weekdayl = qw/Sunday Monday Tuesday Wednesday Thursday Friday Saturday/; |
35
|
|
|
|
|
|
|
our @timeampm = qw/a.m. p.m. AM PM/; |
36
|
|
|
|
|
|
|
our @timespotnames = qw/midnight noon/; |
37
|
|
|
|
|
|
|
our @datesuffixes = qw/th st nd rd/; #qw/Default day1 day2 day3 day4 day5... |
38
|
|
|
|
|
|
|
sub time2str_php |
39
|
|
|
|
|
|
|
{ |
40
|
6
|
|
50
|
6
|
0
|
20
|
my $format = shift // ""; |
41
|
6
|
|
50
|
|
|
15
|
my $time = shift // 0; |
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
|
|
215
|
my @t = localtime($time); |
44
|
6
|
|
|
|
|
36
|
my @s = split //, $format; |
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
|
|
13
|
my $res; |
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
|
|
20
|
while(my $s = shift @s ) |
49
|
|
|
|
|
|
|
{ |
50
|
54
|
100
|
|
|
|
764
|
if ($s eq '\\') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
51
|
3
|
|
|
|
|
8
|
$res .= shift(@s); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ($s eq "a") { |
54
|
0
|
0
|
0
|
|
|
0
|
if ($t[2] > 12 or ($t[2] == 12 and $t[1] > 0)) { |
|
|
|
0
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
$res .= $timeampm[0]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
$res .= $timeampm[1]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ($s eq "A") { |
62
|
0
|
0
|
0
|
|
|
0
|
if ($t[2] > 12 or ($t[2] == 12 and $t[1] > 0)) { |
|
|
|
0
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
$res .= $timeampm[2]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
0
|
$res .= $timeampm[3]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
elsif ($s eq "b") { |
70
|
0
|
|
|
|
|
0
|
$res .= lc($datemonths[$t[4]]); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($s eq "d") { |
73
|
0
|
|
|
|
|
0
|
$res .= sprintf("%02d", $t[3]); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ($s eq "D") { |
76
|
0
|
|
|
|
|
0
|
$res .= $weekdays[$t[6]]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
elsif ($s eq "f") { |
79
|
0
|
|
|
|
|
0
|
my $h = $t[2]; |
80
|
0
|
|
|
|
|
0
|
$h = $h % 12; |
81
|
0
|
0
|
|
|
|
0
|
$h = 12 unless ($h); |
82
|
0
|
|
|
|
|
0
|
$res .= $h; |
83
|
0
|
0
|
|
|
|
0
|
$res .= sprintf(":%02d", $t[1]) if ($t[1]); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ($s eq "F") { |
86
|
0
|
|
|
|
|
0
|
$res .= $datemonthl[$t[4]]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif ($s eq "g") { |
89
|
0
|
|
|
|
|
0
|
my $h = $t[2]; |
90
|
0
|
|
|
|
|
0
|
$h = $h % 12; |
91
|
0
|
0
|
|
|
|
0
|
$h = 12 unless ($h); |
92
|
0
|
|
|
|
|
0
|
$res .= $h; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ($s eq "G") { |
95
|
0
|
|
|
|
|
0
|
$res .= $t[2]; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
elsif ($s eq "h") { |
98
|
0
|
|
|
|
|
0
|
my $h = $t[2]; |
99
|
0
|
|
|
|
|
0
|
$h = $h % 12; |
100
|
0
|
0
|
|
|
|
0
|
$h = 12 unless ($h); |
101
|
0
|
|
|
|
|
0
|
$res .= sprintf("%02d", $h); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
elsif ($s eq "H") { |
104
|
0
|
|
|
|
|
0
|
$res .= sprintf("%02d", $t[2]); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ($s eq "i") { |
107
|
0
|
|
|
|
|
0
|
$res .= sprintf("%02d", $t[1]); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ($s eq "j") { |
110
|
0
|
|
|
|
|
0
|
$res .= $t[3]; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif ($s eq "l") { |
113
|
0
|
|
|
|
|
0
|
$res .= $weekdayl[$t[6]]; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
elsif ($s eq "L") { |
116
|
0
|
|
|
|
|
0
|
my $d = $t[5] + 1900; |
117
|
0
|
0
|
0
|
|
|
0
|
$res .= (((not $d % 4 and $d % 100) or not $d % 400) ? "1" : "0"); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ($s eq "m") { |
120
|
0
|
|
|
|
|
0
|
$res .= sprintf("%02d", $t[4] + 1); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
elsif ($s eq "M") { |
123
|
0
|
|
|
|
|
0
|
$res .= $datemonths[$t[4]]; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
elsif ($s eq "n") { |
126
|
0
|
|
|
|
|
0
|
$res .= $t[4] + 1; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
elsif ($s eq "N") { |
129
|
0
|
|
|
|
|
0
|
$res .= $datemontha[$t[4]]; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
elsif ($s eq "O") { |
132
|
0
|
|
|
|
|
0
|
my @tt = localtime(0); |
133
|
0
|
0
|
|
|
|
0
|
$tt[2] += 1 if ($t[8]); |
134
|
0
|
|
|
|
|
0
|
$res .= sprintf("%+05d", $tt[2] * 100 + $tt[1]); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
elsif ($s eq "P") { |
137
|
0
|
0
|
0
|
|
|
0
|
if ($t[2] == 12 and $t[1] == 0) { |
|
|
0
|
0
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
$res .= $timespotnames[1]; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
elsif ($t[2] == 0 and $t[1] == 0) { |
141
|
0
|
|
|
|
|
0
|
$res .= $timespotnames[0]; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
else { |
144
|
0
|
|
|
|
|
0
|
my $h = $t[2]; |
145
|
0
|
|
|
|
|
0
|
$h = $h % 12; |
146
|
0
|
0
|
|
|
|
0
|
$h = 12 unless ($h); |
147
|
0
|
|
|
|
|
0
|
$res .= $h; |
148
|
0
|
0
|
|
|
|
0
|
$res .= sprintf(":%02d", $t[1]) if ($t[1]); |
149
|
0
|
0
|
0
|
|
|
0
|
if ($t[2] > 12 or ($t[2] == 12 and $t[1] > 0)) { |
|
|
|
0
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
$res .= " ".$timeampm[0]; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
else { |
153
|
0
|
|
|
|
|
0
|
$res .= " ".$timeampm[1]; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
elsif ($s eq "r") { |
159
|
0
|
|
|
|
|
0
|
$res .= $weekdays[$t[6]]; |
160
|
0
|
|
|
|
|
0
|
$res .= ", "; |
161
|
0
|
|
|
|
|
0
|
$res .= $t[4] + 1; |
162
|
0
|
|
|
|
|
0
|
$res .= " ".$datemonths[$t[4]]." ".($t[5] + 1900); |
163
|
0
|
|
|
|
|
0
|
$res .= sprintf(" %02d:%02d:%02d", $t[2], $t[1], $t[0]); |
164
|
0
|
|
|
|
|
0
|
my @tt = localtime(0); |
165
|
0
|
0
|
|
|
|
0
|
$tt[2] += 1 if ($t[8]); |
166
|
0
|
|
|
|
|
0
|
$res .= sprintf(" %+05d", $tt[2] * 100 + $tt[1]); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
elsif ($s eq "s") { |
169
|
0
|
|
|
|
|
0
|
$res .= sprintf("%02d", $t[0]); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
elsif ($s eq "S") { |
172
|
0
|
0
|
|
|
|
0
|
if ($datesuffixes[$t[3]]) { |
173
|
0
|
|
|
|
|
0
|
$res .= $datesuffixes[$t[3]]; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
else { |
176
|
0
|
|
|
|
|
0
|
$res .= $datesuffixes[0] |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
elsif ($s eq "t") { |
180
|
0
|
0
|
0
|
|
|
0
|
if ($t[4] == 1 or $t[4] == 3 or $t[4] == 5 or $t[4] == 7 or $t[4] == 8 or $t[4] == 10 or $t[4] == 12) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
181
|
0
|
|
|
|
|
0
|
$res .= "31"; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
elsif ($t[4] == 2) { |
184
|
0
|
|
|
|
|
0
|
my $d = $t[5] + 1900; |
185
|
0
|
0
|
0
|
|
|
0
|
if ((not $d % 4 and $d % 100) or not $d % 400) { |
|
|
|
0
|
|
|
|
|
186
|
0
|
|
|
|
|
0
|
$res .= "29"; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
else { |
189
|
0
|
|
|
|
|
0
|
$res .= "28"; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
else { |
193
|
0
|
|
|
|
|
0
|
$res .= "30"; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
elsif ($s eq "T") { |
197
|
0
|
|
|
|
|
0
|
require POSIX; |
198
|
0
|
|
|
|
|
0
|
$res .= POSIX::strftime("%Z", @t); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
elsif ($s eq "t") { |
201
|
0
|
|
|
|
|
0
|
$res .= $t[6]; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
elsif ($s eq "W") { |
204
|
0
|
|
|
|
|
0
|
require POSIX; |
205
|
0
|
|
|
|
|
0
|
$res .= POSIX::strftime("%W", @t); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
elsif ($s eq "y") { |
208
|
6
|
|
|
|
|
93
|
$res .= sprintf("%02d", ($t[5] % 100)); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
elsif ($s eq "Y") { |
211
|
6
|
|
|
|
|
22
|
$res .= sprintf("%04d", $t[5] + 1900); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
elsif ($s eq "z") { |
214
|
6
|
|
|
|
|
19
|
$res .= $t[7]; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
elsif ($s eq "Z") { |
217
|
6
|
|
|
|
|
129
|
my @tt = localtime(0); |
218
|
6
|
50
|
|
|
|
23
|
$tt[2] += 1 if ($t[8]); |
219
|
6
|
|
|
|
|
27
|
$res .= $tt[2] * 3600 + $t[1] * 60 + $t[0]; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
elsif ($s eq "\n") { |
222
|
0
|
|
|
|
|
0
|
$res .= "n"; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
elsif ($s eq "\t") { |
225
|
0
|
|
|
|
|
0
|
$res .= "t"; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
elsif ($s eq "\f") { |
228
|
0
|
|
|
|
|
0
|
$res .= "f"; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
elsif ($s eq "\b") { |
231
|
0
|
|
|
|
|
0
|
$res .= "b"; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
elsif ($s eq "\r") { |
234
|
0
|
|
|
|
|
0
|
$res .= "r"; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
else { |
237
|
27
|
|
|
|
|
63
|
$res .= $s; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} |
240
|
6
|
|
|
|
|
21
|
return $res; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
### end of Dotiac::DTL code |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
#Shortcuts below not working on mswin and perl =< 18.2 |
245
|
|
|
|
|
|
|
push @EXPORT_OK, 'uri_escape'; |
246
|
|
|
|
|
|
|
*DTL::Fast::Utils::uri_escape = \&URI::Escape::XS::uri_escape; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
push @EXPORT_OK, 'uri_unescape'; |
249
|
|
|
|
|
|
|
*DTL::Fast::Utils::uri_unescape = \&URI::Escape::XS::uri_unescape; |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
push @EXPORT_OK, 'escape'; |
252
|
|
|
|
|
|
|
*DTL::Fast::Utils::escape = \&URI::Escape::XS::encodeURIComponent; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
push @EXPORT_OK, 'unescape'; |
255
|
|
|
|
|
|
|
*DTL::Fast::Utils::unescape = \&URI::Escape::XS::decodeURIComponent; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
push @EXPORT_OK, 'as_bool'; |
258
|
|
|
|
|
|
|
sub as_bool |
259
|
|
|
|
|
|
|
{ |
260
|
5871
|
|
|
5871
|
0
|
9511
|
my $value = shift; |
261
|
5871
|
|
|
|
|
8385
|
my $value_type = ref $value; |
262
|
|
|
|
|
|
|
|
263
|
5871
|
100
|
|
|
|
11517
|
if ($value_type) |
264
|
|
|
|
|
|
|
{ |
265
|
984
|
100
|
|
|
|
2564
|
if ($value_type eq 'SCALAR') |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
266
|
|
|
|
|
|
|
{ |
267
|
328
|
|
|
|
|
585
|
$value = $$value; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
elsif ($value_type eq 'HASH') |
270
|
|
|
|
|
|
|
{ |
271
|
328
|
|
|
|
|
623
|
$value = scalar keys(%$value); |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
elsif ($value_type eq 'ARRAY') |
274
|
|
|
|
|
|
|
{ |
275
|
328
|
|
|
|
|
537
|
$value = scalar @$value; |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
elsif (UNIVERSAL::can( $value, 'as_bool' )) |
278
|
|
|
|
|
|
|
{ |
279
|
0
|
|
|
|
|
0
|
$value = $value->as_bool(); |
280
|
|
|
|
|
|
|
} |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
5871
|
|
|
|
|
18732
|
return $value; |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
1; |