DateTimeX-Lite
view release on metacpan or search on metacpan
lib/DateTimeX/Lite/TimeZone.pm view on Meta::CPAN
? @{ $DateTimeX::Lite::TimeZone::Catalog::ZONES_BY_COUNTRY{ lc $_[0] } }
: $DateTimeX::Lite::TimeZone::Catalog::ZONES_BY_COUNTRY{ lc $_[0] };
}
1;
__END__
=head1 NAME
DateTimeX::Lite::TimeZone - Time zone object base class and factory
=head1 SYNOPSIS
use DateTimeX::Lite;
use DateTimeX::Lite::TimeZone;
my $tz = DateTimeX::Lite::TimeZone->new( name => 'America/Chicago' );
my $dt = DateTime->now();
my $offset = $tz->offset_for_datetime($dt);
=head1 DESCRIPTION
This class is the base class for all time zone objects. A time zone
is represented internally as a set of observances, each of which
describes the offset from GMT for a given time period.
Note that without the C<DateTime.pm> module, this module does not do
much. It's primary interface is through a C<DateTime> object, and
most users will not need to directly use C<DateTimeX::Lite::TimeZone>
methods.
=head1 USAGE
This class has the following methods:
=head2 DateTimeX::Lite::TimeZone->new( name => $tz_name )
Given a valid time zone name, this method returns a new time zone
blessed into the appropriate subclass. Subclasses are named for the
given time zone, so that the time zone "America/Chicago" is the
DateTimeX::Lite::TimeZone::America::Chicago class.
If the name given is a "link" name in the Olson database, the object
created may have a different name. For example, there is a link from
the old "EST5EDT" name to "America/New_York".
When loading a time zone from the Olson database, the constructor
checks the version of the loaded class to make sure it matches the
version of the current DateTimeX::Lite::TimeZone installation. If they do not
match it will issue a warning. This is useful because time zone names
may fall out of use, but you may have an old module file installed for
that time zone.
There are also several special values that can be given as names.
If the "name" parameter is "floating", then a
C<DateTimeX::Lite::TimeZone::Floating> object is returned. A floating time
zone does have I<any> offset, and is always the same time. This is
useful for calendaring applications, which may need to specify that a
given event happens at the same I<local> time, regardless of where it
occurs. See RFC 2445 for more details.
If the "name" parameter is "UTC", then a C<DateTimeX::Lite::TimeZone::UTC>
object is returned.
If the "name" is an offset string, it is converted to a number, and a
C<DateTimeX::Lite::TimeZone::OffsetOnly> object is returned.
=head3 The "local" time zone
If the "name" parameter is "local", then the module attempts to
determine the local time zone for the system.
The method for finding the local zone varies by operating system. See
the appropriate module for details of how we check for the local time
zone.
=over 4
=item * L<DateTimeX::Lite::TimeZone::Local::Unix>
=item * L<DateTimeX::Lite::TimeZone::Local::Win32>
=item * L<DateTimeX::Lite::TimeZone::Local::VMS>
=back
If a local time zone is not found, then an exception will be thrown.
=head2 $tz->offset_for_datetime( $dt )
Given a C<DateTime> object, this method returns the offset in seconds
for the given datetime. This takes into account historical time zone
information, as well as Daylight Saving Time. The offset is
determined by looking at the object's UTC Rata Die days and seconds.
=head2 $tz->offset_for_local_datetime( $dt )
Given a C<DateTime> object, this method returns the offset in seconds
for the given datetime. Unlike the previous method, this method uses
the local time's Rata Die days and seconds. This should only be done
when the corresponding UTC time is not yet known, because local times
can be ambiguous due to Daylight Saving Time rules.
=head2 $tz->name
Returns the name of the time zone. If this value is passed to the
C<new()> method, it is guaranteed to create the same object.
=head2 $tz->short_name_for_datetime( $dt )
Given a C<DateTime> object, this method returns the "short name" for
the current observance and rule this datetime is in. These are names
like "EST", "GMT", etc.
It is B<strongly> recommended that you do not rely on these names for
anything other than display. These names are not official, and many
of them are simply the invention of the Olson database maintainers.
Moreover, these names are not unique. For example, there is an "EST"
( run in 2.128 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )