1NAME
2 DateTime::TimeZone - Time zone object base class and factory
3
4SYNOPSIS
5 use DateTime;
6 use DateTime::TimeZone;
7
8 my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );
9
10 my $dt = DateTime->now();
11 my $offset = $tz->offset_for_datetime($dt);
12
13DESCRIPTION
14 This class is the base class for all time zone objects. A time zone is
15 represented internally as a set of observances, each of which describes
16 the offset from GMT for a given time period.
17
18 Note that without the `DateTime.pm' module, this module does not do
19 much. It's primary interface is through a `DateTime' object, and most
20 users will not need to directly use `DateTime::TimeZone' methods.
21
22USAGE
23 This class has the following methods:
24
25 DateTime::TimeZone->new( name => $tz_name )
26 Given a valid time zone name, this method returns a new time zone
27 blessed into the appropriate subclass. Subclasses are named for the
28 given time zone, so that the time zone "America/Chicago" is the
29 DateTime::TimeZone::America::Chicago class.
30
31 If the name given is a "link" name in the Olson database, the object
32 created may have a different name. For example, there is a link from the
33 old "EST5EDT" name to "America/New_York".
34
35 When loading a time zone from the Olson database, the constructor checks
36 the version of the loaded class to make sure it matches the version of
37 the current DateTime::TimeZone installation. If they do not match it
38 will issue a warning. This is useful because time zone names may fall
39 out of use, but you may have an old module file installed for that time
40 zone.
41
42 There are also several special values that can be given as names.
43
44 If the "name" parameter is "floating", then a
45 `DateTime::TimeZone::Floating' object is returned. A floating time zone
46 does have *any* offset, and is always the same time. This is useful for
47 calendaring applications, which may need to specify that a given event
48 happens at the same *local* time, regardless of where it occurs. See RFC
49 2445 for more details.
50
51 If the "name" parameter is "UTC", then a `DateTime::TimeZone::UTC'
52 object is returned.
53
54 If the "name" is an offset string, it is converted to a number, and a
55 `DateTime::TimeZone::OffsetOnly' object is returned.
56
57 The "local" time zone
58 If the "name" parameter is "local", then the module attempts to
59 determine the local time zone for the system.
60
61 The method for finding the local zone varies by operating system. See
62 the appropriate module for details of how we check for the local time
63 zone.
64
65 * DateTime::TimeZone::Local::Unix
66 * DateTime::TimeZone::Local::Win32
67 * DateTime::TimeZone::Local::VMS
68
69 If a local time zone is not found, then an exception will be thrown.
70
71 $tz->offset_for_datetime( $dt )
72 Given a `DateTime' object, this method returns the offset in seconds for
73 the given datetime. This takes into account historical time zone
74 information, as well as Daylight Saving Time. The offset is determined
75 by looking at the object's UTC Rata Die days and seconds.
76
77 $tz->offset_for_local_datetime( $dt )
78 Given a `DateTime' object, this method returns the offset in seconds for
79 the given datetime. Unlike the previous method, this method uses the
80 local time's Rata Die days and seconds. This should only be done when
81 the corresponding UTC time is not yet known, because local times can be
82 ambiguous due to Daylight Saving Time rules.
83
84 $tz->name
85 Returns the name of the time zone. If this value is passed to the
86 `new()' method, it is guaranteed to create the same object.
87
88 $tz->short_name_for_datetime( $dt )
89 Given a `DateTime' object, this method returns the "short name" for the
90 current observance and rule this datetime is in. These are names like
91 "EST", "GMT", etc.
92
93 It is strongly recommended that you do not rely on these names for
94 anything other than display. These names are not official, and many of
95 them are simply the invention of the Olson database maintainers.
96 Moreover, these names are not unique. For example, there is an "EST" at
97 both -0500 and +1000/+1100.
98
99 $tz->is_floating
100 Returns a boolean indicating whether or not this object represents a
101 floating time zone, as defined by RFC 2445.
102
103 $tz->is_utc
104 Indicates whether or not this object represents the UTC (GMT) time zone.
105
106 $tz->has_dst_changes
107 Indicates whether or not this zone has *ever* had a change to and from
108 DST, either in the past or future.
109
110 $tz->is_olson
111 Returns true if the time zone is a named time zone from the Olson
112 database.
113
114 $tz->category
115 Returns the part of the time zone name before the first slash. For
116 example, the "America/Chicago" time zone would return "America".
117
118 DateTime::TimeZone->is_valid_name($name)
119 Given a string, this method returns a boolean value indicating whether
120 or not the string is a valid time zone name. If you are using
121 `DateTime::TimeZone::Alias', any aliases you've created will be valid.
122
123 DateTime::TimeZone->all_names
124 This returns a pre-sorted list of all the time zone names. This list
125 does not include link names. In scalar context, it returns an array
126 reference, while in list context it returns an array.
127
128 DateTime::TimeZone->categories
129 This returns a list of all time zone categories. In scalar context, it
130 returns an array reference, while in list context it returns an array.
131
132 DateTime::TimeZone->links
133 This returns a hash of all time zone links, where the keys are the old,
134 deprecated names, and the values are the new names. In scalar context,
135 it returns a hash reference, while in list context it returns a hash.
136
137 DateTime::TimeZone->names_in_category( $category )
138 Given a valid category, this method returns a list of the names in that
139 category, without the category portion. So the list for the "America"
140 category would include the strings "Chicago", "Kentucky/Monticello", and
141 "New_York". In scalar context, it returns an array reference, while in
142 list context it returns an array.
143
144 The list is returned in order of population by zone, which should mean
145 that this order will be the best to use for most UIs.
146
147 DateTime::TimeZone->countries()
148 Returns a sorted list of all the valid country codes (in lower-case)
149 which can be passed to `names_in_country()'. In scalar context, it
150 returns an array reference, while in list context it returns an array.
151
152 If you need to convert country codes to names or vice versa you can use
153 `Locale::Country' to do so.
154
155 DateTime::TimeZone->names_in_country( $country_code )
156 Given a two-letter ISO3166 country code, this method returns a list of
157 time zones used in that country. The country code may be of any case. In
158 scalar context, it returns an array reference, while in list context it
159 returns an array.
160
161 DateTime::TimeZone->offset_as_seconds( $offset )
162 Given an offset as a string, this returns the number of seconds
163 represented by the offset as a positive or negative number. Returns
164 `undef' if $offset is not in the range `-99:59:59' to `+99:59:59'.
165
166 The offset is expected to match either
167 `/^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/' or
168 `/^([\+\-])?(\d\d)(\d\d)(\d\d)?$/'. If it doesn't match either of these,
169 `undef' will be returned.
170
171 This means that if you want to specify hours as a single digit, then
172 each element of the offset must be separated by a colon (:).
173
174 DateTime::TimeZone->offset_as_string( $offset )
175 Given an offset as a number, this returns the offset as a string.
176 Returns `undef' if $offset is not in the range `-359999' to `359999'.
177
178 Storable Hooks
179 This module provides freeze and thaw hooks for `Storable' so that the
180 huge data structures for Olson time zones are not actually stored in the
181 serialized structure.
182
183 If you subclass `DateTime::TimeZone', you will inherit its hooks, which
184 may not work for your module, so please test the interaction of your
185 module with Storable.
186
187SUPPORT
188 Support for this module is provided via the datetime@perl.org email
189 list. See http://datetime.perl.org/?MailingList for details.
190
191 Please submit bugs to the CPAN RT system at
192 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=datetime%3A%3Atimezone or
193 via email at bug-datetime-timezone@rt.cpan.org.
194
195DONATIONS
196 If you'd like to thank me for the work I've done on this module, please
197 consider making a "donation" to me via PayPal. I spend a lot of free
198 time creating free software, and would appreciate any support you'd care
199 to offer.
200
201 Please note that I am not suggesting that you must do this in order for
202 me to continue working on this particular software. I will continue to
203 do so, inasmuch as I have in the past, for as long as it interests me.
204
205 Similarly, a donation made in this way will probably not make me work on
206 this software much more, unless I get so many donations that I can
207 consider working on free software full time, which seems unlikely at
208 best.
209
210 To donate, log into PayPal and send money to autarch@urth.org or use the
211 button on this page: http://www.urth.org/~autarch/fs-donation.html
212
213AUTHOR
214 Dave Rolsky <autarch@urth.org>
215
216CREDITS
217 This module was inspired by Jesse Vincent's work on
218 Date::ICal::Timezone, and written with much help from the
219 datetime@perl.org list.
220
221COPYRIGHT
222 Copyright (c) 2003-2008 David Rolsky. All rights reserved. This program
223 is free software; you can redistribute it and/or modify it under the
224 same terms as Perl itself.
225
226 The full text of the license can be found in the LICENSE file included
227 with this module.
228
229SEE ALSO
230 datetime@perl.org mailing list
231
232 http://datetime.perl.org/
233
234 The tools directory of the DateTime::TimeZone distribution includes two
235 scripts that may be of interest to some people. They are parse_olson and
236 tests_from_zdump. Please run them with the --help flag to see what they
237 can be used for.
238
239