line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Simple::Range; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24142
|
use Time::Simple; |
|
1
|
|
|
|
|
14891
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
899
|
use Time::Seconds (); |
|
1
|
|
|
|
|
1838
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
87
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use base qw/ Class::Accessor /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
921
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ start end /); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.2'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use overload |
14
|
1
|
|
|
|
|
9
|
'fallback' => 1, |
15
|
|
|
|
|
|
|
'bool' => 'bool', |
16
|
|
|
|
|
|
|
'""' => 'stringify', |
17
|
|
|
|
|
|
|
'=' => 'clone', |
18
|
1
|
|
|
1
|
|
2385
|
; |
|
1
|
|
|
|
|
2
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new |
21
|
|
|
|
|
|
|
{ |
22
|
2
|
|
|
2
|
1
|
265
|
my $proto = shift; |
23
|
2
|
|
33
|
|
|
14
|
my $class = ref($proto) || $proto; |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
|
|
20
|
my $self = bless $proto->SUPER::new(), $class; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
30
|
my ($start, $end) = @_; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
8
|
$self->start($start); |
30
|
2
|
|
|
|
|
111
|
$self->end($end); |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
28
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub to_time_simple |
36
|
|
|
|
|
|
|
{ |
37
|
4
|
|
|
4
|
0
|
8
|
my ($self, $arg) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return undef |
40
|
4
|
50
|
|
|
|
11
|
unless defined $arg; |
41
|
|
|
|
|
|
|
|
42
|
4
|
100
|
|
|
|
14
|
if (ref($arg)) { |
43
|
3
|
50
|
|
|
|
31
|
return $arg |
44
|
|
|
|
|
|
|
if $arg->isa('Time::Simple'); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
0
|
|
|
0
|
return $arg->hms |
47
|
|
|
|
|
|
|
if $arg->isa('DateTime') |
48
|
|
|
|
|
|
|
or $arg->isa('Time::Piece'); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
0
|
|
|
0
|
$arg = Time::Simple->new($arg->time(0)) |
|
|
|
0
|
|
|
|
|
51
|
|
|
|
|
|
|
if $arg->isa('Date::Calc::Object') |
52
|
|
|
|
|
|
|
and $arg->is_long |
53
|
|
|
|
|
|
|
and $arg->is_valid; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
8
|
return Time::Simple->new($arg); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub start |
60
|
|
|
|
|
|
|
{ |
61
|
19
|
|
|
19
|
0
|
1037
|
my ($self, $arg) = @_; |
62
|
|
|
|
|
|
|
|
63
|
19
|
100
|
|
|
|
274
|
return $self->_start_accessor |
64
|
|
|
|
|
|
|
unless defined $arg; |
65
|
|
|
|
|
|
|
|
66
|
2
|
50
|
|
|
|
7
|
$arg = $self->to_time_simple($arg) |
67
|
|
|
|
|
|
|
or croak('invalid start time: ', $arg); |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
1095
|
return $self->_start_accessor($arg); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub end |
73
|
|
|
|
|
|
|
{ |
74
|
20
|
|
|
20
|
0
|
3111
|
my ($self, $arg) = @_; |
75
|
|
|
|
|
|
|
|
76
|
20
|
100
|
|
|
|
233
|
return $self->_end_accessor |
77
|
|
|
|
|
|
|
unless defined $arg; |
78
|
|
|
|
|
|
|
|
79
|
2
|
50
|
|
|
|
7
|
$arg = $self->to_time_simple($arg) |
80
|
|
|
|
|
|
|
or croak('invalid end time: ', $arg); |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
299
|
return $self->_end_accessor($arg); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub duration |
87
|
|
|
|
|
|
|
{ |
88
|
3
|
|
|
3
|
0
|
1583
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
3
|
50
|
33
|
|
|
9
|
return 0 |
91
|
|
|
|
|
|
|
unless defined $self->start |
92
|
|
|
|
|
|
|
and defined $self->end; |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
44
|
return Time::Seconds->new($self->end - $self->start); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub minutes |
98
|
|
|
|
|
|
|
{ |
99
|
1
|
|
|
1
|
0
|
622
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
1
|
50
|
33
|
|
|
3
|
return 0 |
102
|
|
|
|
|
|
|
unless defined $self->start |
103
|
|
|
|
|
|
|
and defined $self->end; |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
15
|
return $self->duration->minutes; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub bool |
109
|
|
|
|
|
|
|
{ |
110
|
5
|
|
|
5
|
0
|
1816
|
my $self = shift; |
111
|
5
|
|
66
|
|
|
13
|
return (defined $self->start && defined $self->end); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub stringify |
115
|
|
|
|
|
|
|
{ |
116
|
1
|
|
|
1
|
0
|
600
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
1
|
50
|
|
|
|
4
|
if ($self) { |
119
|
1
|
|
|
|
|
10
|
return $self->start . '-' . $self->end; |
120
|
|
|
|
|
|
|
} else { |
121
|
0
|
|
|
|
|
0
|
return 'incomplete range'; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub clone |
126
|
|
|
|
|
|
|
{ |
127
|
1
|
|
|
1
|
0
|
694
|
my $self = shift; |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
4
|
return new Time::Simple::Range( |
130
|
|
|
|
|
|
|
new Time::Simple($self->start), |
131
|
|
|
|
|
|
|
new Time::Simple($self->end)); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 NAME |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Time::Simple::Range - A range of Time::Simple objects |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SYNOPSIS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
use Time::Simple::Range; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $range = new Time::Simple::Range('14:00:00', '15:00:00'); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
print $range->start, "\n"; |
147
|
|
|
|
|
|
|
print $range->end, "\n"; |
148
|
|
|
|
|
|
|
print $range->duration, "\n"; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DESCRIPTION |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
A range of Time::Simple objects |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Time::Simple, Time::Seconds |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 AUTHOR |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Alessandro Zummo, Ea.zummo@towertech.itE |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Copyright (C) 2008-09 by Alessandro Zummo |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
167
|
|
|
|
|
|
|
modify it under the terms of the GNU General Public License version 2 as |
168
|
|
|
|
|
|
|
published by the Free Software Foundation. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |