line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package Date::Handler::Range; |
3
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
900
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
258
|
|
5
|
8
|
|
|
8
|
|
42
|
use Carp; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
523
|
|
6
|
8
|
|
|
8
|
|
45
|
use Data::Dumper; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
333
|
|
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
40
|
use Date::Handler; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
163
|
|
9
|
8
|
|
|
8
|
|
41
|
use Date::Handler::Delta; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
425
|
|
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
38
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
6171
|
|
12
|
|
|
|
|
|
|
$VERSION = '1.0'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new |
15
|
|
|
|
|
|
|
{ |
16
|
1
|
|
|
1
|
0
|
2
|
my ($classname, $args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
9
|
croak "No arguments to new()" if not defined $args; |
19
|
1
|
50
|
|
|
|
4
|
croak "No date argument passed to new()" if not defined $args->{date}; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
2
|
my $self = {}; |
22
|
1
|
|
|
|
|
2
|
bless $self, $classname; |
23
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
4
|
if(ref($args) eq 'HASH') |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
#Get the date from the arguments. |
27
|
1
|
50
|
|
|
|
6
|
if(UNIVERSAL::isa($args->{date}, 'Date::Handler')) |
28
|
|
|
|
|
|
|
{ |
29
|
1
|
|
|
|
|
4
|
$self->{date} = $args->{date}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
|
|
0
|
my $date = new Date::Handler({ date => $args->{date} }); |
34
|
0
|
0
|
|
|
|
0
|
if(defined $date) |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
0
|
$self->{date} = $date; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
0
|
croak "Invalid format for date in new()"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
1
|
50
|
|
|
|
6
|
if(UNIVERSAL::isa($args->{delta}, 'Date::Handler::Delta')) |
45
|
|
|
|
|
|
|
{ |
46
|
1
|
|
|
|
|
2
|
$self->{delta} = $args->{delta}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
|
|
0
|
my $delta = Date::Handler::Delta->new($args->{delta}); |
51
|
0
|
0
|
|
|
|
0
|
if(defined $delta) |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
0
|
$self->{delta} = $delta; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
0
|
croak "Invalid format for delta in new()"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else |
62
|
|
|
|
|
|
|
{ |
63
|
0
|
|
|
|
|
0
|
croak "Invalid arguments passed to new() (not HASHREF)"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
3
|
return $self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub Direction |
71
|
|
|
|
|
|
|
{ |
72
|
5
|
|
|
5
|
0
|
7
|
my $self = shift; |
73
|
5
|
|
|
|
|
8
|
my $direction = shift; |
74
|
|
|
|
|
|
|
|
75
|
5
|
100
|
|
|
|
11
|
if(defined $direction) |
76
|
|
|
|
|
|
|
{ |
77
|
1
|
50
|
33
|
|
|
15
|
if($direction =~ /FORWARDS/i || $direction eq 1) |
|
|
50
|
33
|
|
|
|
|
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
0
|
$self->{direction} = 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
elsif($direction =~ /BACKWARDS/i || $direction eq 0) |
82
|
|
|
|
|
|
|
{ |
83
|
1
|
|
|
|
|
3
|
$self->{direction} = 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
5
|
100
|
|
|
|
11
|
$self->{direction} = 1 if not defined $self->{direction}; |
88
|
5
|
|
|
|
|
20
|
return $self->{direction}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub Delta |
93
|
|
|
|
|
|
|
{ |
94
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
95
|
2
|
|
|
|
|
2
|
my $delta = shift; |
96
|
|
|
|
|
|
|
|
97
|
2
|
50
|
33
|
|
|
6
|
if(defined $delta && $delta->isa('Date::Handler::Delta')) |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
0
|
$self->{delta} = $delta; |
100
|
|
|
|
|
|
|
} |
101
|
2
|
|
|
|
|
9
|
return $self->{delta}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub Date |
105
|
|
|
|
|
|
|
{ |
106
|
4
|
|
|
4
|
0
|
6
|
my $self = shift; |
107
|
4
|
|
|
|
|
4
|
my $date = shift; |
108
|
|
|
|
|
|
|
|
109
|
4
|
50
|
33
|
|
|
11
|
if(defined $date && $date->isa('Date::Handler')) |
110
|
|
|
|
|
|
|
{ |
111
|
0
|
|
|
|
|
0
|
$self->{date} = $date; |
112
|
|
|
|
|
|
|
} |
113
|
4
|
|
|
|
|
37
|
return $self->{date}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub StartDate |
117
|
|
|
|
|
|
|
{ |
118
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
119
|
|
|
|
|
|
|
|
120
|
2
|
100
|
|
|
|
4
|
if($self->Direction()) |
121
|
|
|
|
|
|
|
{ |
122
|
1
|
|
|
|
|
4
|
return $self->Date(); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else |
125
|
|
|
|
|
|
|
{ |
126
|
1
|
|
|
|
|
4
|
return $self->Date() - $self->Delta(); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub EndDate |
131
|
|
|
|
|
|
|
{ |
132
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
133
|
|
|
|
|
|
|
|
134
|
2
|
100
|
|
|
|
5
|
if($self->Direction()) |
135
|
|
|
|
|
|
|
{ |
136
|
1
|
|
|
|
|
4
|
return $self->Date() + $self->Delta(); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else |
139
|
|
|
|
|
|
|
{ |
140
|
1
|
|
|
|
|
5
|
return $self->Date(); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub Overlaps |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
147
|
0
|
|
|
|
|
|
my $range = shift; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
croak "Arguments to Overlaps() is not a Date::Handler::Range" if !$range->isa('Date::Handler::Range'); |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
return 0 if($self->EndDate() <= $range->StartDate()); |
152
|
0
|
0
|
|
|
|
|
return 0 if($range->EndDate() <= $self->StartDate()); |
153
|
0
|
|
|
|
|
|
return 1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
666; |
160
|
|
|
|
|
|
|
__END__ |