info > DateTime::TimeZone

πŸ—‚οΈ NAME

DateTime::TimeZone β€” Time zone object base class and factory

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ“¦ Create a time zone objectDateTime::TimeZone->new( name => 'America/Chicago' )Returns a new time zone object for the given Olson name
⏱️ Get offset for a datetime$tz->offset_for_datetime($dt)Returns UTC offset in seconds (including DST)
🌐 Get all time zone namesDateTime::TimeZone->all_names()Returns list of all Olson time zone names
🏷️ Get short name (EST, GMT)$tz->short_name_for_datetime($dt)Returns display abbreviation like "EST"
πŸ” Check if a name is validDateTime::TimeZone->is_valid_name($name)Returns boolean validity of time zone name
πŸ“‚ List zones in a countryDateTime::TimeZone->names_in_country('us')Returns zones for a two-letter ISO country code
🏠 Determine local time zoneDateTime::TimeZone->new( name => 'local' )Attempts to auto-detect system's local time zone

πŸ“œ VERSION

version 2.51

πŸ“ 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);

πŸ“– 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 DateTime module, this module does not do much. Its primary interface is through a DateTime object, and most users will not need to directly use DateTime::TimeZone methods.

πŸ–₯️ Special Case Platforms

βš™οΈ USAGE

This class has the following methods:

πŸ†• DateTime::TimeZone->new( name => $tz_name )

Given a valid time zone name, 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 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 from the Olson database, the constructor checks the version of the loaded class against the current DateTime::TimeZone installation. If they do not match it will issue a warning.

Special name values:

If a local time zone is not found, an exception is thrown (stringifies to "Cannot determine local time zone"). Falling back to UTC is a reasonable alternative. When writing tests, avoid using local or set $ENV{TZ} to a known value.

⏱️ $tz->offset_for_datetime( $dt )

Given a DateTime object, returns the offset in seconds for the given datetime. Takes into account historical time zone information and DST. The offset is determined by looking at the object's UTC Rata Die days and seconds.

⏱️ $tz->offset_for_local_datetime( $dt )

Given a DateTime object, returns the offset in seconds using the local time's Rata Die days and seconds. Should only be used when the corresponding UTC time is not yet known, because local times can be ambiguous due to DST.

🌞 $tz->is_dst_for_datetime( $dt )

Returns true if the DateTime is currently in Daylight Saving Time.

🏷️ $tz->name

Returns the name of the time zone.

🏷️ $tz->short_name_for_datetime( $dt )

Returns the "short name" for the current observance and rule (e.g., "EST", "GMT"). Warning: Do not rely on these names for anything other than display. They are not official, and many are inventions of the Olson database maintainers. Names are not unique (e.g., "EST" exists at both -0500 and +1000/+1100).

πŸͺΆ $tz->is_floating

Returns a boolean indicating whether this object represents a floating time zone (RFC 2445).

🌍 $tz->is_utc

Indicates whether this object represents the UTC (GMT) time zone.

πŸ”„ $tz->has_dst_changes

Indicates whether this zone has ever had a change to and from DST, either in the past or future.

πŸ—ΊοΈ $tz->is_olson

Returns true if the time zone is a named time zone from the Olson database.

πŸ“‚ $tz->category

Returns the part of the time zone name before the first slash (e.g., "America" for "America/Chicago").

βœ… DateTime::TimeZone->is_valid_name($name)

Given a string, returns a boolean indicating whether the string is a valid time zone name (including aliases if using DateTime::TimeZone::Alias).

πŸ“‹ DateTime::TimeZone->all_names

Returns a pre-sorted list of all time zone names (excluding link names). In scalar context returns an array reference, in list context returns an array.

πŸ“‚ DateTime::TimeZone->categories

Returns a list of all time zone categories. In scalar context returns an array reference, in list context returns an array.

πŸ”— DateTime::TimeZone->links

Returns a hash of all time zone links, where keys are old deprecated names and values are new names. In scalar context returns a hash reference, in list context returns a hash.

πŸ—‚οΈ DateTime::TimeZone->names_in_category( $category )

Given a valid category, returns a list of names in that category, without the category portion. For example, "America" category returns "Chicago", "Kentucky/Monticello", "New_York". In scalar context returns an array reference, in list context returns an array.

🌐 DateTime::TimeZone->countries()

Returns a sorted list of all valid country codes (lower-case) that can be passed to names_in_country(). Note: "uk" is an alias for "gb" and is not a valid ISO country code. Use Locale::Country for code-to-name conversion.

🌍 DateTime::TimeZone->names_in_country( $country_code )

Given a two-letter ISO3166 country code (any case), returns a list of time zones used in that country. The list is ordered vaguely based on geography and population. In scalar context returns an array reference, in list context returns an array.

πŸ”’ DateTime::TimeZone->offset_as_seconds( $offset )

Given an offset as a string, returns the number of seconds represented. Returns undef if $offset is not in range "-99:59:59" to "+99:59:59". The offset is expected to match either /^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/ or /^([\+\-])?(\d\d)(\d\d)(\d\d)?$/. If you want to specify hours as a single digit, each element must be separated by a colon.

πŸ”€ DateTime::TimeZone->offset_as_string( $offset, $sep )

Given an offset as a number, returns the offset as a string. Returns undef if $offset is not in range "-359999" to 359999. An optional separator can be provided between the hours, minutes, and seconds portions.

πŸ’Ύ Storable Hooks

This module provides freeze and thaw hooks for Storable so that the huge data structures for Olson time zones are not actually stored in the serialized structure. If you subclass DateTime::TimeZone, you will inherit its hooks, so test the interaction with Storable.

πŸ”„ LOADING TIME ZONES IN A PRE-FORKING SYSTEM

If you are running an application that does pre-forking (e.g., with Starman), try to load all the time zones you'll need in the parent process. Time zones are loaded on-demand, so loading them once in each child will waste memory that could otherwise be shared.

πŸ† CREDITS

This module was inspired by Jesse Vincent's work on Date::ICal::Timezone, and written with much help from the datetime@perl.org list.

πŸ“š SEE ALSO

datetime@perl.org mailing list

The tools directory of the DateTime::TimeZone distribution includes two scripts: parse_olson and tests_from_zdump. Run with --help for usage.

πŸ›Ÿ SUPPORT

Support is provided via the datetime@perl.org email list.

Bugs may be submitted at https://github.com/houseabsolute/DateTime-TimeZone/issues.

πŸ“¦ SOURCE

The source code repository for DateTime-TimeZone can be found at https://github.com/houseabsolute/DateTime-TimeZone.

πŸ’ DONATIONS

If you'd like to thank the author, consider making a donation via PayPal. Donations may not directly increase development speed, but are appreciated. Send money to autarch@urth.org or use the button at https://www.urth.org/fs-donation.html.

✍️ AUTHOR

Dave Rolsky <autarch@urth.org>

πŸ™Œ CONTRIBUTORS

πŸ“„ COPYRIGHT AND LICENSE

This software is copyright (c) 2021 by Dave Rolsky.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

The full text of the license can be found in the LICENSE file included with this distribution.

perl v5.32.1 2021-10-22 DateTime::TimeZone(3pm)

DateTime::TimeZone
πŸ—‚οΈ NAME πŸš€ Quick Reference πŸ“œ VERSION πŸ“ SYNOPSIS πŸ“– DESCRIPTION
πŸ–₯️ Special Case Platforms
βš™οΈ USAGE
πŸ†• DateTime::TimeZone->new( name => $tz_name ) ⏱️ $tz->offset_for_datetime( $dt ) ⏱️ $tz->offset_for_local_datetime( $dt ) 🌞 $tz->is_dst_for_datetime( $dt ) 🏷️ $tz->name 🏷️ $tz->short_name_for_datetime( $dt ) πŸͺΆ $tz->is_floating 🌍 $tz->is_utc πŸ”„ $tz->has_dst_changes πŸ—ΊοΈ $tz->is_olson πŸ“‚ $tz->category βœ… DateTime::TimeZone->is_valid_name($name) πŸ“‹ DateTime::TimeZone->all_names πŸ“‚ DateTime::TimeZone->categories πŸ”— DateTime::TimeZone->links πŸ—‚οΈ DateTime::TimeZone->names_in_category( $category ) 🌐 DateTime::TimeZone->countries() 🌍 DateTime::TimeZone->names_in_country( $country_code ) πŸ”’ DateTime::TimeZone->offset_as_seconds( $offset ) πŸ”€ DateTime::TimeZone->offset_as_string( $offset, $sep ) πŸ’Ύ Storable Hooks
πŸ”„ LOADING TIME ZONES IN A PRE-FORKING SYSTEM πŸ† CREDITS πŸ“š SEE ALSO πŸ›Ÿ SUPPORT πŸ“¦ SOURCE πŸ’ DONATIONS ✍️ AUTHOR πŸ™Œ CONTRIBUTORS πŸ“„ COPYRIGHT AND LICENSE

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-25 07:18 @216.73.217.127
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!