line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################################################ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: LocalTime.pm 211 2009-05-25 06:05:50Z aijaz $ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
################################################################################ |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
TaskForest::LocalTime - Module to provide local time. Can be made to return requested values during testing. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use TaskForest::LocalTime; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = &LocalTime::localtime(); |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# THE MONTH IS 1-BASED, AND THE YEAR IS THE FULL YEAR |
18
|
|
|
|
|
|
|
# (i.e., $mon++; $year += 1900; is not required) |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
&LocalTime::setTime({ year => $year, |
21
|
|
|
|
|
|
|
month => $mon, |
22
|
|
|
|
|
|
|
day => $day, |
23
|
|
|
|
|
|
|
hour => $hour, |
24
|
|
|
|
|
|
|
min => $min, |
25
|
|
|
|
|
|
|
sec => $sec, |
26
|
|
|
|
|
|
|
tz => $tz |
27
|
|
|
|
|
|
|
}); |
28
|
|
|
|
|
|
|
# ... |
29
|
|
|
|
|
|
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = &LocalTime::localtime(); |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# THE MONTH IS 1-BASED, AND THE YEAR IS THE FULL YEAR |
32
|
|
|
|
|
|
|
# (i.e., $mon++; $year += 1900; is not required) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DOCUMENTATION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
If you're just looking to use the taskforest application, the only |
37
|
|
|
|
|
|
|
documentation you need to read is that for TaskForest. You can do this |
38
|
|
|
|
|
|
|
either of the two ways: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
perldoc TaskForest |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
OR |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
man TaskForest |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This is a simple package that provides a location for the getLogDir |
49
|
|
|
|
|
|
|
function that's used in a few places. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package TaskForest::LocalTime; |
56
|
97
|
|
|
97
|
|
22301
|
use strict; |
|
97
|
|
|
|
|
2068
|
|
|
97
|
|
|
|
|
4870
|
|
57
|
97
|
|
|
97
|
|
838
|
use warnings; |
|
97
|
|
|
|
|
203
|
|
|
97
|
|
|
|
|
13873
|
|
58
|
97
|
|
|
97
|
|
592
|
use Carp; |
|
97
|
|
|
|
|
219
|
|
|
97
|
|
|
|
|
10738
|
|
59
|
97
|
|
|
97
|
|
30911
|
use DateTime; |
|
97
|
|
|
|
|
4471759
|
|
|
97
|
|
|
|
|
4035
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
BEGIN { |
62
|
97
|
|
|
97
|
|
800
|
use vars qw($VERSION); |
|
97
|
|
|
|
|
452
|
|
|
97
|
|
|
|
|
12013
|
|
63
|
97
|
|
|
97
|
|
41321
|
$VERSION = '1.30'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $time_offset = 0; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=over 4 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item setTime() |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Usage : &LocalTime::setTime({ year => $year, |
76
|
|
|
|
|
|
|
month => $mon, |
77
|
|
|
|
|
|
|
day => $day, |
78
|
|
|
|
|
|
|
hour => $hour, |
79
|
|
|
|
|
|
|
min => $min, |
80
|
|
|
|
|
|
|
sec => $sec, |
81
|
|
|
|
|
|
|
tz => $tz |
82
|
|
|
|
|
|
|
}); |
83
|
|
|
|
|
|
|
Purpose : This method 'sets' the current time to the time specified, in the |
84
|
|
|
|
|
|
|
timezone specified. |
85
|
|
|
|
|
|
|
Returns : Nothing |
86
|
|
|
|
|
|
|
Argument : A hash of values |
87
|
|
|
|
|
|
|
Throws : Nothing |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
94
|
|
|
|
|
|
|
sub setTime { |
95
|
78
|
|
|
78
|
1
|
100070
|
my $args = shift; |
96
|
|
|
|
|
|
|
|
97
|
78
|
50
|
|
|
|
408
|
unless($args) { |
98
|
0
|
|
|
|
|
0
|
$time_offset = 0; |
99
|
0
|
|
|
|
|
0
|
return; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
78
|
|
|
|
|
1366
|
my $dt = DateTime->new( year => $args->{year}, |
103
|
|
|
|
|
|
|
month => $args->{month}, |
104
|
|
|
|
|
|
|
day => $args->{day}, |
105
|
|
|
|
|
|
|
hour => $args->{hour}, |
106
|
|
|
|
|
|
|
minute => $args->{min}, |
107
|
|
|
|
|
|
|
second => $args->{sec}, |
108
|
|
|
|
|
|
|
time_zone => $args->{tz}, |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
78
|
|
|
|
|
1726405
|
my $desired_epoch = $dt->epoch(); |
112
|
|
|
|
|
|
|
|
113
|
78
|
|
|
|
|
2482
|
$time_offset = time() - $desired_epoch; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
119
|
|
|
|
|
|
|
=pod |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over 4 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item lt() |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Usage : &LocalTime::setTime({ year => $year, |
126
|
|
|
|
|
|
|
month => $mon, |
127
|
|
|
|
|
|
|
day => $day, |
128
|
|
|
|
|
|
|
hour => $hour, |
129
|
|
|
|
|
|
|
min => $min, |
130
|
|
|
|
|
|
|
sec => $sec, |
131
|
|
|
|
|
|
|
tz => $tz |
132
|
|
|
|
|
|
|
}); |
133
|
|
|
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = &LocalTime::lt(); |
134
|
|
|
|
|
|
|
Purpose : This method returns the localtime or the time that was previously |
135
|
|
|
|
|
|
|
set with setTime. Time set with setTime will advance. |
136
|
|
|
|
|
|
|
Returns : Nothing |
137
|
|
|
|
|
|
|
Argument : A hash of values |
138
|
|
|
|
|
|
|
Throws : Nothing |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
145
|
|
|
|
|
|
|
sub lt { |
146
|
256
|
|
|
256
|
1
|
11536
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( time() - $time_offset ); $mon++; $year += 1900; |
|
256
|
|
|
|
|
1326
|
|
|
256
|
|
|
|
|
578
|
|
147
|
|
|
|
|
|
|
|
148
|
256
|
|
|
|
|
1385
|
return ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub epoch { |
154
|
708
|
|
|
708
|
0
|
2832
|
return time() - $time_offset; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub ft { |
160
|
1408
|
|
|
1408
|
0
|
18420
|
my $tz = shift; |
161
|
1408
|
|
|
|
|
3188
|
my $epoch = time() - $time_offset; |
162
|
1408
|
|
|
|
|
8059
|
my $dt = DateTime->from_epoch(epoch => $epoch); |
163
|
1408
|
|
|
|
|
440639
|
$dt->set_time_zone($tz); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#return ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); |
166
|
1408
|
|
|
|
|
1067424
|
return ($dt->second, |
167
|
|
|
|
|
|
|
$dt->minute, |
168
|
|
|
|
|
|
|
$dt->hour, |
169
|
|
|
|
|
|
|
$dt->day, |
170
|
|
|
|
|
|
|
$dt->month, |
171
|
|
|
|
|
|
|
$dt->year, |
172
|
|
|
|
|
|
|
$dt->day_of_week % 7, |
173
|
|
|
|
|
|
|
undef, |
174
|
|
|
|
|
|
|
undef); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |