| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Lyskom::Time; |
|
2
|
1
|
|
|
1
|
|
4
|
use base qw{Net::Lyskom::Object}; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
61
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Time::Local; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
57
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
9
|
1
|
|
|
1
|
|
13
|
use warnings; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
760
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Net::Lyskom::Time - object that holds a time value. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
print scalar localtime($obj->time_t); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
All methods except time_t() and new() are get/set attribute accessors. That |
|
22
|
|
|
|
|
|
|
is, they return the attribute's contents if called without an argument and |
|
23
|
|
|
|
|
|
|
set the attribute's contents if given an argument. time_t() returns the held |
|
24
|
|
|
|
|
|
|
time in seconds since the Unix epoch, and new() creates a new object. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 Methods |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=over |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item ->new(seconds => $s, minutes => $m, hours => $h, day => $d, month => $mo, year => $y, day_of_week => $wd, day_of_year => $yd, is_dst => $dst) |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
All arguments are optional. If not given, they default to the value appropriate |
|
33
|
|
|
|
|
|
|
to the current time. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item ->seconds($s) |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item ->minutes($m) |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item ->hours($h) |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item ->day($d) |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item ->month($mo) |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item ->year($y) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item ->day_of_week($wd) |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item ->day_of_year($yd) |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item ->is_dst($dst) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item ->time_t() |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
|
60
|
10
|
|
|
10
|
1
|
24
|
my $s = {}; |
|
61
|
10
|
|
|
|
|
20
|
my $class = shift; |
|
62
|
10
|
|
|
|
|
84
|
my %a = @_; |
|
63
|
10
|
|
|
|
|
378
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); |
|
64
|
|
|
|
|
|
|
|
|
65
|
10
|
50
|
|
|
|
31
|
$class = ref($class) if ref($class); |
|
66
|
10
|
|
|
|
|
31
|
bless $s,$class; |
|
67
|
|
|
|
|
|
|
|
|
68
|
10
|
50
|
|
|
|
21181
|
$s->{seconds} = exists $a{seconds} ? $a{seconds} : $sec; |
|
69
|
10
|
50
|
|
|
|
40
|
$s->{minutes} = exists $a{minutes} ? $a{minutes} : $min; |
|
70
|
10
|
50
|
|
|
|
68
|
$s->{hours} = exists $a{hours} ? $a{hours} : $hour; |
|
71
|
10
|
50
|
|
|
|
34
|
$s->{day} = exists $a{day} ? $a{day} : $mday; |
|
72
|
10
|
50
|
|
|
|
30
|
$s->{month} = exists $a{month} ? $a{month} : $mon; |
|
73
|
10
|
50
|
|
|
|
32
|
$s->{year} = exists $a{year} ? $a{year} : $year; |
|
74
|
10
|
50
|
|
|
|
33
|
$s->{day_of_week} = exists $a{day_of_week} ? $a{day_of_week} : $wday; |
|
75
|
10
|
50
|
|
|
|
40
|
$s->{day_of_year} = exists $a{day_of_year} ? $a{day_of_year} : $yday; |
|
76
|
10
|
50
|
|
|
|
36
|
$s->{is_dst} = exists $a{is_dst} ? $a{is_dst} : $isdst; |
|
77
|
|
|
|
|
|
|
|
|
78
|
10
|
|
|
|
|
48
|
return $s; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub new_from_stream { |
|
82
|
10
|
|
|
10
|
0
|
16
|
my $s = shift; |
|
83
|
10
|
|
|
|
|
15
|
my $arg = $_[0]; |
|
84
|
|
|
|
|
|
|
|
|
85
|
10
|
|
|
|
|
65
|
my $res = $s->new( |
|
86
|
|
|
|
|
|
|
seconds => $arg->[0], |
|
87
|
|
|
|
|
|
|
minutes => $arg->[1], |
|
88
|
|
|
|
|
|
|
hours => $arg->[2], |
|
89
|
|
|
|
|
|
|
day => $arg->[3], |
|
90
|
|
|
|
|
|
|
month => $arg->[4], |
|
91
|
|
|
|
|
|
|
year => $arg->[5], |
|
92
|
|
|
|
|
|
|
day_of_week => $arg->[6], |
|
93
|
|
|
|
|
|
|
day_of_year => $arg->[7], |
|
94
|
|
|
|
|
|
|
is_dst => $arg->[8] |
|
95
|
|
|
|
|
|
|
); |
|
96
|
10
|
|
|
|
|
16
|
splice @{$arg},0,9; |
|
|
10
|
|
|
|
|
32
|
|
|
97
|
10
|
|
|
|
|
68
|
return $res; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub seconds { |
|
101
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
102
|
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
0
|
$s->{seconds} = $_[0] if $_[0]; |
|
104
|
0
|
|
|
|
|
0
|
return $s->{seconds}; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub minutes { |
|
108
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
0
|
$s->{minutes} = $_[0] if $_[0]; |
|
111
|
0
|
|
|
|
|
0
|
return $s->{minutes}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub hours { |
|
115
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
0
|
$s->{hours} = $_[0] if $_[0]; |
|
118
|
0
|
|
|
|
|
0
|
return $s->{hours}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub day { |
|
122
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
0
|
$s->{day} = $_[0] if $_[0]; |
|
125
|
0
|
|
|
|
|
0
|
return $s->{day}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub month { |
|
129
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
0
|
$s->{month} = $_[0] if $_[0]; |
|
132
|
0
|
|
|
|
|
0
|
return $s->{month}; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub year { |
|
136
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
0
|
$s->{year} = $_[0] if $_[0]; |
|
139
|
0
|
|
|
|
|
0
|
return $s->{year}; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub day_of_week { |
|
143
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
0
|
$s->{day_of_week} = $_[0] if $_[0]; |
|
146
|
0
|
|
|
|
|
0
|
return $s->{day_of_week}; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub day_of_year { |
|
150
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
0
|
$s->{day_of_year} = $_[0] if $_[0]; |
|
153
|
0
|
|
|
|
|
0
|
return $s->{day_of_year}; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub is_dst { |
|
157
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
0
|
$s->{is_dst} = $_[0] if $_[0]; |
|
160
|
0
|
|
|
|
|
0
|
return $s->{is_dst}; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub time_t { |
|
164
|
2
|
|
|
2
|
1
|
793
|
my $s = shift; |
|
165
|
|
|
|
|
|
|
|
|
166
|
2
|
50
|
|
|
|
25
|
$s->{time_t} = timelocal($s->{seconds},$s->{minutes},$s->{hours}, |
|
167
|
|
|
|
|
|
|
$s->{day},$s->{month},$s->{year}) |
|
168
|
|
|
|
|
|
|
unless exists($s->{time_t}); |
|
169
|
|
|
|
|
|
|
|
|
170
|
2
|
|
|
|
|
249
|
return $s->{time_t}; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub as_string { |
|
174
|
1
|
|
|
1
|
1
|
2
|
my $s = shift; |
|
175
|
|
|
|
|
|
|
|
|
176
|
1
|
|
|
|
|
5
|
return "Time => { ".scalar(localtime($s->time_t))." }"; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
return 1; |