DateTime-TimeZone

 view release on metacpan or  search on metacpan

lib/DateTime/TimeZone.pm  view on Meta::CPAN

DateTime::TimeZone - Time zone object base class and factory

=head1 VERSION

version 2.68

=head1 SYNOPSIS

  use DateTime;
  use DateTime::TimeZone;

  my $tz = DateTime::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 L<DateTime> module, this module does not do much.  It's
primary interface is through a L<DateTime> object, and most users will not need
to directly use C<DateTime::TimeZone> methods.

=head2 Special Case Platforms

If you are on the Win32 platform, you will want to also install
L<DateTime::TimeZone::Local::Win32>. This will enable you to specify a time
zone of C<'local'> when creating a L<DateTime> object.

If you are on HPUX, install L<DateTime::TimeZone::HPUX>. This provides support
for HPUX style time zones like C<'MET-1METDST'>.

=head1 USAGE

This class has the following methods:

=head2 DateTime::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
DateTime::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
DateTime::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<DateTime::TimeZone::Floating>
object is returned.  A floating time zone does not 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 L<RFC
2445|https://www.ietf.org/rfc/rfc2445.txt> for more details.

If the "name" parameter is "UTC", then a C<DateTime::TimeZone::UTC> object is
returned.

If the "name" is an offset string, it is converted to a number, and a
C<DateTime::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<DateTime::TimeZone::Local::Unix>

=item * L<DateTime::TimeZone::Local::Android>

=item * L<DateTime::TimeZone::Local::hpux>

=item * L<DateTime::TimeZone::Local::Win32>

=item * L<DateTime::TimeZone::Local::VMS>

=back

If a local time zone is not found, then an exception will be thrown. This
exception will always stringify to something containing the text C<"Cannot
determine local time zone">.

If you are writing code for users to run on systems you do not control, you
should try to account for the possibility that this exception may be thrown.
Falling back to UTC might be a reasonable alternative.

When writing tests for your modules that might be run on others' systems, you
are strongly encouraged to either not use C<local> when creating L<DateTime>
objects or to set C<$ENV{TZ}> to a known value in your test code. All of the
per-OS classes check this environment variable.

=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.



( run in 0.484 second using v1.01-cache-2.11-cpan-39bf76dae61 )