1DateTime::TimeZone(3) User Contributed Perl DocumentationDateTime::TimeZone(3)
2
3
4

NAME

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

VERSION

9       version 1.42
10

SYNOPSIS

12         use DateTime;
13         use DateTime::TimeZone;
14
15         my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );
16
17         my $dt = DateTime->now();
18         my $offset = $tz->offset_for_datetime($dt);
19

DESCRIPTION

21       This class is the base class for all time zone objects.  A time zone is
22       represented internally as a set of observances, each of which describes
23       the offset from GMT for a given time period.
24
25       Note that without the "DateTime.pm" module, this module does not do
26       much.  It's primary interface is through a "DateTime" object, and most
27       users will not need to directly use "DateTime::TimeZone" methods.
28

USAGE

30       This class has the following methods:
31
32   DateTime::TimeZone->new( name => $tz_name )
33       Given a valid time zone name, this method returns a new time zone
34       blessed into the appropriate subclass.  Subclasses are named for the
35       given time zone, so that the time zone "America/Chicago" is the
36       DateTime::TimeZone::America::Chicago class.
37
38       If the name given is a "link" name in the Olson database, the object
39       created may have a different name.  For example, there is a link from
40       the old "EST5EDT" name to "America/New_York".
41
42       When loading a time zone from the Olson database, the constructor
43       checks the version of the loaded class to make sure it matches the
44       version of the current DateTime::TimeZone installation. If they do not
45       match it will issue a warning. This is useful because time zone names
46       may fall out of use, but you may have an old module file installed for
47       that time zone.
48
49       There are also several special values that can be given as names.
50
51       If the "name" parameter is "floating", then a
52       "DateTime::TimeZone::Floating" object is returned.  A floating time
53       zone does have any offset, and is always the same time.  This is useful
54       for calendaring applications, which may need to specify that a given
55       event happens at the same local time, regardless of where it occurs.
56       See RFC 2445 for more details.
57
58       If the "name" parameter is "UTC", then a "DateTime::TimeZone::UTC"
59       object is returned.
60
61       If the "name" is an offset string, it is converted to a number, and a
62       "DateTime::TimeZone::OffsetOnly" object is returned.
63
64       The "local" time zone
65
66       If the "name" parameter is "local", then the module attempts to
67       determine the local time zone for the system.
68
69       The method for finding the local zone varies by operating system. See
70       the appropriate module for details of how we check for the local time
71       zone.
72
73       ·   DateTime::TimeZone::Local::Unix
74
75       ·   DateTime::TimeZone::Local::Win32
76
77       ·   DateTime::TimeZone::Local::VMS
78
79       If a local time zone is not found, then an exception will be thrown.
80
81   $tz->offset_for_datetime( $dt )
82       Given a "DateTime" object, this method returns the offset in seconds
83       for the given datetime.  This takes into account historical time zone
84       information, as well as Daylight Saving Time.  The offset is determined
85       by looking at the object's UTC Rata Die days and seconds.
86
87   $tz->offset_for_local_datetime( $dt )
88       Given a "DateTime" object, this method returns the offset in seconds
89       for the given datetime.  Unlike the previous method, this method uses
90       the local time's Rata Die days and seconds.  This should only be done
91       when the corresponding UTC time is not yet known, because local times
92       can be ambiguous due to Daylight Saving Time rules.
93
94   $tz->is_dst_for_datetime( $dt )
95       Given a "DateTime" object, this method returns true if the DateTime is
96       currently in Daylight Saving Time.
97
98   $tz->name
99       Returns the name of the time zone.
100
101   $tz->short_name_for_datetime( $dt )
102       Given a "DateTime" object, this method returns the "short name" for the
103       current observance and rule this datetime is in.  These are names like
104       "EST", "GMT", etc.
105
106       It is strongly recommended that you do not rely on these names for
107       anything other than display.  These names are not official, and many of
108       them are simply the invention of the Olson database maintainers.
109       Moreover, these names are not unique.  For example, there is an "EST"
110       at both -0500 and +1000/+1100.
111
112   $tz->is_floating
113       Returns a boolean indicating whether or not this object represents a
114       floating time zone, as defined by RFC 2445.
115
116   $tz->is_utc
117       Indicates whether or not this object represents the UTC (GMT) time
118       zone.
119
120   $tz->has_dst_changes
121       Indicates whether or not this zone has ever had a change to and from
122       DST, either in the past or future.
123
124   $tz->is_olson
125       Returns true if the time zone is a named time zone from the Olson
126       database.
127
128   $tz->category
129       Returns the part of the time zone name before the first slash.  For
130       example, the "America/Chicago" time zone would return "America".
131
132   DateTime::TimeZone->is_valid_name($name)
133       Given a string, this method returns a boolean value indicating whether
134       or not the string is a valid time zone name.  If you are using
135       "DateTime::TimeZone::Alias", any aliases you've created will be valid.
136
137   DateTime::TimeZone->all_names
138       This returns a pre-sorted list of all the time zone names.  This list
139       does not include link names.  In scalar context, it returns an array
140       reference, while in list context it returns an array.
141
142   DateTime::TimeZone->categories
143       This returns a list of all time zone categories.  In scalar context, it
144       returns an array reference, while in list context it returns an array.
145
146   DateTime::TimeZone->links
147       This returns a hash of all time zone links, where the keys are the old,
148       deprecated names, and the values are the new names.  In scalar context,
149       it returns a hash reference, while in list context it returns a hash.
150
151   DateTime::TimeZone->names_in_category( $category )
152       Given a valid category, this method returns a list of the names in that
153       category, without the category portion.  So the list for the "America"
154       category would include the strings "Chicago", "Kentucky/Monticello",
155       and "New_York". In scalar context, it returns an array reference, while
156       in list context it returns an array.
157
158       The list is returned in order of population by zone, which should mean
159       that this order will be the best to use for most UIs.
160
161   DateTime::TimeZone->countries()
162       Returns a sorted list of all the valid country codes (in lower-case)
163       which can be passed to "names_in_country()". In scalar context, it
164       returns an array reference, while in list context it returns an array.
165
166       If you need to convert country codes to names or vice versa you can use
167       "Locale::Country" to do so.
168
169   DateTime::TimeZone->names_in_country( $country_code )
170       Given a two-letter ISO3166 country code, this method returns a list of
171       time zones used in that country. The country code may be of any case.
172       In scalar context, it returns an array reference, while in list context
173       it returns an array.
174
175   DateTime::TimeZone->offset_as_seconds( $offset )
176       Given an offset as a string, this returns the number of seconds
177       represented by the offset as a positive or negative number.  Returns
178       "undef" if $offset is not in the range "-99:59:59" to "+99:59:59".
179
180       The offset is expected to match either
181       "/^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/" or
182       "/^([\+\-])?(\d\d)(\d\d)(\d\d)?$/".  If it doesn't match either of
183       these, "undef" will be returned.
184
185       This means that if you want to specify hours as a single digit, then
186       each element of the offset must be separated by a colon (:).
187
188   DateTime::TimeZone->offset_as_string( $offset )
189       Given an offset as a number, this returns the offset as a string.
190       Returns "undef" if $offset is not in the range "-359999" to 359999.
191
192   Storable Hooks
193       This module provides freeze and thaw hooks for "Storable" so that the
194       huge data structures for Olson time zones are not actually stored in
195       the serialized structure.
196
197       If you subclass "DateTime::TimeZone", you will inherit its hooks, which
198       may not work for your module, so please test the interaction of your
199       module with Storable.
200

SUPPORT

202       Support for this module is provided via the datetime@perl.org email
203       list. See http://datetime.perl.org/wiki/datetime/page/Mailing_List for
204       details.
205
206       Please submit bugs to the CPAN RT system at
207       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=datetime%3A%3Atimezone
208       or via email at bug-datetime-timezone@rt.cpan.org.
209

DONATIONS

211       If you'd like to thank me for the work I've done on this module, please
212       consider making a "donation" to me via PayPal. I spend a lot of free
213       time creating free software, and would appreciate any support you'd
214       care to offer.
215
216       Please note that I am not suggesting that you must do this in order for
217       me to continue working on this particular software. I will continue to
218       do so, inasmuch as I have in the past, for as long as it interests me.
219
220       Similarly, a donation made in this way will probably not make me work
221       on this software much more, unless I get so many donations that I can
222       consider working on free software full time, which seems unlikely at
223       best.
224
225       To donate, log into PayPal and send money to autarch@urth.org or use
226       the button on this page: http://www.urth.org/~autarch/fs-donation.html
227       <http://www.urth.org/~autarch/fs-donation.html>
228

CREDITS

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

SEE ALSO

235       datetime@perl.org mailing list
236
237       http://datetime.perl.org/
238
239       The tools directory of the DateTime::TimeZone distribution includes two
240       scripts that may be of interest to some people.  They are parse_olson
241       and tests_from_zdump.  Please run them with the --help flag to see what
242       they can be used for.
243

AUTHOR

245       Dave Rolsky <autarch@urth.org>
246
248       This software is copyright (c) 2011 by Dave Rolsky.
249
250       This is free software; you can redistribute it and/or modify it under
251       the same terms as the Perl 5 programming language system itself.
252
253
254
255perl v5.12.4                      2011-11-07             DateTime::TimeZone(3)
Impressum