NAME
DateTime::TimeZone - Time zone object base class and factory
SYNOPSIS
use DateTime::TimeZone
my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );
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.
USAGE
This class has the following methods:
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".
There are also several special values that can be given as names.
If the "name" parameter is "floating", then a
DateTime::TimeZone::Floating
object is returned. A floating time zone does have 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 local time, regardless of where it occurs. See RFC 2445 for more details.If the "name" parameter is "UTC", then a
DateTime::TimeZone::UTC
object is returned.If the "name" is an offset string, it is converted to a number, and a
DateTime::TimeZone::OffsetOnly
object is returned.
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 $ENV{TZ}
. 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 /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 /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 /etc/localtime instead of making a symlink. Unfortunately, these files don't contain their own name! This means that there is no way to look at a copy and figure out what time zone it represents.
Then it checks for a file called /etc/timezone. If this 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 /etc/sysconfig/clock. If this file exists, it looks for a line inside the file matching /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.
Object Methods
DateTime::TimeZone
objects provide the following methods:
offset_for_datetime( $datetime )
Given an object which implements the DateTime.pm API, 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.
offset_for_local_datetime( $datetime )
Given an object which implements the DateTime.pm API, 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.
name
Returns the name of the time zone. If this value is passed to the
new()
method, it is guaranteed to create the same object.short_name_for_datetime( $datetime )
Given an object which implements the DateTime.pm API, 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 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.
is_floating
Returns a boolean indicating whether or not this object represents a floating time zone, as defined by RFC 2445.
is_utc
Indicates whether or not this object represents the UTC (GMT) time zone.
is_olson
Returns true if the time zone is a named time zone from the Olson database.
category
Returns the part of the time zone name before the first slash. For example, the "America/Chicago" time zone would return "America".
Functions
This class also contains several functions, none of which are exported.
all_names
This returns a pre-sorted list of all the time zone names. This list does not include link names. In scalar context, it returns an array reference, while in list context it returns an array.
categories
This returns a list of all time zone categories. In scalar context, it returns an array reference, while in list context it returns an array.
links
This returns a hash of all time zone links, where the keys are the old, deprecated names, and the values are the new names. In scalar context, it returns a hash reference, while in list context it returns a hash.
names_in_category( $category )
Given a valid category, this method returns a list of the names in that category, without the category portion. So the list for the "America" category would include the strings "Chicago", "Kentucky/Monticello", and "New_York". In scalar context, it returns an array reference, while in list context it returns an array.
offset_as_seconds( $offset )
Given an offset as a string, this returns the number of seconds represented by the offset as a positive or negative number.
offset_as_string( $offset )
Given an offset as a number, this returns the offset as a string.
SUPPORT
Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details.
Please submit bugs to the CPAN RT system at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=datetime%3A%3Atimezone or via email at bug-datetime-timezone@rt.cpan.org.
AUTHOR
Dave Rolsky <autarch@urth.org>, inspired by Jesse Vincent's work on Date::ICal::Timezone, and with help from the datetime@perl.org list.
COPYRIGHT
Copyright (c) 2003 David Rolsky. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
SEE ALSO
datetime@perl.org mailing list
http://datetime.perl.org/
The tools directory of the DateTime::TimeZone distribution includes two scripts that may be of interest to some people. They are parse_olson and tests_from_zdump. Please run them with the --help flag to see what they can be used for.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 437:
You forgot a '=back' before '=head3'
- Around line 470:
=back without =over