line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package perfSONAR_PS::Time; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
37539
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
1377
|
use Log::Log4perl qw(get_logger); |
|
1
|
|
|
|
|
62287
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
11904
|
use Data::Dumper; |
|
1
|
|
|
|
|
19603
|
|
|
1
|
|
|
|
|
95
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1741
|
use fields 'TYPE', 'STARTTIME', 'ENDTIME', 'DURATION', 'TIME'; |
|
1
|
|
|
|
|
2046
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.09; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
perfSONAR_PS::Time - A module that provides methods for the a simple time |
15
|
|
|
|
|
|
|
element that can represent either single points in time or time ranges as unix |
16
|
|
|
|
|
|
|
timestamps. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 new ($package, $type, $arg1, $arg2) |
21
|
|
|
|
|
|
|
This allocates a perfSONAR_PS::Time element. The type parameter can be one |
22
|
|
|
|
|
|
|
of 'range', 'duration' or 'point'. If the type is 'point', then $arg1 is |
23
|
|
|
|
|
|
|
the time parameter as a unix timestamp. If the type is 'range', then $arg1 |
24
|
|
|
|
|
|
|
is the startTime and $arg2 is the endTime. If the type is 'duration', then |
25
|
|
|
|
|
|
|
$arg1 is the startTime and $arg2 is the duration. |
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
sub new { |
28
|
3
|
|
|
3
|
1
|
1314
|
my ($package, $type, $arg1, $arg2) = @_; |
29
|
3
|
|
|
|
|
16
|
my $logger = get_logger("perfSONAR_PS::Time"); |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
435
|
my $self = fields::new($package); |
32
|
|
|
|
|
|
|
|
33
|
3
|
100
|
|
|
|
4322
|
if ($type eq "range") { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
$self->{TYPE} = "range"; |
35
|
1
|
|
|
|
|
3
|
$self->{STARTTIME} = $arg1; |
36
|
1
|
|
|
|
|
4
|
$self->{ENDTIME} = $arg2; |
37
|
1
|
|
|
|
|
2
|
$self->{DURATION} = $arg2 - $arg1; |
38
|
|
|
|
|
|
|
} elsif ($type eq "duration") { |
39
|
1
|
|
|
|
|
4
|
$self->{TYPE} = "duration"; |
40
|
1
|
|
|
|
|
3
|
$self->{STARTTIME} = $arg1; |
41
|
1
|
|
|
|
|
3
|
$self->{DURATION} = $arg2; |
42
|
|
|
|
|
|
|
} elsif ($type eq "point") { |
43
|
1
|
|
|
|
|
3
|
$self->{TYPE} = "point"; |
44
|
1
|
|
|
|
|
3
|
$self->{TIME} = $arg1; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
0
|
$logger->error("Invalid type: $type"); |
47
|
0
|
|
|
|
|
0
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
13
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 getType ($self) |
54
|
|
|
|
|
|
|
This function returns what type 'point', 'range' or 'duration' that this |
55
|
|
|
|
|
|
|
Time element is. |
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
sub getType { |
58
|
3
|
|
|
3
|
1
|
1540
|
my ($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
17
|
return $self->{TYPE}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 getTime ($self) |
64
|
|
|
|
|
|
|
This function is valid for Time elements of type 'point' and simply returns |
65
|
|
|
|
|
|
|
the point in time that this element describes. |
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
sub getTime { |
68
|
3
|
|
|
3
|
1
|
7
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
13
|
return $self->{TIME}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 getStartTime ($self) |
74
|
|
|
|
|
|
|
This function is valid for Time elements of type 'range' or 'duration' and |
75
|
|
|
|
|
|
|
returns the starting point of the time range. |
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
sub getStartTime { |
78
|
3
|
|
|
3
|
1
|
7
|
my ($self) = @_; |
79
|
3
|
100
|
|
|
|
12
|
if ($self->{TYPE} eq "point") { |
80
|
1
|
|
|
|
|
5
|
return $self->{TIME}; |
81
|
|
|
|
|
|
|
} else { |
82
|
2
|
|
|
|
|
10
|
return $self->{STARTTIME}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 getEndTime ($self) |
87
|
|
|
|
|
|
|
This function is valid for Time elements of type 'range' or 'duration' and |
88
|
|
|
|
|
|
|
returns the ending point of the time range. |
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
sub getEndTime { |
91
|
3
|
|
|
3
|
1
|
7
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
3
|
100
|
|
|
|
17
|
if ($self->{TYPE} eq "duration") { |
|
|
100
|
|
|
|
|
|
94
|
1
|
|
|
|
|
27
|
return $self->{STARTTIME} + $self->{DURATION}; |
95
|
|
|
|
|
|
|
} elsif ($self->{TYPE} eq "range") { |
96
|
1
|
|
|
|
|
7
|
return $self->{ENDTIME}; |
97
|
|
|
|
|
|
|
} else { |
98
|
1
|
|
|
|
|
5
|
return $self->{TIME}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 getDuration ($self) |
103
|
|
|
|
|
|
|
This function is valid for Time elements of type 'duration' and |
104
|
|
|
|
|
|
|
returns the duration of the time range. |
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
sub getDuration { |
107
|
3
|
|
|
3
|
1
|
10
|
my ($self) = @_; |
108
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
14
|
return $self->{DURATION}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |