line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Transform;
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Object Model
|
4
|
|
|
|
|
|
|
#
|
5
|
|
|
|
|
|
|
# transform
|
6
|
|
|
|
|
|
|
# + source
|
7
|
|
|
|
|
|
|
# + filter
|
8
|
|
|
|
|
|
|
# + destination
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# use lib 'C:/Documents and Settings/Christopher Brown/Desktop/CPAN';
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
22200
|
use 5.006;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
129
|
|
13
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
14
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
35
|
|
15
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
116
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use Data::Dumper;
|
18
|
|
|
|
|
|
|
# use Benchmark qw(:all);
|
19
|
1
|
|
|
1
|
|
1192
|
use Switch 'Perl5', 'Perl6';
|
|
1
|
|
|
|
|
120816
|
|
|
1
|
|
|
|
|
8
|
|
20
|
1
|
|
|
1
|
|
283503
|
use Tie::IxHash;
|
|
1
|
|
|
|
|
5772
|
|
|
1
|
|
|
|
|
39
|
|
21
|
1
|
|
|
1
|
|
932
|
use POSIX qw(strftime);
|
|
1
|
|
|
|
|
7263
|
|
|
1
|
|
|
|
|
8
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
2059
|
use Date::Transform::Closures; # Functions that create the closures.
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
88
|
|
24
|
1
|
|
|
1
|
|
591
|
use Date::Transform::Functions; # Functions used in the closures
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
92
|
|
25
|
1
|
|
|
1
|
|
569
|
use Date::Transform::Extensions; # Contains Extensions to Other Modules
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
288
|
|
26
|
1
|
|
|
1
|
|
621
|
use Date::Transform::Constants; # Contains Constant Definitions
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
64
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
require Exporter;
|
29
|
1
|
|
|
1
|
|
5
|
use AutoLoader qw(AUTOLOAD);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
30
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export
|
33
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead.
|
34
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants.
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# This allows declaration use Date::Manip::Transform ':all';
|
37
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
38
|
|
|
|
|
|
|
# will save memory.
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [qw()] );
|
41
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
42
|
|
|
|
|
|
|
our @EXPORT = qw( @CONSTANTS );
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
our $VERSION = '0.11';
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Preloaded methods go here.
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new {
|
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
1
|
942
|
my $type = shift;
|
51
|
1
|
|
33
|
|
|
10
|
my $class = ref($type) || $type;
|
52
|
1
|
|
|
|
|
2
|
my $self;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Arguments
|
55
|
|
|
|
|
|
|
|
56
|
1
|
50
|
|
|
|
5
|
if ( scalar(@_) < 2 ) { # Make sure that both arguments are given.
|
57
|
0
|
|
|
|
|
0
|
carp("Both an input and an output arguments must be supplied.\n");
|
58
|
0
|
|
|
|
|
0
|
die;
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
5
|
$self->{source}->{format} = shift;
|
62
|
1
|
|
|
|
|
4
|
$self->{destination}->{format} = shift;
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Bless and return the object.
|
65
|
1
|
|
|
|
|
3
|
bless $self, $class;
|
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
5
|
$self->_initialize();
|
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
5
|
return $self;
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
## SUBROUTINE: _initialize
|
74
|
|
|
|
|
|
|
## Creates Transformation Function
|
75
|
|
|
|
|
|
|
sub _initialize {
|
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
1
|
|
1
|
my $self = shift;
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Expand Input & Output Formats
|
80
|
|
|
|
|
|
|
# From here on out we should deal exclusively with expanded formats.
|
81
|
1
|
|
|
|
|
12
|
$self->{source}->{expanded_format} =
|
82
|
|
|
|
|
|
|
_expand_compound_formats( $self->{source}->{format} );
|
83
|
1
|
|
|
|
|
9
|
$self->{destination}->{expanded_format} =
|
84
|
|
|
|
|
|
|
_expand_compound_formats( $self->{destination}->{format} );
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
## We can check the expanded output format for validity by making sure that none of the %_ are
|
87
|
|
|
|
|
|
|
## other than those acceptable to strftime function. We can raise an error if they are detected.
|
88
|
|
|
|
|
|
|
##
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
## CREATE PLACE for POSIX ARRAY OF DATE
|
91
|
|
|
|
|
|
|
## sec, min, hour, mday, mon, year, wday
|
92
|
|
|
|
|
|
|
## {filter} will be the array passed to Posix::strftime
|
93
|
1
|
|
|
|
|
12
|
my $ixhash_obj = Tie::IxHash->new();
|
94
|
1
|
|
|
|
|
20
|
$ixhash_obj->STORE( 'format', $self->{destination}->{expanded_format} );
|
95
|
1
|
|
|
|
|
23
|
$self->{filter}->{input} = $ixhash_obj;
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Generate records of the formats and orders.
|
98
|
|
|
|
|
|
|
# Retrieve input formats and order of formats.
|
99
|
1
|
|
|
|
|
5
|
$self->{source}->{formats} =
|
100
|
|
|
|
|
|
|
_parse_format_string( $self->{source}->{expanded_format} );
|
101
|
1
|
|
|
|
|
4
|
$self->{destination}->{formats} =
|
102
|
|
|
|
|
|
|
_parse_format_string( $self->{destination}->{expanded_format} );
|
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
5
|
$self->_crosscheck
|
105
|
|
|
|
|
|
|
; # Does the input data supply everything for necessary for the output.
|
106
|
1
|
|
|
|
|
5
|
$self->_regexp; # Create regexp for matching.
|
107
|
1
|
|
|
|
|
4
|
$self->_transform_functions; # Create functions for mapping.
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} # END SUBROUTINE: _initialize
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
## SUBROUTINE: transform
|
112
|
|
|
|
|
|
|
## Transforms the supplied date.
|
113
|
|
|
|
|
|
|
sub transform {
|
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
1
|
1
|
733
|
my $self = shift;
|
116
|
1
|
|
|
|
|
3
|
my $input = shift;
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
## Set Defaults.
|
119
|
|
|
|
|
|
|
## my @array = $self->{filter}->{input}->Values;
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
## $matches will hold the values from the matched regular expression.
|
122
|
1
|
|
|
|
|
5
|
my $matches = Tie::IxHash->new();
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
## SHOULD WE DO A CASE INSENSITIVE MATCH -- Default: Yes.
|
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
237
|
if ( $input =~ /$self->{filter}->{regexp}/i ) {
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
## TEMPORARILY DISABLE strict 'refs' SO THAT WE CAN USE $$n.
|
129
|
1
|
|
|
1
|
|
467
|
no strict 'refs';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
## Create Values from RegularExpression to Store in Cache.
|
132
|
|
|
|
|
|
|
## Foreach of the input formats,
|
133
|
|
|
|
|
|
|
## name => value from regexp
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
## THIS IS THE SECOND MOST LIMITING STEP @ 1100/sec
|
136
|
1
|
|
|
|
|
7
|
foreach ( $self->{source}->{formats}->Keys ) {
|
137
|
7
|
|
|
|
|
28
|
$matches->Push( $_,
|
138
|
7
|
|
|
|
|
125
|
${ $self->{source}->{formats}->IndexFromKey($_) + 1 } );
|
139
|
|
|
|
|
|
|
}
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
## REENABLE strict
|
142
|
1
|
|
|
1
|
|
5
|
use strict 'refs';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4293
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
## SET matches to object.
|
145
|
1
|
|
|
|
|
24
|
$self->{filter}->{matches} = $matches;
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
## PERFORM EACH OF THE TRANSFORMATIONS
|
148
|
|
|
|
|
|
|
## THIS IS THE TIME LIMITING STEP @ 900/sec
|
149
|
1
|
|
|
|
|
2
|
foreach my $transformation ( @{ $self->{filter}->{transformations} } ) {
|
|
1
|
|
|
|
|
3
|
|
150
|
6
|
|
|
|
|
77
|
$self->$transformation;
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
else {
|
155
|
0
|
|
|
|
|
0
|
carp(
|
156
|
|
|
|
|
|
|
"No date matched input string, \"$input\".\nUsing Regular Expression: ",
|
157
|
|
|
|
|
|
|
$self->{filter}->{regexp}, ".\n"
|
158
|
|
|
|
|
|
|
);
|
159
|
|
|
|
|
|
|
}
|
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
25
|
return POSIX::strftime( $self->{filter}->{input}->Values );
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} # END SUBROUTINE: transform
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
## SUBROUTINE: _transform_functions
|
166
|
|
|
|
|
|
|
## Creates and stores the closures to be used in the transformation
|
167
|
|
|
|
|
|
|
sub _transform_functions {
|
168
|
|
|
|
|
|
|
|
169
|
1
|
|
|
1
|
|
3
|
my $self = shift;
|
170
|
|
|
|
|
|
|
|
171
|
1
|
|
|
|
|
2
|
my $required = $self->{filter}->{requirements};
|
172
|
1
|
|
|
|
|
3
|
my $supplied = $self->{source}->{formats};
|
173
|
1
|
|
|
|
|
3
|
my $filter = $self->{filter}->{input};
|
174
|
1
|
|
|
|
|
2
|
my $transformations = $self->{filter}->{transformations};
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
## 1. SECONDS
|
177
|
1
|
50
|
|
|
|
5
|
if ( exists $required->{'S'} ) {
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Generate second code.
|
180
|
|
|
|
|
|
|
|
181
|
1
|
50
|
|
|
|
6
|
if ( $supplied->EXISTS('S') ) {
|
182
|
|
|
|
|
|
|
|
183
|
1
|
|
|
|
|
10
|
my $f1 = mk_passthru('S');
|
184
|
1
|
|
|
|
|
6
|
my $function = mk_set_filter_input( 'S', $f1 );
|
185
|
|
|
|
|
|
|
|
186
|
1
|
|
|
|
|
2
|
push ( @{ $self->{filter}->{transformations} }, $function );
|
|
1
|
|
|
|
|
4
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
}
|
189
|
|
|
|
|
|
|
else {
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# SET DEFAULTS
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
}
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
}
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
## 2. MINUTES
|
198
|
1
|
50
|
|
|
|
5
|
if ( $required->{'M'} ) {
|
199
|
|
|
|
|
|
|
|
200
|
1
|
50
|
|
|
|
4
|
if ( $supplied->EXISTS('M') ) {
|
201
|
|
|
|
|
|
|
|
202
|
1
|
|
|
|
|
8
|
my $f1 = mk_passthru('M');
|
203
|
1
|
|
|
|
|
4
|
my $function = mk_set_filter_input( 'M', $f1 );
|
204
|
|
|
|
|
|
|
|
205
|
1
|
|
|
|
|
2
|
push ( @{ $self->{filter}->{transformations} }, $function );
|
|
1
|
|
|
|
|
3
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
}
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
}
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
## 3. HOURS
|
212
|
1
|
50
|
|
|
|
5
|
if ( exists $required->{'H'} ) {
|
213
|
|
|
|
|
|
|
|
214
|
1
|
|
|
|
|
2
|
my $function;
|
215
|
|
|
|
|
|
|
|
216
|
1
|
50
|
33
|
|
|
4
|
if ( $supplied->EXISTS('H') ) {
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
0
|
my $f1 = mk_passthru('H');
|
219
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'H', $f1 );
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
}
|
222
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('k') ) {
|
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
0
|
my $f1 = mk_passthru('k');
|
225
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'H', $f1 );
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
}
|
228
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('i') and $supplied->EXISTS('p') ) {
|
229
|
|
|
|
|
|
|
|
230
|
1
|
|
|
|
|
36
|
my $f = \&iI_p_to_strftime_H;
|
231
|
1
|
|
|
|
|
5
|
my $f1 = mk_function( $f, 'i', 'p' );
|
232
|
1
|
|
|
|
|
3
|
$function = mk_set_filter_input( 'H', $f1 );
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
#= '$self->{filter}->{input}->[3] = $' . $supplied->IndexFromKey('H');
|
235
|
|
|
|
|
|
|
#$function = '$self->{filter}->{input}->[3] = $' . $supplied->IndexFromKey('H') . ' + 12' if ($ 0);
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
}
|
238
|
|
|
|
|
|
|
|
239
|
1
|
|
|
|
|
2
|
push ( @{ $self->{filter}->{transformations} }, $function );
|
|
1
|
|
|
|
|
3
|
|
240
|
|
|
|
|
|
|
}
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
## 4. MONTHDAY
|
243
|
1
|
50
|
|
|
|
5
|
if ( exists $required->{'d'} ) {
|
244
|
|
|
|
|
|
|
|
245
|
1
|
|
|
|
|
1
|
my $function;
|
246
|
|
|
|
|
|
|
|
247
|
1
|
50
|
|
|
|
4
|
if ( $supplied->EXISTS('d') ) {
|
|
|
50
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
0
|
my $f1 = mk_passthru('d');
|
250
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'd', $f1 );
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
}
|
253
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('e') ) {
|
254
|
|
|
|
|
|
|
|
255
|
1
|
|
|
|
|
24
|
my $f1 = mk_passthru('e');
|
256
|
1
|
|
|
|
|
4
|
$function = mk_set_filter_input( 'd', $f1 );
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
}
|
259
|
|
|
|
|
|
|
|
260
|
1
|
|
|
|
|
2
|
push ( @{ $self->{filter}->{transformations} }, $function );
|
|
1
|
|
|
|
|
4
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
}
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
## 5. MONTH
|
265
|
1
|
50
|
|
|
|
14
|
if ( exists $required->{'m'} ) {
|
266
|
|
|
|
|
|
|
|
267
|
1
|
|
|
|
|
2
|
my $function;
|
268
|
|
|
|
|
|
|
|
269
|
1
|
50
|
|
|
|
5
|
if ( $supplied->EXISTS('m') ) {
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
0
|
|
|
|
|
0
|
my $f = \&m_to_strftime_m;
|
272
|
0
|
|
|
|
|
0
|
my $f1 = mk_function( $f, 'm' );
|
273
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'm', $f1 );
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
}
|
276
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('f') ) {
|
277
|
|
|
|
|
|
|
|
278
|
0
|
|
|
|
|
0
|
my $f = \&m_to_strftime_m;
|
279
|
0
|
|
|
|
|
0
|
my $f1 = mk_function( $f, 'f' );
|
280
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'm', $f1 );
|
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
}
|
283
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('b') ) {
|
284
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
0
|
my $f = \&bh_to_strftime_m;
|
286
|
0
|
|
|
|
|
0
|
my $f1 = mk_function( $f, 'b' );
|
287
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'm', $f1 );
|
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
}
|
290
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('h') ) {
|
291
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
0
|
my $f = \&bh_to_strftime_m;
|
293
|
0
|
|
|
|
|
0
|
my $f1 = mk_function( $f, 'h' );
|
294
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'm', $f1 );
|
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
}
|
297
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('B') ) {
|
298
|
|
|
|
|
|
|
|
299
|
1
|
|
|
|
|
41
|
my $f = \&B_to_strftime_m;
|
300
|
1
|
|
|
|
|
4
|
my $f1 = mk_function( $f, 'B' );
|
301
|
1
|
|
|
|
|
3
|
$function = mk_set_filter_input( 'm', $f1 );
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
}
|
304
|
|
|
|
|
|
|
|
305
|
1
|
|
|
|
|
3
|
push ( @{ $self->{filter}->{transformations} }, $function );
|
|
1
|
|
|
|
|
4
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
}
|
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
## 6. YEAR
|
310
|
1
|
50
|
|
|
|
4
|
if ( exists $required->{'Y'} ) {
|
311
|
|
|
|
|
|
|
|
312
|
1
|
|
|
|
|
1
|
my $function;
|
313
|
|
|
|
|
|
|
|
314
|
1
|
50
|
|
|
|
5
|
if ( $supplied->EXISTS('y') ) {
|
|
|
0
|
|
|
|
|
|
315
|
|
|
|
|
|
|
|
316
|
1
|
|
|
|
|
7
|
my $f1 = mk_passthru('y');
|
317
|
1
|
|
|
|
|
4
|
$function = mk_set_filter_input( 'y', $f1 );
|
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
}
|
320
|
|
|
|
|
|
|
elsif ( $supplied->EXISTS('Y') ) {
|
321
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
0
|
my $f = \&Y_to_strftime_y;
|
323
|
0
|
|
|
|
|
0
|
my $f1 = mk_function( $f, 'Y' );
|
324
|
0
|
|
|
|
|
0
|
$function = mk_set_filter_input( 'y', $f1 );
|
325
|
|
|
|
|
|
|
}
|
326
|
|
|
|
|
|
|
|
327
|
1
|
|
|
|
|
3
|
push ( @{ $self->{filter}->{transformations} }, $function );
|
|
1
|
|
|
|
|
8
|
|
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
}
|
330
|
|
|
|
|
|
|
|
331
|
1
|
|
|
|
|
3
|
return 1;
|
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
}
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
## SUBROUTINE: _regexp
|
336
|
|
|
|
|
|
|
## Creates the regexp used in the transformation
|
337
|
|
|
|
|
|
|
sub _regexp {
|
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
## Converts input format into regular expression format.
|
340
|
1
|
|
|
1
|
|
2
|
my $self = shift;
|
341
|
|
|
|
|
|
|
|
342
|
1
|
|
|
|
|
3
|
my $regexp = $self->{source}->{expanded_format};
|
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
# Replace Special Characters
|
345
|
1
|
|
|
|
|
5
|
$regexp =~ s/\%n/\\n/g;
|
346
|
1
|
|
|
|
|
3
|
$regexp =~ s/\%t/\\t/g;
|
347
|
1
|
|
|
|
|
3
|
$regexp =~ s/\%\%/\\%/g;
|
348
|
1
|
|
|
|
|
2
|
$regexp =~ s/\%\+/\\+/g;
|
349
|
|
|
|
|
|
|
|
350
|
1
|
|
|
|
|
7
|
foreach ( $self->{source}->{formats}->Keys ) {
|
351
|
7
|
|
|
|
|
35
|
my $re_replacement = "(" . &_re($_) . ")";
|
352
|
7
|
|
|
|
|
116
|
$regexp =~ s/\%($_)/$re_replacement/eg;
|
|
7
|
|
|
|
|
29
|
|
353
|
|
|
|
|
|
|
}
|
354
|
|
|
|
|
|
|
|
355
|
1
|
|
|
|
|
5
|
$self->{filter}->{regexp} = $regexp;
|
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# return $regexp;
|
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
} # END SUBROUTINE: _regexp
|
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
## SUBROUTINE: _crosscheck
|
362
|
|
|
|
|
|
|
## ensures that the input string supplies all the necessary information
|
363
|
|
|
|
|
|
|
## for the requested output. Requires some complex logic (not implemented yet.)
|
364
|
|
|
|
|
|
|
sub _crosscheck {
|
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
# Checks to see if the necessary data elements the input_format supplies enough data.
|
367
|
|
|
|
|
|
|
|
368
|
1
|
|
|
1
|
|
2
|
my $self = shift;
|
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
# my %strftime_requirements;
|
371
|
|
|
|
|
|
|
# my @req;
|
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
# What are the output requirements.
|
374
|
1
|
|
|
|
|
6
|
my %or = _strftime_requirements( $self->{destination}->{formats}->Keys );
|
375
|
1
|
|
|
|
|
7
|
$self->{filter}->{requirements} = \%or;
|
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
# What are the input supplied.
|
378
|
1
|
|
|
|
|
8
|
my %is = _strftime_requirements( $self->{source}->{formats}->Keys );
|
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# $self->{source}->{supplied} = \%is;
|
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
# Crosscheck outputs requested vs inputs supplied.
|
383
|
|
|
|
|
|
|
#my %is = map { $_ => 1 } @is;
|
384
|
|
|
|
|
|
|
|
385
|
1
|
|
|
|
|
8
|
foreach my $or ( sort keys %or ) {
|
386
|
|
|
|
|
|
|
|
387
|
6
|
50
|
|
|
|
18
|
if ( !$is{$or} ) {
|
388
|
0
|
|
|
|
|
0
|
carp
|
389
|
|
|
|
|
|
|
"WARNING: %$or is required by the output, but not supplied by the input.\n";
|
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
# die("\n") unless ( $is{$or} );
|
392
|
|
|
|
|
|
|
}
|
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
}
|
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
}
|
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
## SUBROUTINE: _parse_format_string
|
399
|
|
|
|
|
|
|
## Given a date string => href of elements in the string, aref of order of elements
|
400
|
|
|
|
|
|
|
## Because we reverse the format string ... walking it backwards ... if an element
|
401
|
|
|
|
|
|
|
## appears more than once, the REAL first occurence will be captured.
|
402
|
|
|
|
|
|
|
sub _parse_format_string {
|
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
# Format String => href Elements in Sting, aref order of elements
|
405
|
|
|
|
|
|
|
|
406
|
2
|
|
|
2
|
|
4
|
my $format = shift;
|
407
|
2
|
|
|
|
|
3
|
my $index = 0;
|
408
|
|
|
|
|
|
|
|
409
|
2
|
|
|
|
|
6
|
my $ixhash_obj = Tie::IxHash->new();
|
410
|
|
|
|
|
|
|
|
411
|
2
|
|
|
|
|
22
|
$format = reverse($format); # REVERSE THE ORDER OF FORMAT.
|
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
# my $elements;
|
414
|
|
|
|
|
|
|
# my $order;
|
415
|
|
|
|
|
|
|
|
416
|
2
|
|
|
|
|
3
|
my ( $r1, $r2 );
|
417
|
|
|
|
|
|
|
|
418
|
2
|
|
|
|
|
4
|
$r1 = chop($format);
|
419
|
|
|
|
|
|
|
|
420
|
2
|
|
|
|
|
5
|
while ($format) {
|
421
|
|
|
|
|
|
|
|
422
|
76
|
|
|
|
|
78
|
$r2 = $r1;
|
423
|
76
|
|
|
|
|
83
|
$r1 = chop($format);
|
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
# Test for format field.
|
426
|
76
|
100
|
|
|
|
177
|
if ( $r2 eq '%' ) {
|
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
# $elements->{$r1} = undef; # These will become storage recepticles later.
|
429
|
|
|
|
|
|
|
# push @{$order}, $r1;
|
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
# Since date information might appear twice in the string, we only want to take the first instance.
|
432
|
|
|
|
|
|
|
# next if ( $ixhash_obj->[0]->{$r1} );
|
433
|
|
|
|
|
|
|
# Make sure to put the new formats at the front of object.
|
434
|
39
|
|
|
|
|
95
|
$ixhash_obj->Push( $r1 => $index );
|
435
|
39
|
|
|
|
|
568
|
$r1 = chop($format);
|
436
|
|
|
|
|
|
|
|
437
|
39
|
|
|
|
|
83
|
$index++;
|
438
|
|
|
|
|
|
|
}
|
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
}
|
441
|
|
|
|
|
|
|
|
442
|
2
|
|
|
|
|
7
|
return $ixhash_obj;
|
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
}
|
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
########################
|
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
## SUBROUTINE: _expand_compound_formats
|
449
|
|
|
|
|
|
|
## Expands compound formats to full formats.
|
450
|
|
|
|
|
|
|
sub _expand_compound_formats {
|
451
|
|
|
|
|
|
|
|
452
|
2
|
|
|
2
|
|
5
|
my $format = shift;
|
453
|
2
|
|
|
|
|
3
|
my ( $expansion, $new_format );
|
454
|
|
|
|
|
|
|
|
455
|
2
|
|
|
|
|
6
|
$format = reverse $format;
|
456
|
|
|
|
|
|
|
|
457
|
2
|
|
|
|
|
3
|
my ( $r1, $r2 );
|
458
|
2
|
|
|
|
|
6
|
$r1 = chop $format;
|
459
|
|
|
|
|
|
|
|
460
|
2
|
|
|
|
|
5
|
while ($format) {
|
461
|
|
|
|
|
|
|
|
462
|
54
|
|
|
|
|
62
|
$r2 = $r1;
|
463
|
54
|
|
|
|
|
62
|
$r1 = chop($format);
|
464
|
|
|
|
|
|
|
|
465
|
54
|
|
|
|
|
54
|
my $expansion;
|
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
# Test for format field.
|
468
|
54
|
100
|
|
|
|
93
|
if ( $r2 eq '%' ) {
|
469
|
|
|
|
|
|
|
|
470
|
28
|
|
|
|
|
34
|
given($r1) {
|
|
28
|
|
|
|
|
34
|
|
|
28
|
|
|
|
|
68
|
|
|
25
|
|
|
|
|
32
|
|
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
# COMPUND FORMATS
|
473
|
|
|
|
|
|
|
|
474
|
28
|
100
|
|
|
|
386
|
when [ "T", "X" ] { $expansion = "%H:%M:%S"; }
|
|
1
|
|
|
|
|
44
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
475
|
27
|
100
|
|
|
|
925
|
when "c" { $expansion = "%a %b %e %H:%M:%S %z %Y"; }
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
476
|
26
|
50
|
|
|
|
346
|
when [ "C", "u" ] { $expansion = "%a %b %e %H:%M:%S %z %Y"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
477
|
26
|
50
|
|
|
|
846
|
when "g" { $expansion = "%a, %d %b %Y %H:%M:%S %z"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
478
|
26
|
100
|
|
|
|
320
|
when [ "D", "x" ] { $expansion = "%m/%d/%y"; }
|
|
1
|
|
|
|
|
31
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
479
|
|
|
|
|
|
|
|
480
|
25
|
50
|
|
|
|
825
|
when "r" { $expansion = "%I:%M:%S %p"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
481
|
25
|
50
|
|
|
|
294
|
when "R" { $expansion = "%H:%M"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
482
|
25
|
50
|
|
|
|
284
|
when "V" { $expansion = "%m%d%H%M%y"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
483
|
25
|
50
|
|
|
|
277
|
when "Q" { $expansion = "%Y%m%d"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
484
|
25
|
50
|
|
|
|
271
|
when "q" { $expansion = "%Y%m%d%H%M%S"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
485
|
25
|
50
|
|
|
|
348
|
when "P" { $expansion = "%Y%m%d%H:%M:%S"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
486
|
25
|
50
|
|
|
|
277
|
when "F" { $expansion = "%A, %B %e, %Y"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
487
|
25
|
50
|
|
|
|
267
|
when "J" { $expansion = "%G-%W-%w"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
488
|
25
|
50
|
|
|
|
262
|
when "K" { $expansion = "%Y-%j"; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
# when "" { $re = '' } # MORE.
|
491
|
|
|
|
|
|
|
# when "l" { $re = "[" . join( ' ', _re(b,e,R) ) . '|' . join( ' ', _re(b,e,Y) ) . "]" }
|
492
|
|
|
|
|
|
|
# Omitted for now, but logic can be included to solve the problem.
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
# Don't expand non compound factors
|
495
|
25
|
|
|
|
|
334
|
else { $expansion .= $r2 . $r1; }
|
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
} # End SWITCH
|
498
|
|
|
|
|
|
|
|
499
|
28
|
|
|
|
|
56
|
$r1 = chop($format);
|
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
}
|
502
|
|
|
|
|
|
|
else {
|
503
|
|
|
|
|
|
|
|
504
|
26
|
|
|
|
|
34
|
$expansion = $r2;
|
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
} # END if
|
507
|
|
|
|
|
|
|
|
508
|
54
|
|
|
|
|
124
|
$new_format .= $expansion;
|
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
} # END format WHILE
|
511
|
|
|
|
|
|
|
|
512
|
2
|
|
|
|
|
8
|
return $new_format;
|
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
}
|
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
## SUBROUTINE: _strftime_requirements
|
517
|
|
|
|
|
|
|
## Given a series of formats that are requested,
|
518
|
|
|
|
|
|
|
## This function determines what is required by
|
519
|
|
|
|
|
|
|
## strftime to suppy those requirements.
|
520
|
|
|
|
|
|
|
sub _strftime_requirements {
|
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
# OUTPUT REQUIREMENTS
|
523
|
|
|
|
|
|
|
# my $format;
|
524
|
2
|
|
|
2
|
|
44
|
my @formats = @_;
|
525
|
2
|
|
|
|
|
4
|
my @req;
|
526
|
|
|
|
|
|
|
|
527
|
2
|
|
|
|
|
4
|
foreach my $format (@formats) {
|
528
|
|
|
|
|
|
|
|
529
|
27
|
|
|
|
|
35
|
given($format) {
|
|
27
|
|
|
|
|
33
|
|
|
27
|
|
|
|
|
64
|
|
|
3
|
|
|
|
|
93
|
|
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
# Year
|
532
|
27
|
100
|
|
|
|
357
|
when [ "Y", "y", "G", "L" ] { push ( @req, 'Y' ); }
|
|
3
|
|
|
|
|
84
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
17
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
# Month
|
535
|
24
|
100
|
|
|
|
1097
|
when [ "m", "f", "b", "h", "B" ] { push ( @req, 'm' ); }
|
|
4
|
|
|
|
|
146
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
26
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
# Week/Day of the year, Day of the week
|
538
|
20
|
100
|
|
|
|
1142
|
when [ "U", "W", "j", "v", "a", "A", "w" ] {
|
|
6
|
|
|
|
|
242
|
|
539
|
6
|
|
|
|
|
14
|
push ( @req, 'Y', 'm', 'd' );
|
540
|
6
|
|
|
|
|
38
|
}
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
# Day of the Month
|
543
|
14
|
100
|
|
|
|
796
|
when [ "d", "e", "E" ] { push ( @req, 'd' ); }
|
|
3
|
|
|
|
|
85
|
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
# Hour
|
546
|
11
|
100
|
|
|
|
414
|
when [ "H", "k", "i", "l", "p" ] { push ( @req, 'H' ); }
|
|
4
|
|
|
|
|
142
|
|
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
25
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
# Minute
|
549
|
7
|
100
|
|
|
|
326
|
when ["M"] { push ( @req, 'M' ); }
|
|
2
|
|
|
|
|
52
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
11
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
# Second
|
552
|
5
|
100
|
|
|
|
142
|
when ["S"] { push ( @req, 'S' ); }
|
|
2
|
|
|
|
|
45
|
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
} # END SWITCH BLOCK
|
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
} # END @formats LOOP
|
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
# Remove duplicates from requirements
|
559
|
2
|
|
|
|
|
4
|
my %req = map { $_ => 1 } @req;
|
|
36
|
|
|
|
|
67
|
|
560
|
|
|
|
|
|
|
|
561
|
2
|
|
|
|
|
21
|
return %req; # return (keys(%req));
|
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
}
|
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
sub _re {
|
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# Generate regular expression for the given format(s)
|
568
|
|
|
|
|
|
|
# In general the regular expressions should be
|
569
|
|
|
|
|
|
|
# restrictive and fast.
|
570
|
|
|
|
|
|
|
#
|
571
|
|
|
|
|
|
|
|
572
|
7
|
|
|
7
|
|
10
|
my $format = shift;
|
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
# my $regexp;
|
575
|
|
|
|
|
|
|
|
576
|
7
|
|
|
|
|
9
|
my $re;
|
577
|
|
|
|
|
|
|
|
578
|
7
|
|
|
|
|
16
|
given($format) {
|
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
16
|
|
|
0
|
|
|
|
|
0
|
|
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
# YEAR
|
581
|
7
|
100
|
|
|
|
84
|
when "y" { $re = '\d{2}'; }
|
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
582
|
6
|
50
|
|
|
|
81
|
when [ "Y", "G", "L" ] { $re = '\d{4}'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
#Month
|
585
|
6
|
50
|
|
|
|
250
|
when "m" { $re = '[01]\d'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
586
|
6
|
50
|
|
|
|
72
|
when "f" { $re = '\d{1}|1[0-2]'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
587
|
6
|
50
|
|
|
|
72
|
when [ "b", "h" ] {
|
|
0
|
|
|
|
|
0
|
|
588
|
0
|
|
|
|
|
0
|
$re = 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec';
|
589
|
0
|
|
|
|
|
0
|
}
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
590
|
6
|
100
|
|
|
|
190
|
when "B" {
|
|
1
|
|
|
|
|
12
|
|
591
|
1
|
|
|
|
|
2
|
$re =
|
592
|
|
|
|
|
|
|
'January|February|March|April|May|June|July|August|September|October|November|December';
|
593
|
1
|
|
|
|
|
6
|
}
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
594
|
5
|
50
|
|
|
|
60
|
when [ "U", "W" ] { $re = '[0-5]\d'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
# Day
|
597
|
5
|
50
|
|
|
|
152
|
when "j" { $re = '[0-3]\d{2}'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
598
|
5
|
50
|
|
|
|
59
|
when "d" { $re = '[0-3]\d'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
599
|
5
|
100
|
|
|
|
54
|
when "e" { $re = '[ |0|1|2|3]\d'; }
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
5
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
600
|
4
|
50
|
|
|
|
44
|
when "v" { $re = ' S| M| T| W|Th|F|Sa'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
601
|
4
|
50
|
|
|
|
52
|
when "a" { $re = 'Sun|Mon|Tue|Wed|Thu|Fri|Sat'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
602
|
4
|
50
|
|
|
|
46
|
when "A" {
|
|
0
|
|
|
|
|
0
|
|
603
|
0
|
|
|
|
|
0
|
$re = 'Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday';
|
604
|
0
|
|
|
|
|
0
|
}
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
605
|
4
|
50
|
|
|
|
45
|
when "w" { $re = '1-7'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
606
|
4
|
50
|
|
|
|
51
|
when "E" { $re = '\d{1,2}st|nd|rd|th'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
# Hours
|
609
|
4
|
50
|
|
|
|
46
|
when "H" { $re = '[0-2]\d'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
610
|
4
|
50
|
|
|
|
43
|
when "k" { $re = '[ 12]\d'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
611
|
4
|
100
|
|
|
|
44
|
when "i" { $re = '[ 1]\d'; }
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
612
|
3
|
50
|
|
|
|
34
|
when "I" { $re = '[01]\d'; }
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
613
|
3
|
100
|
|
|
|
34
|
when "p" { $re = 'AM|PM'; }
|
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
614
|
|
|
|
|
|
|
|
615
|
2
|
50
|
|
|
|
24
|
when [ "M", "S" ] { $re = '[0-6]\d'; }
|
|
2
|
|
|
|
|
50
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
616
|
|
|
|
|
|
|
|
617
|
0
|
|
|
|
|
0
|
else { carp "No Regular Expression found for POSIX format -- $format"; }
|
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
} # END case BLOCK
|
620
|
|
|
|
|
|
|
|
621
|
7
|
|
|
|
|
23
|
return $re
|
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
} # END SUBROUTINE _re
|
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program.
|
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
1;
|
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
__END__;
|