line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::TimeZone::LMT; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
103732
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
171
|
|
4
|
4
|
|
|
4
|
|
23
|
use vars qw( $VERSION ); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
295
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '1.00'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
3872
|
use Params::Validate qw( validate validate_pos SCALAR ARRAYREF BOOLEAN ); |
|
4
|
|
|
|
|
46416
|
|
|
4
|
|
|
|
|
381
|
|
9
|
4
|
|
|
4
|
|
36
|
use Carp; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
216
|
|
10
|
4
|
|
|
4
|
|
5668
|
use DateTime; |
|
4
|
|
|
|
|
664670
|
|
|
4
|
|
|
|
|
168
|
|
11
|
4
|
|
|
4
|
|
52
|
use DateTime::TimeZone; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2197
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
16
|
|
|
16
|
1
|
8066
|
my $class = shift; |
15
|
16
|
|
|
|
|
389
|
my %p = validate( @_, { |
16
|
|
|
|
|
|
|
longitude => { type => SCALAR }, |
17
|
|
|
|
|
|
|
name => { type => SCALAR, optional => 1 } |
18
|
|
|
|
|
|
|
}); |
19
|
16
|
50
|
33
|
|
|
176
|
croak("Your longitude must be between -180 and +180") unless $p{longitude} <= 180 and $p{longitude} >= -180; |
20
|
|
|
|
|
|
|
|
21
|
16
|
|
|
|
|
64
|
my %self = ( |
22
|
|
|
|
|
|
|
longitude => $p{longitude}, |
23
|
|
|
|
|
|
|
offset => offset_at_longitude($p{longitude}), |
24
|
|
|
|
|
|
|
); |
25
|
16
|
50
|
|
|
|
552
|
$self{name} = $p{name} if exists $p{name}; |
26
|
|
|
|
|
|
|
|
27
|
16
|
|
|
|
|
76
|
return bless \%self, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub offset_for_datetime{ |
31
|
14
|
|
|
14
|
1
|
93
|
my ($self, $dt) = @_; |
32
|
14
|
|
|
|
|
37
|
return DateTime::TimeZone::offset_as_seconds($self->{offset}) |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub offset_for_local_datetime{ |
36
|
16
|
|
|
16
|
1
|
116
|
my ($self, $dt) = @_; |
37
|
16
|
|
|
|
|
48
|
return DateTime::TimeZone::offset_as_seconds($self->{offset}) |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
2
|
0
|
426
|
sub offset { $_[0]->{offset} } |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
1
|
0
|
sub short_name_for_datetime { 'LMT' } |
43
|
|
|
|
|
|
|
sub name { |
44
|
6
|
|
|
6
|
1
|
746
|
my $self = shift; |
45
|
6
|
|
|
|
|
12
|
my $new_name = shift; |
46
|
6
|
100
|
|
|
|
18
|
$self->{name} = $new_name if $new_name; |
47
|
6
|
|
|
|
|
415
|
return $self->{name} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub longitude { |
51
|
18
|
|
|
18
|
1
|
5409
|
my $self = shift; |
52
|
18
|
|
|
|
|
21
|
my $new_longitude = shift; |
53
|
18
|
100
|
|
|
|
41
|
if ($new_longitude) { |
54
|
2
|
50
|
33
|
|
|
12
|
croak("Your longitude must be between -180 and +180") |
55
|
|
|
|
|
|
|
unless $new_longitude <= 180 and $new_longitude >= -180; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
3
|
$self->{longitude} = $new_longitude; |
58
|
2
|
|
|
|
|
5
|
$self->{offset} = offset_at_longitude($new_longitude); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
18
|
|
|
|
|
132
|
return $self->{longitude} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# No, we're not floating (unless on a boat, in which case you'll |
66
|
|
|
|
|
|
|
# have to continually modify your longitude. Unless, of course, |
67
|
|
|
|
|
|
|
# you're heading due north or due south. In which case your |
68
|
|
|
|
|
|
|
# longitude will not change. |
69
|
53
|
|
|
53
|
1
|
87642
|
sub is_floating { 0 } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Not this either. Unless we're on the Prime Meridian (0 deg long) |
72
|
|
|
|
|
|
|
# in which case we're still not UTC, although we're the same as. |
73
|
31
|
|
|
31
|
1
|
8343
|
sub is_utc { 0 } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Nup, these aren't olsons either |
76
|
0
|
|
|
0
|
1
|
0
|
sub is_olson { 0 } |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# No such thing as DST so we're never in DST |
79
|
0
|
|
|
0
|
0
|
0
|
sub is_dst_for_datetime { 0 } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# We're a solar based zone, so for the sake of returning something |
82
|
|
|
|
|
|
|
# I'm returning 'solar'. If I return 'Local' it could be confused |
83
|
|
|
|
|
|
|
# with DateTime::TimeZone::Local |
84
|
0
|
|
|
0
|
1
|
0
|
sub category { 'Solar' } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub make_alias { |
87
|
2
|
|
|
2
|
0
|
697
|
my $self = shift; |
88
|
2
|
|
100
|
|
|
9
|
my $name = shift || 'LMT'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#eval("use DateTime::TimeZone::Alias $name => ".$self->{offset}); |
91
|
|
|
|
|
|
|
#if (@_) { |
92
|
2
|
|
|
|
|
17
|
$DateTime::TimeZone::LINKS{ $name } = $self->{offset}; |
93
|
|
|
|
|
|
|
#} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
# Functions |
98
|
|
|
|
|
|
|
# |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub offset_at_longitude { |
101
|
|
|
|
|
|
|
# A function, not a class method |
102
|
|
|
|
|
|
|
|
103
|
18
|
|
|
18
|
1
|
25
|
my $longitude = shift; |
104
|
|
|
|
|
|
|
|
105
|
18
|
|
|
|
|
45
|
my $offset_seconds = ( $longitude / 180 ) * (12 * 60 * 60); |
106
|
|
|
|
|
|
|
|
107
|
18
|
|
|
|
|
68
|
return DateTime::TimeZone::offset_as_string( $offset_seconds ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
DateTime::TimeZone::LMT - A Local Mean Time time zone for DateTime |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 SYNOPSIS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use DateTime::TimeZone::LMT |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $tz_lmt = DateTime::TimeZone::LMT->new( |
119
|
|
|
|
|
|
|
longitude => -174.2342 |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$now = DateTime->now( time_zone => $tz_lmt ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $tz_office = DateTime::TimeZone::LMT->new( |
125
|
|
|
|
|
|
|
name => 'Office', |
126
|
|
|
|
|
|
|
longitude => -174.2343 |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$tz_office->make_alias; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$now = DateTime->now( time_zone => 'Office' ); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$tz_office->name; |
134
|
|
|
|
|
|
|
# Office |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$tz_office->longitude( 45.123 ); |
137
|
|
|
|
|
|
|
# 45.123 |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
$tz_office->longitude; |
140
|
|
|
|
|
|
|
# 45.123 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 DESCRIPTION |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This module provides a 'Local Mean Time' timezone for DateTime. Using |
146
|
|
|
|
|
|
|
it you can determine the Mean Time for any location on Earth. Note |
147
|
|
|
|
|
|
|
however that the Mean Time and the Apparent Time (where the sun is |
148
|
|
|
|
|
|
|
in the sky) differ from day to day. This module may account for |
149
|
|
|
|
|
|
|
Local Apparent Time in the future but then again, the Solar:: modules |
150
|
|
|
|
|
|
|
will probably be a better bet. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
If you want more information on the difference between LMT and LAT, |
153
|
|
|
|
|
|
|
search the www for 'equation of time' or 'ephemeris'. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 CONSTRUCTORS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This module has the following constructor: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over 4 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * new( longitude => $longitude_float, name => $name_string ) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Creates a new time zone object usable by DateTime. The zone is calculated |
164
|
|
|
|
|
|
|
to the second for the given longitude. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
An optional name can be given in order to distinguish between multiple |
167
|
|
|
|
|
|
|
instances. This is the long name accessable via DateTime. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 ACCESSORS |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
C objects provide the following accessor methods: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over 4 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * offset_for_datetime( $datetime ) |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Given an object which implements the DateTime.pm API, this method |
180
|
|
|
|
|
|
|
returns the offset in seconds for the given datetime. This takes into |
181
|
|
|
|
|
|
|
account historical time zone information, as well as Daylight Saving |
182
|
|
|
|
|
|
|
Time. The offset is determined by looking at the object's UTC Rata |
183
|
|
|
|
|
|
|
Die days and seconds. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item * offset_for_local_datetime( $datetime ) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Given an object which implements the DateTime.pm API, this method |
188
|
|
|
|
|
|
|
returns the offset in seconds for the given datetime. Unlike the |
189
|
|
|
|
|
|
|
previous method, this method uses the local time's Rata Die days and |
190
|
|
|
|
|
|
|
seconds. This should only be done when the corresponding UTC time is |
191
|
|
|
|
|
|
|
not yet known, because local times can be ambiguous due to Daylight |
192
|
|
|
|
|
|
|
Saving Time rules. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * name( $new_name_string ) |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Returns the name of the time zone. This is "Local Mean Time" unless |
197
|
|
|
|
|
|
|
the contructor specifies a different name. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
If a new name is given, then the object will be changed before being |
200
|
|
|
|
|
|
|
returned. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * longitude( $new_longitude_float ) |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Returns the longitude of the time zone. This is the value specified |
205
|
|
|
|
|
|
|
in the constructor. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
If a new longitude is given, then the object will be changed before |
208
|
|
|
|
|
|
|
being returned. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * short_name_for_datetime( $datetime ) |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Returns 'LMT' in all circumstances. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
It is B recommended that you do not rely on short names for |
215
|
|
|
|
|
|
|
anything other than display. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * create_alias( $alias_name ); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Creates an alias that can be called as a string by DateTime methods. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
This means you can C<$dt = DateTime->new( time_zone => 'LMT' )> rather |
222
|
|
|
|
|
|
|
than the normal C<$dt = DateTime->new( time_zone => $lmt )>. This is of |
223
|
|
|
|
|
|
|
little benefit unless you're accepting a time zone name from a user. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
If the optional $alias_name is provided then that will be the alias |
226
|
|
|
|
|
|
|
created. Otherwise the alias is 'LMT'. Multiple aliases can be created |
227
|
|
|
|
|
|
|
from the one object. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
If the longitude is changed after an alias is created, then the alias |
230
|
|
|
|
|
|
|
B>. The alias does not behave as an instance of |
231
|
|
|
|
|
|
|
C. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 Compatability methods |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
The following methods always return the same value. They exist in order |
238
|
|
|
|
|
|
|
to make the LMT time zone compatible with the default C |
239
|
|
|
|
|
|
|
modules. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=over 4 |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item * is_floating |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Returns false (0) in all circumstances. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item * is_utc |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Returns false (0) in all circumstances. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item * is_olson |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
Returns false (0) in all circumstances. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * category |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Returns 'Solar' in all circumstances. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=back |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 Functions |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This class also contains the following function: |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over 4 |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * offset_at_longitude( $longitude ) |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Given a longitude, this method returns a string offset. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=back |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 SUPPORT |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Support for this module is provided via the datetime@perl.org email |
276
|
|
|
|
|
|
|
list. See http://lists.perl.org/ for more details. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Please submit bugs to the CPAN RT system at |
279
|
|
|
|
|
|
|
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=datetime%3A%3Atimezone%3A%3Almt |
280
|
|
|
|
|
|
|
or via email at bug-datetime-timezone-lmt@rt.cpan.org. |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 AUTHOR |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
Rick Measham with parts taken from DateTime::TimeZone |
285
|
|
|
|
|
|
|
by Dave Rolsky . |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 COPYRIGHT |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Copyright (C) 2003 Rick Measham. All rights reserved. This program |
290
|
|
|
|
|
|
|
is free software; you can redistribute it and/or modify it under the |
291
|
|
|
|
|
|
|
same terms as Perl itself. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
The full text of the license can be found in the LICENSE file included |
294
|
|
|
|
|
|
|
with this module. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=head1 SEE ALSO |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
datetime@perl.org mailing list |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
http://datetime.perl.org/ |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=cut |