• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

dev-bin/H22-Oct-2021-2013

git/H22-Oct-2021-4429

inc/H22-Oct-2021-7451

lib/DateTime/H22-Oct-2021-258,521246,738

t/H22-Oct-2021-2,5842,066

tools/H22-Oct-2021-1,145818

xt/H22-Oct-2021-1,9531,872

CODE_OF_CONDUCT.mdH A D22-Oct-20213.2 KiB7656

CONTRIBUTING.mdH A D22-Oct-20214.3 KiB11679

ChangesH A D22-Oct-202156.3 KiB2,0201,132

INSTALLH A D22-Oct-20212.4 KiB7648

LICENSEH A D22-Oct-202117.9 KiB380292

MANIFESTH A D22-Oct-202115.7 KiB426425

META.jsonH A D22-Oct-202195.5 KiB2,7522,750

META.ymlH A D22-Oct-202166.8 KiB2,0842,083

Makefile.PLH A D22-Oct-20212.7 KiB11097

README.mdH A D22-Oct-202112.8 KiB336233

azure-pipelines.ymlH A D22-Oct-2021669 3024

cpanfileH A D22-Oct-20212.7 KiB8781

dist.iniH A D22-Oct-20211.8 KiB6659

perlcriticrcH A D22-Oct-20212.1 KiB7552

perltidyrcH A D22-Oct-2021301 2322

precious.tomlH A D22-Oct-20211.8 KiB6760

README.md

1# NAME
2
3DateTime::TimeZone - Time zone object base class and factory
4
5# VERSION
6
7version 2.51
8
9# SYNOPSIS
10
11    use DateTime;
12    use DateTime::TimeZone;
13
14    my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );
15
16    my $dt = DateTime->now();
17    my $offset = $tz->offset_for_datetime($dt);
18
19# DESCRIPTION
20
21This class is the base class for all time zone objects.  A time zone
22is represented internally as a set of observances, each of which
23describes the offset from GMT for a given time period.
24
25Note that without the [DateTime](https://metacpan.org/pod/DateTime) module, this module does not do
26much.  It's primary interface is through a [DateTime](https://metacpan.org/pod/DateTime) object, and
27most users will not need to directly use `DateTime::TimeZone`
28methods.
29
30## Special Case Platforms
31
32If you are on the Win32 platform, you will want to also install
33[DateTime::TimeZone::Local::Win32](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3ALocal%3A%3AWin32). This will enable you to specify a time
34zone of `'local'` when creating a [DateTime](https://metacpan.org/pod/DateTime) object.
35
36If you are on HPUX, install [DateTime::TimeZone::HPUX](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3AHPUX). This provides support
37for HPUX style time zones like `'MET-1METDST'`.
38
39# USAGE
40
41This class has the following methods:
42
43## DateTime::TimeZone->new( name => $tz\_name )
44
45Given a valid time zone name, this method returns a new time zone
46blessed into the appropriate subclass.  Subclasses are named for the
47given time zone, so that the time zone "America/Chicago" is the
48DateTime::TimeZone::America::Chicago class.
49
50If the name given is a "link" name in the Olson database, the object
51created may have a different name.  For example, there is a link from
52the old "EST5EDT" name to "America/New\_York".
53
54When loading a time zone from the Olson database, the constructor
55checks the version of the loaded class to make sure it matches the
56version of the current DateTime::TimeZone installation. If they do not
57match it will issue a warning. This is useful because time zone names
58may fall out of use, but you may have an old module file installed for
59that time zone.
60
61There are also several special values that can be given as names.
62
63If the "name" parameter is "floating", then a `DateTime::TimeZone::Floating`
64object is returned.  A floating time zone does not have _any_ offset, and is
65always the same time.  This is useful for calendaring applications, which may
66need to specify that a given event happens at the same _local_ time,
67regardless of where it occurs. See [RFC
682445](https://www.ietf.org/rfc/rfc2445.txt) for more details.
69
70If the "name" parameter is "UTC", then a `DateTime::TimeZone::UTC`
71object is returned.
72
73If the "name" is an offset string, it is converted to a number, and a
74`DateTime::TimeZone::OffsetOnly` object is returned.
75
76### The "local" time zone
77
78If the "name" parameter is "local", then the module attempts to
79determine the local time zone for the system.
80
81The method for finding the local zone varies by operating system. See
82the appropriate module for details of how we check for the local time
83zone.
84
85- [DateTime::TimeZone::Local::Unix](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3ALocal%3A%3AUnix)
86- [DateTime::TimeZone::Local::Android](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3ALocal%3A%3AAndroid)
87- [DateTime::TimeZone::Local::hpux](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3ALocal%3A%3Ahpux)
88- [DateTime::TimeZone::Local::Win32](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3ALocal%3A%3AWin32)
89- [DateTime::TimeZone::Local::VMS](https://metacpan.org/pod/DateTime%3A%3ATimeZone%3A%3ALocal%3A%3AVMS)
90
91If a local time zone is not found, then an exception will be thrown. This
92exception will always stringify to something containing the text `"Cannot
93determine local time zone"`.
94
95If you are writing code for users to run on systems you do not control, you
96should try to account for the possibility that this exception may be
97thrown. Falling back to UTC might be a reasonable alternative.
98
99When writing tests for your modules that might be run on others' systems, you
100are strongly encouraged to either not use `local` when creating [DateTime](https://metacpan.org/pod/DateTime)
101objects or to set `$ENV{TZ}` to a known value in your test code. All of the
102per-OS classes check this environment variable.
103
104## $tz->offset\_for\_datetime( $dt )
105
106Given a `DateTime` object, this method returns the offset in seconds
107for the given datetime.  This takes into account historical time zone
108information, as well as Daylight Saving Time.  The offset is
109determined by looking at the object's UTC Rata Die days and seconds.
110
111## $tz->offset\_for\_local\_datetime( $dt )
112
113Given a `DateTime` object, this method returns the offset in seconds
114for the given datetime.  Unlike the previous method, this method uses
115the local time's Rata Die days and seconds.  This should only be done
116when the corresponding UTC time is not yet known, because local times
117can be ambiguous due to Daylight Saving Time rules.
118
119## $tz->is\_dst\_for\_datetime( $dt )
120
121Given a `DateTime` object, this method returns true if the DateTime is
122currently in Daylight Saving Time.
123
124## $tz->name
125
126Returns the name of the time zone.
127
128## $tz->short\_name\_for\_datetime( $dt )
129
130Given a `DateTime` object, this method returns the "short name" for
131the current observance and rule this datetime is in.  These are names
132like "EST", "GMT", etc.
133
134It is **strongly** recommended that you do not rely on these names for
135anything other than display.  These names are not official, and many
136of them are simply the invention of the Olson database maintainers.
137Moreover, these names are not unique.  For example, there is an "EST"
138at both -0500 and +1000/+1100.
139
140## $tz->is\_floating
141
142Returns a boolean indicating whether or not this object represents a floating
143time zone, as defined by [RFC 2445](https://www.ietf.org/rfc/rfc2445.txt).
144
145## $tz->is\_utc
146
147Indicates whether or not this object represents the UTC (GMT) time
148zone.
149
150## $tz->has\_dst\_changes
151
152Indicates whether or not this zone has _ever_ had a change to and
153from DST, either in the past or future.
154
155## $tz->is\_olson
156
157Returns true if the time zone is a named time zone from the Olson
158database.
159
160## $tz->category
161
162Returns the part of the time zone name before the first slash.  For
163example, the "America/Chicago" time zone would return "America".
164
165## DateTime::TimeZone->is\_valid\_name($name)
166
167Given a string, this method returns a boolean value indicating whether
168or not the string is a valid time zone name.  If you are using
169`DateTime::TimeZone::Alias`, any aliases you've created will be valid.
170
171## DateTime::TimeZone->all\_names
172
173This returns a pre-sorted list of all the time zone names.  This list
174does not include link names.  In scalar context, it returns an array
175reference, while in list context it returns an array.
176
177## DateTime::TimeZone->categories
178
179This returns a list of all time zone categories.  In scalar context,
180it returns an array reference, while in list context it returns an
181array.
182
183## DateTime::TimeZone->links
184
185This returns a hash of all time zone links, where the keys are the
186old, deprecated names, and the values are the new names.  In scalar
187context, it returns a hash reference, while in list context it returns
188a hash.
189
190## DateTime::TimeZone->names\_in\_category( $category )
191
192Given a valid category, this method returns a list of the names in
193that category, without the category portion.  So the list for the
194"America" category would include the strings "Chicago",
195"Kentucky/Monticello", and "New\_York". In scalar context, it returns
196an array reference, while in list context it returns an array.
197
198## DateTime::TimeZone->countries()
199
200Returns a sorted list of all the valid country codes (in lower-case)
201which can be passed to `names_in_country()`. In scalar context, it
202returns an array reference, while in list context it returns an array.
203
204If you need to convert country codes to names or vice versa you can use
205`Locale::Country` to do so. Note that one of the codes returned is "uk",
206which is an alias for the country code "gb", and is not a valid ISO country
207code.
208
209## DateTime::TimeZone->names\_in\_country( $country\_code )
210
211Given a two-letter ISO3166 country code, this method returns a list of
212time zones used in that country. The country code may be of any
213case. In scalar context, it returns an array reference, while in list
214context it returns an array.
215
216This list is returned in an order vaguely based on geography and
217population. In general, the least used zones come last, but there are not
218guarantees of a specific order from one release to the next. This order is
219probably the best option for presenting zones names to end users.
220
221## DateTime::TimeZone->offset\_as\_seconds( $offset )
222
223Given an offset as a string, this returns the number of seconds
224represented by the offset as a positive or negative number.  Returns
225`undef` if $offset is not in the range `-99:59:59` to `+99:59:59`.
226
227The offset is expected to match either
228`/^([\+\-])?(\d\d?):(\d\d)(?::(\d\d))?$/` or
229`/^([\+\-])?(\d\d)(\d\d)(\d\d)?$/`.  If it doesn't match either of
230these, `undef` will be returned.
231
232This means that if you want to specify hours as a single digit, then
233each element of the offset must be separated by a colon (:).
234
235## DateTime::TimeZone->offset\_as\_string( $offset, $sep )
236
237Given an offset as a number, this returns the offset as a string.
238Returns `undef` if $offset is not in the range `-359999` to `359999`.
239
240You can also provide an optional separator which will go between the hours,
241minutes, and seconds (if applicable) portions of the offset.
242
243## Storable Hooks
244
245This module provides freeze and thaw hooks for `Storable` so that the
246huge data structures for Olson time zones are not actually stored in
247the serialized structure.
248
249If you subclass `DateTime::TimeZone`, you will inherit its hooks,
250which may not work for your module, so please test the interaction of
251your module with Storable.
252
253# LOADING TIME ZONES IN A PRE-FORKING SYSTEM
254
255If you are running an application that does pre-forking (for example with
256Starman), then you should try to load all the time zones that you'll need in
257the parent process. Time zones are loaded on-demand, so loading them once in
258each child will waste memory that could otherwise be shared.
259
260# CREDITS
261
262This module was inspired by Jesse Vincent's work on
263Date::ICal::Timezone, and written with much help from the
264datetime@perl.org list.
265
266# SEE ALSO
267
268datetime@perl.org mailing list
269
270The tools directory of the DateTime::TimeZone distribution includes
271two scripts that may be of interest to some people.  They are
272parse\_olson and tests\_from\_zdump.  Please run them with the --help
273flag to see what they can be used for.
274
275# SUPPORT
276
277Support for this module is provided via the datetime@perl.org email list.
278
279Bugs may be submitted at [https://github.com/houseabsolute/DateTime-TimeZone/issues](https://github.com/houseabsolute/DateTime-TimeZone/issues).
280
281# SOURCE
282
283The source code repository for DateTime-TimeZone can be found at [https://github.com/houseabsolute/DateTime-TimeZone](https://github.com/houseabsolute/DateTime-TimeZone).
284
285# DONATIONS
286
287If you'd like to thank me for the work I've done on this module, please
288consider making a "donation" to me via PayPal. I spend a lot of free time
289creating free software, and would appreciate any support you'd care to offer.
290
291Please note that **I am not suggesting that you must do this** in order for me
292to continue working on this particular software. I will continue to do so,
293inasmuch as I have in the past, for as long as it interests me.
294
295Similarly, a donation made in this way will probably not make me work on this
296software much more, unless I get so many donations that I can consider working
297on free software full time (let's all have a chuckle at that together).
298
299To donate, log into PayPal and send money to autarch@urth.org, or use the
300button at [https://www.urth.org/fs-donation.html](https://www.urth.org/fs-donation.html).
301
302# AUTHOR
303
304Dave Rolsky <autarch@urth.org>
305
306# CONTRIBUTORS
307
308- Alexey Molchanov <alexey.molchanov@gmail.com>
309- Alfie John <alfiej@fastmail.fm>
310- Andrew Paprocki <apaprocki@bloomberg.net>
311- Bron Gondwana <brong@fastmail.fm>
312- Daisuke Maki <dmaki@cpan.org>
313- David Pinkowitz <dave@pinkowitz.com>
314- Iain Truskett &lt;deceased>
315- Jakub Wilk <jwilk@jwilk.net>
316- James E Keenan <jkeenan@cpan.org>
317- Joshua Hoblitt <jhoblitt@cpan.org>
318- Karen Etheridge <ether@cpan.org>
319- karupanerura <karupa@cpan.org>
320- kclaggett <kclaggett@proofpoint.com>
321- Matthew Horsfall <wolfsage@gmail.com>
322- Mohammad S Anwar <mohammad.anwar@yahoo.com>
323- Olaf Alders <olaf@wundersolutions.com>
324- Peter Rabbitson <ribasushi@cpan.org>
325- Tom Wyant <wyant@cpan.org>
326
327# COPYRIGHT AND LICENSE
328
329This software is copyright (c) 2021 by Dave Rolsky.
330
331This is free software; you can redistribute it and/or modify it under
332the same terms as the Perl 5 programming language system itself.
333
334The full text of the license can be found in the
335`LICENSE` file included with this distribution.
336