line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MySQL::DateFormat; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
414
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
3
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
5
|
1
|
|
|
1
|
|
431
|
use Date::Calc; |
|
1
|
|
|
|
|
25216
|
|
|
1
|
|
|
|
|
60
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION $VERSION_DATE); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
637
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = "1.03"; |
10
|
|
|
|
|
|
|
$VERSION_DATE = "November 30, 2014"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
1
|
|
|
1
|
0
|
33
|
my $proto = shift; |
14
|
1
|
|
33
|
|
|
5
|
my $class = ref($proto) || $proto; |
15
|
1
|
|
|
|
|
2
|
my $self = {}; |
16
|
1
|
|
|
|
|
2
|
%{ $self->{args} } = @_; |
|
1
|
|
|
|
|
5
|
|
17
|
1
|
50
|
|
|
|
3
|
unless ($self->{args}->{format}) { |
18
|
0
|
|
|
|
|
0
|
croak "[$$] No format specified. Value of 'format' arg must be 'us' or 'eu'."; |
19
|
|
|
|
|
|
|
} |
20
|
1
|
|
|
|
|
2
|
bless($self, $class); |
21
|
1
|
|
|
|
|
2
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub toMySQL { |
25
|
1
|
|
|
1
|
1
|
12
|
my $self = shift; |
26
|
1
|
|
|
|
|
1
|
my $date = shift; |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
3
|
unless ($date) { |
29
|
0
|
|
|
|
|
0
|
carp "[$$] No date supplied"; |
30
|
0
|
|
|
|
|
0
|
return 0; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
4
|
$date =~ s#/#-#g; # we accept either |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
1
|
my ($d, $m, $y); |
36
|
1
|
|
|
|
|
3
|
my ($a, $b, $c) = split("-", $date); |
37
|
|
|
|
|
|
|
|
38
|
1
|
50
|
33
|
|
|
7
|
unless ($a and $b and $c) { |
|
|
|
33
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
carp "[$$] Invalid date [$a/$b/$c]"; |
40
|
0
|
|
|
|
|
0
|
return 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
5
|
if ($self->{args}->{format} eq 'eu') { |
|
|
50
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Europe format: DD/MM/YYYY |
45
|
0
|
|
|
|
|
0
|
$d = $a; $m = $b; $y = $c; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
46
|
|
|
|
|
|
|
} elsif ($self->{args}->{format} eq 'us') { |
47
|
|
|
|
|
|
|
# USA format: MM/DD/YYYY |
48
|
1
|
|
|
|
|
2
|
$m = $a; $d = $b; $y = $c; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1
|
|
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
0
|
carp "[$$] Invalid format specified. Value of 'format' arg must be 'us' or 'eu'."; |
51
|
0
|
|
|
|
|
0
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
0
|
33
|
|
|
5
|
if ($self->{args}->{century_cutoff} and $self->{args}->{century_cutoff} eq 'disallow' |
|
|
|
33
|
|
|
|
|
55
|
|
|
|
|
|
|
and $y !~ m/^\d{4}$/) { |
56
|
0
|
|
|
|
|
0
|
carp "[$$] Two-digit year supplied when four digits required"; |
57
|
0
|
|
|
|
|
0
|
return 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
4
|
$m = sprintf("%0.2d", $m); |
61
|
1
|
|
|
|
|
3
|
$d = sprintf("%0.2d", $d); |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
2
|
my $cutoff = 20; |
64
|
1
|
50
|
33
|
|
|
3
|
if ($self->{args}->{century_cutoff} and $self->{args}->{century_cutoff} =~ m/^\d{1,2}$/) { |
65
|
0
|
|
|
|
|
0
|
$cutoff = $self->{args}->{century_cutoff}; |
66
|
|
|
|
|
|
|
} |
67
|
1
|
0
|
|
|
|
3
|
$y = ($y < 100) ? ($y > $cutoff) ? $y + 1900 : $y + 2000 : $y; |
|
|
50
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
1
|
50
|
|
|
|
7
|
unless (Date::Calc::check_date($y,$m,$d)) { |
70
|
0
|
|
|
|
|
0
|
carp "[$$] Invalid date [y:$y m:$m d:$d]"; |
71
|
0
|
|
|
|
|
0
|
return 0; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
22
|
return join("-", $y, $m, $d); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub frMySQL { |
78
|
1
|
|
|
1
|
1
|
24
|
my $self = shift; |
79
|
1
|
|
|
|
|
1
|
my $date = shift; |
80
|
|
|
|
|
|
|
|
81
|
1
|
50
|
|
|
|
3
|
unless ($date) { |
82
|
0
|
|
|
|
|
0
|
carp "[$$] No date supplied"; |
83
|
0
|
|
|
|
|
0
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
2
|
$date =~ s#/#-#g; |
87
|
1
|
|
|
|
|
6
|
my ($y,$m,$d) = split("-", $date); |
88
|
|
|
|
|
|
|
|
89
|
1
|
50
|
|
|
|
4
|
unless (Date::Calc::check_date($y,$m,$d)) { |
90
|
0
|
|
|
|
|
0
|
carp "[$$] Invalid date [y:$y m:$m d:$d]"; |
91
|
0
|
|
|
|
|
0
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
14
|
if ($self->{args}->{informal}) { |
95
|
1
|
|
|
|
|
5
|
$m =~ s/^0//; |
96
|
1
|
|
|
|
|
2
|
$d =~ s/^0//; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
2
|
my $separator = '/'; |
100
|
1
|
50
|
|
|
|
4
|
if ($self->{args}->{separator}) { |
101
|
0
|
|
|
|
|
0
|
$separator = $self->{args}->{separator}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
3
|
my @elements = ($m,$d,$y); |
105
|
1
|
50
|
33
|
|
|
8
|
@elements = ($d,$m,$y) if $self->{args}->{format} and $self->{args}->{format} eq 'eu'; |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
6
|
return join($separator, @elements); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |