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 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<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.
First it checks C<$ENV> for keys named "TZ", "SYS$TIMEZONE_RULE",
"SYS$TIMEZONE_NAME", "UCX$TZ", or "TCPIP$TZC" (the last 4 are for
VMS). If this is defined, and it is not the string "local", then it
is treated as any other valid name (including "floating"), and the
constructor tries to create a time zone based on that name.
Next, it checks for the existence of a symlink at F</etc/localtime>.
It follows this link to the real file and figures out what the file's
name is. It then tries to turn this name into a valid time zone. For
example, if this file is linked to F</usr/share/zoneinfo/US/Central>,
it will end up trying "US/Central", which will then be converted to
"America/Chicago" internally.
Some systems just copy the relevant file to F</etc/localtime> instead
of making a symlink. In this case, we look in F</usr/share/zoneinfo>
for a file that has the same size and content as F</etc/localtime> to
determine the local time zone.
Then it checks for a file called F</etc/timezone> or F</etc/TIMEZONE>.
If one of these exists, it is read and it tries to create a time zone
with the name contained in the file.
Finally, it checks for a file called F</etc/sysconfig/clock>. If this
file exists, it looks for a line inside the file matching
C</^(?:TIME)?ZONE="([^"]+)"/>. If this line exists, it tries the
value as a time zone name.
If none of these methods work, it gives up and dies.
=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"
at both -0500 and +1000/+1100.
=head2 $tz->is_floating
=7= |