| 1 |
# Copyright (c) 2008-2026 Sullivan Beck. All rights reserved. |
| 2 |
# This program is free software; you can redistribute it and/or modify it |
| 3 |
# under the same terms as Perl itself. |
| 4 |
|
| 5 |
=pod |
| 6 |
|
| 7 |
=head1 NAME |
| 8 |
|
| 9 |
Date::Manip::TZ - an interface to the time zone data |
| 10 |
|
| 11 |
=head1 SYNOPSIS |
| 12 |
|
| 13 |
use Date::Manip::TZ; |
| 14 |
$tz = new Date::Manip::TZ; |
| 15 |
|
| 16 |
Data for most (and hopefully all) time zones used around the world have |
| 17 |
been gathered and is publicly available in the zoneinfo (or Olson) |
| 18 |
database. |
| 19 |
|
| 20 |
This module uses the data from the zoneinfo database to perform various |
| 21 |
time zone operations. |
| 22 |
|
| 23 |
=head1 DESCRIPTION |
| 24 |
|
| 25 |
Every time zone has some of the following characteristics: |
| 26 |
|
| 27 |
=over 4 |
| 28 |
|
| 29 |
=item B<name> |
| 30 |
|
| 31 |
Every time zone has a unique name. In the zoneinfo database, these |
| 32 |
are something similar to: |
| 33 |
|
| 34 |
America/New_York |
| 35 |
|
| 36 |
=item B<aliases> |
| 37 |
|
| 38 |
Time zones may have (but are not required to have) one or more aliases. |
| 39 |
Each alias is unique, and is not the same as any time zone name. An |
| 40 |
alias can be used in exactly the same way as a name. |
| 41 |
|
| 42 |
=item B<periods> |
| 43 |
|
| 44 |
Every time zone is broken up into periods. Each period describes how |
| 45 |
a portion of time relates to GMT, and how it might be expressed. |
| 46 |
|
| 47 |
=back |
| 48 |
|
| 49 |
Each period includes the following information: |
| 50 |
|
| 51 |
=over 4 |
| 52 |
|
| 53 |
=item B<start time, end time> |
| 54 |
|
| 55 |
The period begin and ends at certain times. The times are |
| 56 |
included both as an absolute GMT time, and as a wall clock time. |
| 57 |
The wall clock start time is the time that will be on a clock |
| 58 |
just as the period starts (i.e. after a time change). The wall clock |
| 59 |
end time is the time on a clock immediately before the period ends. |
| 60 |
|
| 61 |
=item B<offset> |
| 62 |
|
| 63 |
The entire period has an offset which is how much the wall clock |
| 64 |
time differs from GMT. |
| 65 |
|
| 66 |
=item B<abbreviation> |
| 67 |
|
| 68 |
When expressing the time period, an abbreviation (such as EST) is |
| 69 |
typically used. |
| 70 |
|
| 71 |
=item B<daylight saving time flag> |
| 72 |
|
| 73 |
Every period is categorized as a standard time or a daylight |
| 74 |
saving time. The flag will be 1 if it is a daylight saving time, |
| 75 |
or 0 if it is a standard time. |
| 76 |
|
| 77 |
=back |
| 78 |
|
| 79 |
Date::Manip includes all of the data for all of the time zones from |
| 80 |
the zoneinfo database. This data is available from: |
| 81 |
|
| 82 |
L<ftp://ftp.iana.org/tz/> |
| 83 |
|
| 84 |
Additional data from other standards are also used. |
| 85 |
|
| 86 |
The zoneinfo database is not necessary in order to use Date::Manip. |
| 87 |
Instead, all of that data has been extracted and stored in a |
| 88 |
series of other modules which are used to handle each time zone. |
| 89 |
In that way, Date::Manip has no dependency on any other source |
| 90 |
of data. |
| 91 |
|
| 92 |
The L<Date::Manip::Zones> document contains detailed information |
| 93 |
on the data available. |
| 94 |
|
| 95 |
=head1 METHODS |
| 96 |
|
| 97 |
In all methods, the following variables are used: |
| 98 |
|
| 99 |
=over 4 |
| 100 |
|
| 101 |
=item B<$zone> |
| 102 |
|
| 103 |
This is a string which contains a valid time zone name. For |
| 104 |
example: |
| 105 |
|
| 106 |
America/New_York |
| 107 |
|
| 108 |
=item B<$alias> |
| 109 |
|
| 110 |
This is a strings which contains a valid time zone name, or a valid |
| 111 |
time zone alias. For example: |
| 112 |
|
| 113 |
America/New_York |
| 114 |
US/Eastern |
| 115 |
EST5EDT |
| 116 |
|
| 117 |
=item B<$abbrev> |
| 118 |
|
| 119 |
This is a string which contains a valid time zone abbreviation. For |
| 120 |
example: |
| 121 |
|
| 122 |
EST |
| 123 |
|
| 124 |
=item B<$offset> |
| 125 |
|
| 126 |
This is a time zone entered as an offset. An offset is either a string |
| 127 |
of one of the formats: |
| 128 |
|
| 129 |
+HH |
| 130 |
+HHMM |
| 131 |
+HHMMSS |
| 132 |
+HH:MM |
| 133 |
+HH:MM:SS |
| 134 |
|
| 135 |
or it can be a list reference: |
| 136 |
|
| 137 |
[HH,MM,SS] |
| 138 |
|
| 139 |
If a list reference is used, the sign must be included with all values. |
| 140 |
So, the offset "-05:30" would be the list reference: |
| 141 |
|
| 142 |
[-5,-30,0] |
| 143 |
|
| 144 |
=item B<$dstflag> |
| 145 |
|
| 146 |
This is always one of the values: std, stdonly, dst, dstonly |
| 147 |
|
| 148 |
It defaults to "std" if it is not present. When determining a time zone, |
| 149 |
it is usually necessary to check a number of different time zone and |
| 150 |
DST combinations. |
| 151 |
|
| 152 |
If C<$dstflag> is "std", it will check both standard and daylight saving |
| 153 |
times, but will give preference to standard times. If C<$dstflag> is |
| 154 |
"stdonly", only standard times will be checked. |
| 155 |
|
| 156 |
The "dst" flag will search both, but give preference to daylight saving |
| 157 |
times. The "dstonly" values will only use daylight saving times. |
| 158 |
|
| 159 |
=item B<$date> |
| 160 |
|
| 161 |
A date is always a string containing a date in one of the formats: |
| 162 |
|
| 163 |
YYYYMMDDHH:MN:SS |
| 164 |
YYYY-MM-DD-HH:MN:SS |
| 165 |
YYYYMMDDHHMNSS |
| 166 |
|
| 167 |
or a list reference: |
| 168 |
|
| 169 |
[Y,M,D,H,MN,S] |
| 170 |
|
| 171 |
=item B<$isdst> |
| 172 |
|
| 173 |
This is 0 if a date is in standard time, 1 if it is in daylight saving |
| 174 |
time. |
| 175 |
|
| 176 |
=item B<$period> |
| 177 |
|
| 178 |
A period is a list reference currently containing the following |
| 179 |
items: |
| 180 |
|
| 181 |
[ $dateUT, $dateLT, $offsetstr, $offset, $abbrev, $isdst, |
| 182 |
$endUT, $endLT, $begUTs, $begLTs, $endUTs, $endLTs ] |
| 183 |
|
| 184 |
C<$dateUT> and C<$dateLT> are the starting date of the period (i.e. the |
| 185 |
first second in a period) in universal (GMT) time and local |
| 186 |
(wall clock) time. C<$endUT> and C<$endLT> are the end date of the period |
| 187 |
(i.e. the last second in a period) in universal and local time. |
| 188 |
These are all stored as list references. |
| 189 |
|
| 190 |
C<$offsetstr> is the string representation of the offset ("+05:00:00") |
| 191 |
and C<$offset> is the corresponding list reference form ([5,0,0]). |
| 192 |
|
| 193 |
C<$abbrev> is the abbreviation that applies during this period, and C<$isdst> |
| 194 |
is 0 or 1 if it is standard or daylight saving time. |
| 195 |
|
| 196 |
When accessing the elements in a period, use ONLY positive indices. |
| 197 |
In other words, to get C<$endUT>, access it as C<$$period[6]>, NOT as |
| 198 |
C<$$period[-2]>, since I am considering adding more information to the |
| 199 |
period description that may speed up performance. |
| 200 |
|
| 201 |
C<$begUTs> is the string representation (YYYYMMDDHH:MN:SS) of C<$begUT>. |
| 202 |
Similar for C<$begLTs>, C<$endUTs>, and C<$endLTs>. |
| 203 |
|
| 204 |
=back |
| 205 |
|
| 206 |
The following methods are available: |
| 207 |
|
| 208 |
=over 4 |
| 209 |
|
| 210 |
=item B<base> |
| 211 |
|
| 212 |
=item B<config> |
| 213 |
|
| 214 |
=item B<err> |
| 215 |
|
| 216 |
=item B<new> |
| 217 |
|
| 218 |
=item B<new_config> |
| 219 |
|
| 220 |
Please refer to the L<Date::Manip::Obj> documentation for these methods. |
| 221 |
|
| 222 |
=item B<all_periods> |
| 223 |
|
| 224 |
@periods = $tz->all_periods($zone,$year); |
| 225 |
|
| 226 |
This returns the description of all time zone periods that occur (in |
| 227 |
full or in part) during the given year. The year is measured in universal |
| 228 |
(GMT) time. |
| 229 |
|
| 230 |
=item B<convert> |
| 231 |
|
| 232 |
=item B<convert_to_gmt> |
| 233 |
|
| 234 |
=item B<convert_from_gmt> |
| 235 |
|
| 236 |
=item B<convert_to_local> |
| 237 |
|
| 238 |
=item B<convert_from_local> |
| 239 |
|
| 240 |
These functions convert a date from one time zone to another. |
| 241 |
|
| 242 |
($err,$date,$offset,$isdst,$abbrev) = |
| 243 |
$tz->convert($date,$from,$to [,$isdst]); |
| 244 |
|
| 245 |
This converts a date in the time zone given by C<$from> to the time zone |
| 246 |
given by C<$to>. |
| 247 |
|
| 248 |
($err,$date,$offset,$isdst,$abbrev) = |
| 249 |
$tz->convert_to_gmt($date [,$from] [,$isdst]); |
| 250 |
|
| 251 |
This converts a date to GMT. If C<$from> is given, it is the current |
| 252 |
time zone of the date. If C<$from> is omitted, it defaults to the local |
| 253 |
time zone. |
| 254 |
|
| 255 |
The value of C<$isdst> returned is always 0. |
| 256 |
|
| 257 |
($err,$date,$offset,$isdst,$abbrev) = |
| 258 |
$tz->convert_from_gmt($date [,$to]); |
| 259 |
|
| 260 |
This converts a date from GMT to another time zone. If C<$to> is given, |
| 261 |
the date is converted to that time zone. Otherwise, it is converted |
| 262 |
to the local time zone. |
| 263 |
|
| 264 |
($err,$date,$offset,$isdst,$abbrev) = |
| 265 |
$tz->convert_to_local($date [,$from] [,$isdst]); |
| 266 |
($err,$date,$offset,$isdst,$abbrev) = |
| 267 |
$tz->convert_from_local($date [,$to] [,$isdst]); |
| 268 |
|
| 269 |
Similar to the B<convert_to_gmt> and B<convert_from_gmt> functions. If C<$from> |
| 270 |
or C<$to> are omitted, they default to GMT. |
| 271 |
|
| 272 |
If there is any ambiguity about whether C<$date> is in DST or not (i.e. |
| 273 |
if it is a date that is repeated during a time change due to the clock |
| 274 |
being moved back), the C<$isdst> option can be passed in as an argument |
| 275 |
(it should be 0 or 1) to say which time to use. It is ignored in all |
| 276 |
cases where C<$date> can be determined without that information. |
| 277 |
|
| 278 |
The C<$isdst> value passed back is 1 if the converted date is in DST. The |
| 279 |
C<$offset> value passed back is a list reference containing the offset from |
| 280 |
GMT. C<$abbrev> passed back is the time zone abbreviation. |
| 281 |
|
| 282 |
Error codes are: |
| 283 |
|
| 284 |
0 No error |
| 285 |
1 Invalid arguments |
| 286 |
2 Invalid FROM zone |
| 287 |
3 Invalid TO zone |
| 288 |
4 Invalid date |
| 289 |
|
| 290 |
=item B<curr_zone> |
| 291 |
|
| 292 |
$tz->curr_zone(); |
| 293 |
|
| 294 |
This returns the system time zone. The system time zone is determined |
| 295 |
using the methods described below in the |
| 296 |
L</"DETERMINING THE SYSTEM TIME ZONE"> section. |
| 297 |
|
| 298 |
This is the time zone that is used by default unless the SetDate |
| 299 |
or ForceDate config variable is set to a different zone. |
| 300 |
|
| 301 |
$tz->curr_zone(1); |
| 302 |
|
| 303 |
This clears the system time zone and re-determines it using the |
| 304 |
methods described below. |
| 305 |
|
| 306 |
The main reason to do this is if the curr_zone_methods method is |
| 307 |
used to change how the time zone is determined. |
| 308 |
|
| 309 |
=item B<curr_zone_methods> |
| 310 |
|
| 311 |
$tz->curr_zone_methods(@methods); |
| 312 |
|
| 313 |
This sets the list and order of methods to use in determining the |
| 314 |
local time zone. The various methods available are listed below in |
| 315 |
the section L</"DETERMINING THE SYSTEM TIME ZONE">. |
| 316 |
|
| 317 |
Some methods may require one or more arguments. For example, the |
| 318 |
method named "mainvar" takes an option that is the name of a |
| 319 |
variable. The arguments must be included in the @methods list |
| 320 |
immediately after the method name (so @methods is actually a |
| 321 |
mixture of method names and arguments). |
| 322 |
|
| 323 |
This method may not be used in any environment where taint |
| 324 |
checking is enabled. If it is, it will issue a warning, but |
| 325 |
will NOT change the method list. |
| 326 |
|
| 327 |
=item B<date_period> |
| 328 |
|
| 329 |
$period = $tz->date_period($date,$zone,$wall_clock [,$isdst]); |
| 330 |
|
| 331 |
This returns the period information for the given date. $date defaults |
| 332 |
to GMT, but may be given as local (i.e. wall clock) time if $wall_clock |
| 333 |
is non-zero. The period information is described in the periods method |
| 334 |
below. |
| 335 |
|
| 336 |
If a wall clock time is given, no period is returned if the wall clock |
| 337 |
time doesn't ever appear (such as when a time change results in the |
| 338 |
clock moving forward "skipping" a period of time). If the wall clock |
| 339 |
time appears twice (i.e. when a time change results in the clock |
| 340 |
being set back), the $isdst variable is used. The standard time |
| 341 |
is used unless $isdst is non-zero. $isdst is ignored except in the |
| 342 |
case where there are two possible periods. |
| 343 |
|
| 344 |
=item B<define_abbrev> |
| 345 |
|
| 346 |
($err,$val) = $tz->define_abbrev($abbrev,@zone); |
| 347 |
|
| 348 |
When encountering an abbreviation, by default, all time zones which ever |
| 349 |
include the abbreviation will be examine in the order given in the |
| 350 |
Date::Manip::Zones manual. |
| 351 |
|
| 352 |
Occasionally, it may be necessary to change the order. This is |
| 353 |
true if you are parsing dates in a time zone which uses an abbreviation which |
| 354 |
is also used in another time zone, and where the other time zone is given |
| 355 |
preference. As an example, the abbreviation "ADT" will default to the |
| 356 |
"Atlantic/Bermuda" time zone. If you are in the "America/Halifax" time zone |
| 357 |
(which also uses that abbreviation), you may want to change the order |
| 358 |
of time zones. |
| 359 |
|
| 360 |
This will take an abbreviation (which must be a known |
| 361 |
abbreviation... there is no means of defining a totally new |
| 362 |
abbreviation) and a list of zones. This will set the list of zones |
| 363 |
that will be checked, and the order in which they are checked, when a |
| 364 |
date is encountered with the given abbreviation. It is not necessary |
| 365 |
that the list include every zone that has ever used the abbreviation, |
| 366 |
but it may not include a zone that has never used it. |
| 367 |
|
| 368 |
If $abbrev is "reset", all abbreviations are reset to the standard |
| 369 |
values. If @zone includes only the element 'reset', the default list |
| 370 |
for $abbrev is restored. |
| 371 |
|
| 372 |
The following error codes are returned: |
| 373 |
|
| 374 |
0 No error |
| 375 |
1 $abbrev is not a valid abbreviation in any time zone |
| 376 |
2 A zone (returned as $val) is not a valid time zone |
| 377 |
3 A zone (returned as $val) does not use the abbreviation |
| 378 |
|
| 379 |
For more information about the different zones which may correspond |
| 380 |
to each abbreviation, and the order in which they will be examined |
| 381 |
by default, refer to the Date::Manip::Zones manual. |
| 382 |
|
| 383 |
=item B<define_alias> |
| 384 |
|
| 385 |
$err = $tz->define_alias($alias,$zone); |
| 386 |
|
| 387 |
This will define a new alias (or override an existing alias). $zone must |
| 388 |
be a valid zone or an error is returned. |
| 389 |
|
| 390 |
For more information about the different aliases which are set by |
| 391 |
default, refer to the Date::Manip::Zones manual. |
| 392 |
|
| 393 |
If $alias is "reset", all aliases will be reset to the standard values. |
| 394 |
If $zone is "reset", $alias will be reset to the standard value. |
| 395 |
|
| 396 |
=item B<define_offset> |
| 397 |
|
| 398 |
($err,$val) = $tz->define_offset($offset, [$dstflag,] @zone); |
| 399 |
|
| 400 |
This is similar to the define_abbrev method. When an offset is encountered, |
| 401 |
all time zones which have ever included that offset are checked. This will |
| 402 |
defined which time zones, and in what order, they should be checked. |
| 403 |
|
| 404 |
The zones to both standard and daylight saving times which include the |
| 405 |
offset (if $dstflag is "std" or "dst") or to only one or the other. |
| 406 |
|
| 407 |
If $offset is "reset", all lists are reset to the default values. If |
| 408 |
@zone includes only the element 'reset', the default list and order is |
| 409 |
restored for $offset ($dstflag must not be given). |
| 410 |
|
| 411 |
The following error codes are returned: |
| 412 |
|
| 413 |
0 No error |
| 414 |
1 $offset is not a valid offset in any time zone |
| 415 |
2 $offset is not a valid offset in the selected |
| 416 |
time (if doing "dstonly" or "stdonly") |
| 417 |
3 A zone (returned as $val) is not a valid time zone |
| 418 |
4 A zone (returned as $val) does not use the offset |
| 419 |
5 A zone (returned as $val) does not include the |
| 420 |
offset in the selected time (if doing "dstonly" |
| 421 |
or "stdonly") |
| 422 |
|
| 423 |
9 Offset is not a valid offset |
| 424 |
|
| 425 |
=item B<periods> |
| 426 |
|
| 427 |
@periods = $tz->periods($zone,$year); |
| 428 |
|
| 429 |
This returns the description of all time zone periods that begin during the |
| 430 |
year given. The year is measured in universal (GMT) time. |
| 431 |
|
| 432 |
If no time zone period starts in the given year, nothing is returned. |
| 433 |
|
| 434 |
@periods = $tz->periods($zone,undef,$year); |
| 435 |
|
| 436 |
This returns all periods that begin in any year from 0001 to $year. |
| 437 |
|
| 438 |
@periods = $tz->periods($zone,$year0,$year1); |
| 439 |
|
| 440 |
This returns all periods that begin in any year from $year0 to $year1. |
| 441 |
|
| 442 |
=item B<tzdata> |
| 443 |
|
| 444 |
=item B<tzcode> |
| 445 |
|
| 446 |
$vers = $tz->tzdata(); |
| 447 |
$vers = $tz->tzcode(); |
| 448 |
|
| 449 |
These return the versions of the tzdata and tzcode packages used to |
| 450 |
generate the modules. |
| 451 |
|
| 452 |
=item B<zone> |
| 453 |
|
| 454 |
$zone = $tz->zone(@args); |
| 455 |
@zone = $tz->zone(@args); |
| 456 |
|
| 457 |
This function will return a list of all zones, or the default zone, |
| 458 |
which matches all of the supplied information. In scalar context, |
| 459 |
it will return only the default zone. In list context, it will return |
| 460 |
all zones. |
| 461 |
|
| 462 |
@args may include any of the following items, and the order is not |
| 463 |
important. |
| 464 |
|
| 465 |
A zone name or alias ($alias) |
| 466 |
|
| 467 |
A zone abbreviation ($abbrev) |
| 468 |
|
| 469 |
An offset ($offset) |
| 470 |
|
| 471 |
A dstflag ($dstflag) |
| 472 |
|
| 473 |
A date ($date) |
| 474 |
|
| 475 |
It is NOT valid to include two of any of the items. Any time zone |
| 476 |
returned will match all of the data supplied. |
| 477 |
|
| 478 |
If an error occurs, undef is returned. If no zone matches, an empty |
| 479 |
string, or an empty list is returned. |
| 480 |
|
| 481 |
The order of the zones will be determined in the following way: |
| 482 |
|
| 483 |
If $abbrev is given, the order of time zones will be determined by it |
| 484 |
(and $dstflag). If $dstflag is "std", all zones which match $abbrev in |
| 485 |
standard time are included, followed by all that match $abbrev in |
| 486 |
saving time (but no duplication is allowed). The reverse is true if |
| 487 |
$dstflag is "dst". |
| 488 |
|
| 489 |
If $abbrev is not given, but $offset is, $offset (and $dstflag) |
| 490 |
will determine the order given. If $dstflag is "std", all zones |
| 491 |
which match $offset in standard time are included, followed by |
| 492 |
all that match $offset in saving time (but no duplication is |
| 493 |
allowed). The reverse is true if $dstflag is "dst". |
| 494 |
|
| 495 |
If $date is given, only zones in which $date will appear in a |
| 496 |
zone that matches all other information are given. $date is a |
| 497 |
wall clock time. |
| 498 |
|
| 499 |
If no $zone, $abbrev, or $offset are entered, the local time zone |
| 500 |
may be returned (unless $date is entered, and it doesn't exist in |
| 501 |
the local time zone). |
| 502 |
|
| 503 |
NOTE: there is one important thing to note with respect to $dstflag |
| 504 |
when you are working with a timezone expressed as an offset and a date |
| 505 |
is passed in. In this case, the default value of $dstflag is "dst" |
| 506 |
(NOT "stdonly"), and you probably never want to pass in a value of |
| 507 |
"std" (though passing in "stdonly" is okay). |
| 508 |
|
| 509 |
For standard offsets (with no minute component), there is always |
| 510 |
a standard timezone which matches that offset. For example, |
| 511 |
the timezone "+0100" matches the timezone "Etc/GMT+01", so you |
| 512 |
will never get a timezone in daylight saving time if $dstflag |
| 513 |
is "std". |
| 514 |
|
| 515 |
If you want to pass in a date of 2001-07-01-00:00:00 and an timezone |
| 516 |
of "+0100" and you want to get a timezone that refers to that date |
| 517 |
as a daylight saving time date, you must use the $dstflag of "dst" |
| 518 |
(or "dstonly"). |
| 519 |
|
| 520 |
Because this is almost always the behavior desired, when a zone |
| 521 |
is passed in as an offset, and a date is passed in, the default |
| 522 |
$dstflag is "dst" instead of "std". In all other situations, |
| 523 |
the default is still "std". |
| 524 |
|
| 525 |
If the timezone is expressed as an abbreviation, this problem |
| 526 |
does not occur. |
| 527 |
|
| 528 |
=back |
| 529 |
|
| 530 |
=head1 TIME ZONE INFORMATION IN DATE::MANIP |
| 531 |
|
| 532 |
Date::Manip makes use of three potentially different time zones when |
| 533 |
working with a date. |
| 534 |
|
| 535 |
The first time zone that may be used is the actual local time zone. |
| 536 |
This is the time zone that the computer is actually running in. |
| 537 |
|
| 538 |
The second time zone is the working time zone. Usually, you will want |
| 539 |
the default time zone to be the local time zone, but occasionally, you |
| 540 |
may want the default time zone to be different. |
| 541 |
|
| 542 |
The third time zone is the actual time zone that was parsed, or set, |
| 543 |
for a date. If a date contains no time zone information, it will |
| 544 |
default to the working time zone. |
| 545 |
|
| 546 |
The local time zone is determined using the methods described in the |
| 547 |
following section. Methods exist for locating the zone in one of the |
| 548 |
system configuration files, determining it by running a system |
| 549 |
command, or by looking it up in the registry (for Windows operating |
| 550 |
systems). If all of these methods fail, the local time zone may be |
| 551 |
set using either the $::TZ or $ENV{TZ} variables. Please note that |
| 552 |
these should ONLY be used to set the actual local time zone. |
| 553 |
|
| 554 |
If you are running in one time zone, but you want to force dates to be |
| 555 |
specified in an alternate time zone by default, you need to set the |
| 556 |
working time zone. The working time zone defaults to the local time zone, |
| 557 |
but this can be changed using either the SetDate or ForceDate |
| 558 |
config variables. Refer to the Date::Manip::Config manual for more |
| 559 |
information. |
| 560 |
|
| 561 |
Finally, when a date is actually parsed, if it contains any time zone |
| 562 |
information, the date is stored in that time zone. |
| 563 |
|
| 564 |
=head1 DETERMINING THE SYSTEM TIME ZONE |
| 565 |
|
| 566 |
There are a large number of ways available for determining the |
| 567 |
time zone. Some or all of them may be checked. A list of methods to use |
| 568 |
is provided by default, and may be overridden by the curr_zone_methods |
| 569 |
function described above. To override the default order and/or list of |
| 570 |
methods, just pass in a list of method names (with arguments where |
| 571 |
necessary), and only those methods will be done, and in the order |
| 572 |
given. |
| 573 |
|
| 574 |
The following methods are available: |
| 575 |
|
| 576 |
Method Argument(s) Procedure |
| 577 |
====== =========== ========= |
| 578 |
|
| 579 |
main VAR The main variable named VAR is |
| 580 |
checked. E.g. "main TZ" checks |
| 581 |
the variable $::TZ . |
| 582 |
|
| 583 |
env TYPE VAR The named environment variable |
| 584 |
is checked and the type of |
| 585 |
data stored there (TYPE can |
| 586 |
be 'zone' or 'offset' which |
| 587 |
is the number of seconds from |
| 588 |
UTC). |
| 589 |
|
| 590 |
file FILE Look in the given file for any |
| 591 |
one of the following case |
| 592 |
insensitive lines: |
| 593 |
ZONE |
| 594 |
tz = ZONE |
| 595 |
zone = ZONE |
| 596 |
timezone = ZONE |
| 597 |
ZONE may be quoted (single or |
| 598 |
double) and whitespace is |
| 599 |
ignored (except that underscores |
| 600 |
in the zone name may be replaced |
| 601 |
by whitespace on some OSes). If |
| 602 |
the entire line is a zone, it must |
| 603 |
be the first non-blank non-comment |
| 604 |
line in the file. |
| 605 |
|
| 606 |
command COMMAND Runs a command which produces |
| 607 |
a time zone as the output. |
| 608 |
|
| 609 |
cmdfield COMMAND N Runs a command which produces |
| 610 |
whitespace separated fields, |
| 611 |
the Nth one containing the |
| 612 |
time zone (fields are numbered |
| 613 |
starting at 0, or from the |
| 614 |
end starting at -1). |
| 615 |
|
| 616 |
gmtoff Uses the current offset from |
| 617 |
GMT to come up with a best guess. |
| 618 |
|
| 619 |
tzdata FILE DIR This uses a system config file that |
| 620 |
contains a pointer to the local tzdata |
| 621 |
files to determine the timezone. On |
| 622 |
many operating systems, use: |
| 623 |
|
| 624 |
tzdata /etc/localtime /usr/share/zoneinfo |
| 625 |
|
| 626 |
FILE is the system file. DIR is the |
| 627 |
directory where the tzdata files are stored. |
| 628 |
|
| 629 |
The config file is either a link to a file |
| 630 |
in the tzdata directory or a copy of one |
| 631 |
of the files. |
| 632 |
|
| 633 |
registry Look up the value in the |
| 634 |
Windows registry. This is only |
| 635 |
available to hosts running a |
| 636 |
Windows operating system. |
| 637 |
|
| 638 |
Note that the "main" and "env" methods should only be used to |
| 639 |
specify the actual time zone the system is running in. Use the |
| 640 |
SetDate and ForceDate config variables to specify an alternate |
| 641 |
time zone that you want to work in. |
| 642 |
|
| 643 |
By default, the following methods are checked (in the order given) on |
| 644 |
Unix systems: |
| 645 |
|
| 646 |
main TZ |
| 647 |
env zone TZ |
| 648 |
file /etc/TIMEZONE |
| 649 |
file /etc/timezone |
| 650 |
file /etc/sysconfig/clock |
| 651 |
file /etc/default/init |
| 652 |
command "/bin/date +%Z" |
| 653 |
command "/usr/bin/date +%Z" |
| 654 |
command "/usr/local/bin/date +%Z" |
| 655 |
cmdfield /bin/date -2 |
| 656 |
cmdfield /usr/bin/date -2 |
| 657 |
cmdfield /usr/local/bin/date -2 |
| 658 |
command "/bin/date +%z" |
| 659 |
command "/usr/bin/date +%z" |
| 660 |
command "/usr/local/bin/date +%z" |
| 661 |
tzdata /etc/localtime /usr/share/zoneinfo |
| 662 |
gmtoff |
| 663 |
|
| 664 |
The default methods for Windows systems are: |
| 665 |
|
| 666 |
main TZ |
| 667 |
env zone TZ |
| 668 |
registry |
| 669 |
gmtoff |
| 670 |
|
| 671 |
The default methods for VMS systems are: |
| 672 |
|
| 673 |
main TZ |
| 674 |
env zone TZ |
| 675 |
env zone SYS$TIMEZONE_NAME |
| 676 |
env zone UCX$TZ |
| 677 |
env zone TCPIP$TZ |
| 678 |
env zone MULTINET_TIMEZONE |
| 679 |
env offset SYS$TIMEZONE_DIFFERENTIAL |
| 680 |
gmtoff |
| 681 |
|
| 682 |
The default methods for all other systems are: |
| 683 |
|
| 684 |
main TZ |
| 685 |
env zone TZ |
| 686 |
gmtoff |
| 687 |
|
| 688 |
If anyone wants better support for a specific OS, please contact me and |
| 689 |
we'll coordinate adding it. |
| 690 |
|
| 691 |
In all cases, the value returned from the method may be any of the |
| 692 |
following: |
| 693 |
|
| 694 |
the full name of a time zone (e.g. America/New_York) |
| 695 |
or an alias |
| 696 |
|
| 697 |
an abbreviation (e.g. EDT) which will be used to |
| 698 |
determine the zone if possible |
| 699 |
|
| 700 |
an offset (+hh, +hhmn, +hh:mm, +hh:mm:ss) from GMT |
| 701 |
|
| 702 |
The Date::Manip::Zones module contains information about the time zones |
| 703 |
and aliases available, and what time zones contain the abbreviations. |
| 704 |
|
| 705 |
=head1 DESIGN ISSUES |
| 706 |
|
| 707 |
The design decisions made in writing this module may cause some |
| 708 |
questions (and probably complaints). The time zone modules are all |
| 709 |
generated using scripts (included in the Date::Manip distribution) |
| 710 |
which use the standard tzdata tools to parse the tzdata files and |
| 711 |
store that information in perl modules. |
| 712 |
|
| 713 |
I'd like to address some of them, to avoid answering some of the |
| 714 |
"why did you do it that way" remarks. I do welcome discussion about |
| 715 |
these decisions... but preferably after you understand why those |
| 716 |
decisions were made so that that we have an informed basis to begin |
| 717 |
a discussion. |
| 718 |
|
| 719 |
=over 4 |
| 720 |
|
| 721 |
=item B<Why not use existing zoneinfo files> |
| 722 |
|
| 723 |
Some people will probably think that I should have written an interface to |
| 724 |
the zoneinfo files which are distributed with most operating systems. |
| 725 |
Although I considered doing that, I rejected the idea for two reasons. |
| 726 |
|
| 727 |
First, not all operating systems come with the zoneinfo databases in a |
| 728 |
user accessible state (Microsoft for example). Even those that do |
| 729 |
include them store the information in various formats and locations. |
| 730 |
In order to bypass all that, I have included the data directly in |
| 731 |
these modules. |
| 732 |
|
| 733 |
Second, as I was doing my initial investigations into this, I ran into |
| 734 |
a bug in the Solaris zoneinfo tools (long since fixed I'm sure). I |
| 735 |
decided then that I didn't want to depend on an implementation where I |
| 736 |
could not control and fix the bugs. |
| 737 |
|
| 738 |
=item B<Why not use the native tzdata files> |
| 739 |
|
| 740 |
Another decision people may question is that I parse the tzdata |
| 741 |
files and store the data from them in a large number of perl modules |
| 742 |
instead of creating an interface to the tzdata files directly. This |
| 743 |
was done solely for the sake of speed. Date::Manip is already a slow |
| 744 |
module. I didn't want to slow it down further by doing the complex |
| 745 |
parsing required to interpret the tzdata files while manipulating |
| 746 |
dates. By storing the data in these modules, there is little or no |
| 747 |
parsing done while using Date::Manip modules. It costs a little disk |
| 748 |
space to store this information... but very little of it is actually |
| 749 |
loaded at runtime (time zone data is only loaded when the time zone |
| 750 |
is actually referred to), so I feel it's a good tradeoff. |
| 751 |
|
| 752 |
=item B<Why store the information in so many files> |
| 753 |
|
| 754 |
The data from the native tzdata files are parsed and stored in two |
| 755 |
sets of modules. These include almost 500 Date::Manip::Offset::* |
| 756 |
modules and almost 450 Date::Manip::TZ::* modules. |
| 757 |
|
| 758 |
I note that on my linux box, /usr/share/zoneinfo (which contains data |
| 759 |
files generated from the tzdata files) contains over 1700 files, so |
| 760 |
I'm not doing anything "new" by breaking up the information into |
| 761 |
separate files. And doing so has a huge impact on performance... it |
| 762 |
is not necessary to load and/or manipulate data from time zones which |
| 763 |
are not in use. |
| 764 |
|
| 765 |
The minute I made the decision to distribute the timezone information |
| 766 |
myself, as opposed to using the system version, it was a given that |
| 767 |
there would be a lot of files. |
| 768 |
|
| 769 |
These modules are loaded only when the time zone or offset is actually |
| 770 |
used, so, unless dates from around the world are being parsed, only a |
| 771 |
very small number of these modules will actually be loaded. In many |
| 772 |
applications, only a single TZ module will be loaded. If parsing |
| 773 |
dates which have timezone information stored as offsets, one or two |
| 774 |
Offset modules will also be loaded. |
| 775 |
|
| 776 |
=item B<The disk space seems excessive> |
| 777 |
|
| 778 |
Currently, the disk usage of the perl files is around 9 MB. Total disk |
| 779 |
usage for /usr/share/zoneinfo on my computer is around 4 MB. There are |
| 780 |
a couple of differences. |
| 781 |
|
| 782 |
The primary difference is that the zoneinfo files are stored in a binary |
| 783 |
(and hence, more compressed) version, where the perl modules have all |
| 784 |
the data in pure text. |
| 785 |
|
| 786 |
Since these are all automatically generated and used, it may be |
| 787 |
beneficial to store the data in some packed binary format instead of |
| 788 |
the fully expanded text form that is currently in use. This would |
| 789 |
decrease the disk space usage, and might improve performance. However, |
| 790 |
the performance improvement would happen only once per timezone, and |
| 791 |
would make for more complicated code, so I'm not very interested in |
| 792 |
pursuing this. |
| 793 |
|
| 794 |
Another aspect of the current modules is that they all include pod |
| 795 |
documentation. Although not necessary, this allows users to easily |
| 796 |
see what modules handle which time zones, and that's nice. It also |
| 797 |
allows me to use pod_coverage tests for the module which is a nice |
| 798 |
check to make sure that the documentation is accurate. |
| 799 |
|
| 800 |
All told, I don't consider the disk usage excessive at all. |
| 801 |
|
| 802 |
=back |
| 803 |
|
| 804 |
=head1 KNOWN PROBLEMS OR ISSUES |
| 805 |
|
| 806 |
=over 4 |
| 807 |
|
| 808 |
=item B<Unable to determine Time Zone> |
| 809 |
|
| 810 |
When using Date::Manip, when the module is initialized, it must be |
| 811 |
able to determine the local time zone. If it fails to do so, an |
| 812 |
error will occur: |
| 813 |
|
| 814 |
Unable to determine Time Zone |
| 815 |
|
| 816 |
and the script will exit. |
| 817 |
|
| 818 |
In the past, this was the most common problem with using Date::Manip . |
| 819 |
With the release of 6.00, this problem should be significantly less |
| 820 |
common. If you do get this error, please refer to the section above |
| 821 |
DETERMINING THE SYSTEM TIME ZONE for information about determining the |
| 822 |
local time zone. I am also interested in hearing about this so that I |
| 823 |
can update the default list of methods to be able to determine the |
| 824 |
local time zone better. |
| 825 |
|
| 826 |
=item B<Asia/Jerusalem time zone> |
| 827 |
|
| 828 |
The Asia/Jerusalem time zone has a non-standard way of specifying |
| 829 |
the start and end of Daylight Saving Time based on the Hebrew |
| 830 |
calendar. |
| 831 |
|
| 832 |
As a result, there is no way to specify a simple rule to define |
| 833 |
time zone changes for all years in the future. As such, this module |
| 834 |
supports all time zone changes currently specified in the zoneinfo |
| 835 |
database (which currently goes to the year 2037) but does not attempt |
| 836 |
to correctly handle zone changes beyond that date. As a result, |
| 837 |
Date::Manip should not be used to parse dates in the Jerusalem |
| 838 |
time zone that are far enough in the future that information is not |
| 839 |
included in the current version of the zoneinfo database. |
| 840 |
|
| 841 |
=item B<LMT and zzz abbreviations> |
| 842 |
|
| 843 |
Both the LMT and zzz abbreviations are used in the zoneinfo databases. |
| 844 |
LMT is use for most time zones for the times before the Gregorian |
| 845 |
calendar was adopted, and zzz is used for a few where the time zone was |
| 846 |
created and no description of dates prior to that are supported. Both |
| 847 |
LMT and zzz are basically ignored in parsing dates (because there is |
| 848 |
no reasonable way to determine which zone they are referring to), and |
| 849 |
will be treated as the local time zone regardless. |
| 850 |
|
| 851 |
=back |
| 852 |
|
| 853 |
=head1 KNOWN BUGS |
| 854 |
|
| 855 |
None known. |
| 856 |
|
| 857 |
=head1 BUGS AND QUESTIONS |
| 858 |
|
| 859 |
Please refer to the Date::Manip::Problems documentation for |
| 860 |
information on submitting bug reports or questions to the author. |
| 861 |
|
| 862 |
=head1 SEE ALSO |
| 863 |
|
| 864 |
Date::Manip - main module documentation |
| 865 |
|
| 866 |
=head1 LICENSE |
| 867 |
|
| 868 |
This script is free software; you can redistribute it and/or |
| 869 |
modify it under the same terms as Perl itself. |
| 870 |
|
| 871 |
=head1 AUTHOR |
| 872 |
|
| 873 |
Sullivan Beck ([email protected]) |
| 874 |
|
| 875 |
=cut |