Blame lib/Date/Manip/TZ.pod

Packit Service 653591
# Copyright (c) 2008-2017 Sullivan Beck. All rights reserved.
Packit Service 653591
# This program is free software; you can redistribute it and/or modify it
Packit Service 653591
# under the same terms as Perl itself.
Packit Service 653591
Packit Service 653591
=pod
Packit Service 653591
Packit Service 653591
=head1 NAME
Packit Service 653591
Packit Service 653591
Date::Manip::TZ - an interface to the time zone data
Packit Service 653591
Packit Service 653591
=head1 SYNOPSIS
Packit Service 653591
Packit Service 653591
   use Date::Manip::TZ;
Packit Service 653591
   $tz = new Date::Manip::TZ;
Packit Service 653591
Packit Service 653591
Data for most (and hopefully all) time zones used around the world have
Packit Service 653591
been gathered and is publicly available in the zoneinfo (or Olson)
Packit Service 653591
database.
Packit Service 653591
Packit Service 653591
This module uses the data from the zoneinfo database to perform various
Packit Service 653591
time zone operations.
Packit Service 653591
Packit Service 653591
=head1 DESCRIPTION
Packit Service 653591
Packit Service 653591
Every time zone has some of the following characteristics:
Packit Service 653591
Packit Service 653591
=over 4
Packit Service 653591
Packit Service 653591
=item B<name>
Packit Service 653591
Packit Service 653591
Every time zone has a unique name. In the zoneinfo database, these
Packit Service 653591
are something similar to:
Packit Service 653591
Packit Service 653591
   America/New_York
Packit Service 653591
Packit Service 653591
=item B<aliases>
Packit Service 653591
Packit Service 653591
Time zones may have (but are not required to have) one or more aliases.
Packit Service 653591
Each alias is unique, and is not the same as any time zone name. An
Packit Service 653591
alias can be used in exactly the same way as a name.
Packit Service 653591
Packit Service 653591
=item B<periods>
Packit Service 653591
Packit Service 653591
Every time zone is broken up into periods. Each period describes how
Packit Service 653591
a portion of time relates to GMT, and how it might be expressed.
Packit Service 653591
Packit Service 653591
=back
Packit Service 653591
Packit Service 653591
Each period includes the following information:
Packit Service 653591
Packit Service 653591
=over 4
Packit Service 653591
Packit Service 653591
=item B<start time, end time>
Packit Service 653591
Packit Service 653591
The period begin and ends at certain times. The times are
Packit Service 653591
included both as an absolute GMT time, and as a wall clock time.
Packit Service 653591
The wall clock start time is the time that will be on a clock
Packit Service 653591
just as the period starts (i.e. after a time change). The wall clock
Packit Service 653591
end time is the time on a clock immediately before the period ends.
Packit Service 653591
Packit Service 653591
=item B<offset>
Packit Service 653591
Packit Service 653591
The entire period has an offset which is how much the wall clock
Packit Service 653591
time differs from GMT.
Packit Service 653591
Packit Service 653591
=item B<abbreviation>
Packit Service 653591
Packit Service 653591
When expressing the time period, an abbreviation (such as EST) is
Packit Service 653591
typically used.
Packit Service 653591
Packit Service 653591
=item B<daylight saving time flag>
Packit Service 653591
Packit Service 653591
Every period is categorized as a standard time or a daylight
Packit Service 653591
saving time. The flag will be 1 if it is a daylight saving time,
Packit Service 653591
or 0 if it is a standard time.
Packit Service 653591
Packit Service 653591
=back
Packit Service 653591
Packit Service 653591
Date::Manip includes all of the data for all of the time zones from
Packit Service 653591
the zoneinfo database. This data is available from:
Packit Service 653591
Packit Service 653591
L<ftp://ftp.iana.org/tz/>
Packit Service 653591
Packit Service 653591
Additional data from other standards are also used.
Packit Service 653591
Packit Service 653591
The zoneinfo database is not necessary in order to use Date::Manip.
Packit Service 653591
Instead, all of that data has been extracted and stored in a
Packit Service 653591
series of other modules which are used to handle each time zone.
Packit Service 653591
In that way, Date::Manip has no dependency on any other source
Packit Service 653591
of data.
Packit Service 653591
Packit Service 653591
The L<Date::Manip::Zones> document contains detailed information
Packit Service 653591
on the data available.
Packit Service 653591
Packit Service 653591
=head1 METHODS
Packit Service 653591
Packit Service 653591
In all methods, the following variables are used:
Packit Service 653591
Packit Service 653591
=over 4
Packit Service 653591
Packit Service 653591
=item B<$zone>
Packit Service 653591
Packit Service 653591
This is a string which contains a valid time zone name.  For
Packit Service 653591
example:
Packit Service 653591
Packit Service 653591
  America/New_York
Packit Service 653591
Packit Service 653591
=item B<$alias>
Packit Service 653591
Packit Service 653591
This is a strings which contains a valid time zone name, or a valid
Packit Service 653591
time zone alias. For example:
Packit Service 653591
Packit Service 653591
  America/New_York
Packit Service 653591
  US/Eastern
Packit Service 653591
  EST5EDT
Packit Service 653591
Packit Service 653591
=item B<$abbrev>
Packit Service 653591
Packit Service 653591
This is a string which contains a valid time zone abbreviation. For
Packit Service 653591
example:
Packit Service 653591
Packit Service 653591
  EST
Packit Service 653591
Packit Service 653591
=item B<$offset>
Packit Service 653591
Packit Service 653591
This is a time zone entered as an offset. An offset is either a string
Packit Service 653591
of one of the formats:
Packit Service 653591
Packit Service 653591
  +HH
Packit Service 653591
  +HHMM
Packit Service 653591
  +HHMMSS
Packit Service 653591
  +HH:MM
Packit Service 653591
  +HH:MM:SS
Packit Service 653591
Packit Service 653591
or it can be a list reference:
Packit Service 653591
Packit Service 653591
  [HH,MM,SS]
Packit Service 653591
Packit Service 653591
If a list reference is used, the sign must be included with all values.
Packit Service 653591
So, the offset "-05:30" would be the list reference:
Packit Service 653591
Packit Service 653591
  [-5,-30,0]
Packit Service 653591
Packit Service 653591
=item B<$dstflag>
Packit Service 653591
Packit Service 653591
This is always one of the values: std, stdonly, dst, dstonly
Packit Service 653591
Packit Service 653591
It defaults to "std" if it is not present. When determining a time zone,
Packit Service 653591
it is usually necessary to check a number of different time zone and
Packit Service 653591
DST combinations.
Packit Service 653591
Packit Service 653591
If C<$dstflag> is "std", it will check both standard and daylight saving
Packit Service 653591
times, but will give preference to standard times. If C<$dstflag> is
Packit Service 653591
"stdonly", only standard times will be checked.
Packit Service 653591
Packit Service 653591
The "dst" flag will search both, but give preference to daylight saving
Packit Service 653591
times.  The "dstonly" values will only use daylight saving times.
Packit Service 653591
Packit Service 653591
=item B<$date>
Packit Service 653591
Packit Service 653591
A date is always a string containing a date in one of the formats:
Packit Service 653591
Packit Service 653591
   YYYYMMDDHH:MN:SS
Packit Service 653591
   YYYY-MM-DD-HH:MN:SS
Packit Service 653591
   YYYYMMDDHHMNSS
Packit Service 653591
Packit Service 653591
or a list reference:
Packit Service 653591
Packit Service 653591
   [Y,M,D,H,MN,S]
Packit Service 653591
Packit Service 653591
=item B<$isdst>
Packit Service 653591
Packit Service 653591
This is 0 if a date is in standard time, 1 if it is in daylight saving
Packit Service 653591
time.
Packit Service 653591
Packit Service 653591
=item B<$period>
Packit Service 653591
Packit Service 653591
A period is a list reference currently containing the following
Packit Service 653591
items:
Packit Service 653591
Packit Service 653591
   [ $dateUT, $dateLT, $offsetstr, $offset, $abbrev, $isdst,
Packit Service 653591
     $endUT, $endLT, $begUTs, $begLTs, $endUTs, $endLTs ]
Packit Service 653591
Packit Service 653591
C<$dateUT> and C<$dateLT> are the starting date of the period (i.e. the
Packit Service 653591
first second in a period) in universal (GMT) time and local
Packit Service 653591
(wall clock) time. C<$endUT> and C<$endLT> are the end date of the period
Packit Service 653591
(i.e. the last second in a period) in universal and local time.
Packit Service 653591
These are all stored as list references.
Packit Service 653591
Packit Service 653591
C<$offsetstr> is the string representation of the offset ("+05:00:00")
Packit Service 653591
and C<$offset> is the corresponding list reference form ([5,0,0]).
Packit Service 653591
Packit Service 653591
C<$abbrev> is the abbreviation that applies during this period, and C<$isdst>
Packit Service 653591
is 0 or 1 if it is standard or daylight saving time.
Packit Service 653591
Packit Service 653591
When accessing the elements in a period, use ONLY positive indices.
Packit Service 653591
In other words, to get C<$endUT>, access it as C<$$period[6]>, NOT as
Packit Service 653591
C<$$period[-2]>, since I am considering adding more information to the
Packit Service 653591
period description that may speed up performance.
Packit Service 653591
Packit Service 653591
C<$begUTs> is the string representation (YYYYMMDDHH:MN:SS) of C<$begUT>.
Packit Service 653591
Similar for C<$begLTs>, C<$endUTs>, and C<$endLTs>.
Packit Service 653591
Packit Service 653591
=back
Packit Service 653591
Packit Service 653591
The following methods are available:
Packit Service 653591
Packit Service 653591
=over 4
Packit Service 653591
Packit Service 653591
=item B<base>
Packit Service 653591
Packit Service 653591
=item B<config>
Packit Service 653591
Packit Service 653591
=item B<err>
Packit Service 653591
Packit Service 653591
=item B<new>
Packit Service 653591
Packit Service 653591
=item B<new_config>
Packit Service 653591
Packit Service 653591
Please refer to the L<Date::Manip::Obj> documentation for these methods.
Packit Service 653591
Packit Service 653591
=item B<all_periods>
Packit Service 653591
Packit Service 653591
   @periods = $tz->all_periods($zone,$year);
Packit Service 653591
Packit Service 653591
This returns the description of all time zone periods that occur (in
Packit Service 653591
full or in part) during the given year.  The year is measured in universal
Packit Service 653591
(GMT) time.
Packit Service 653591
Packit Service 653591
=item B<convert>
Packit Service 653591
Packit Service 653591
=item B<convert_to_gmt>
Packit Service 653591
Packit Service 653591
=item B<convert_from_gmt>
Packit Service 653591
Packit Service 653591
=item B<convert_to_local>
Packit Service 653591
Packit Service 653591
=item B<convert_from_local>
Packit Service 653591
Packit Service 653591
These functions convert a date from one time zone to another.
Packit Service 653591
Packit Service 653591
   ($err,$date,$offset,$isdst,$abbrev) =
Packit Service 653591
      $tz->convert($date,$from,$to [,$isdst]);
Packit Service 653591
Packit Service 653591
This converts a date in the time zone given by C<$from> to the time zone
Packit Service 653591
given by C<$to>.
Packit Service 653591
Packit Service 653591
   ($err,$date,$offset,$isdst,$abbrev) =
Packit Service 653591
      $tz->convert_to_gmt($date [,$from] [,$isdst]);
Packit Service 653591
Packit Service 653591
This converts a date to GMT. If C<$from> is given, it is the current
Packit Service 653591
time zone of the date. If C<$from> is omitted, it defaults to the local
Packit Service 653591
time zone.
Packit Service 653591
Packit Service 653591
The value of C<$isdst> returned is always 0.
Packit Service 653591
Packit Service 653591
   ($err,$date,$offset,$isdst,$abbrev) =
Packit Service 653591
      $tz->convert_from_gmt($date [,$to]);
Packit Service 653591
Packit Service 653591
This converts a date from GMT to another time zone. If C<$to> is given,
Packit Service 653591
the date is converted to that time zone. Otherwise, it is converted
Packit Service 653591
to the local time zone.
Packit Service 653591
Packit Service 653591
   ($err,$date,$offset,$isdst,$abbrev) =
Packit Service 653591
      $tz->convert_to_local($date [,$from] [,$isdst]);
Packit Service 653591
   ($err,$date,$offset,$isdst,$abbrev) =
Packit Service 653591
      $tz->convert_from_local($date [,$to] [,$isdst]);
Packit Service 653591
Packit Service 653591
Similar to the B<convert_to_gmt> and B<convert_from_gmt> functions. If C<$from>
Packit Service 653591
or C<$to> are omitted, they default to GMT.
Packit Service 653591
Packit Service 653591
If there is any ambiguity about whether C<$date> is in DST or not (i.e.
Packit Service 653591
if it is a date that is repeated during a time change due to the clock
Packit Service 653591
being moved back), the C<$isdst> option can be passed in as an argument
Packit Service 653591
(it should be 0 or 1) to say which time to use. It is ignored in all
Packit Service 653591
cases where C<$date> can be determined without that information.
Packit Service 653591
Packit Service 653591
The C<$isdst> value passed back is 1 if the converted date is in DST. The
Packit Service 653591
C<$offset> value passed back is a list reference containing the offset from
Packit Service 653591
GMT. C<$abbrev> passed back is the time zone abbreviation.
Packit Service 653591
Packit Service 653591
Error codes are:
Packit Service 653591
Packit Service 653591
   0  No error
Packit Service 653591
   1  Invalid arguments
Packit Service 653591
   2  Invalid FROM zone
Packit Service 653591
   3  Invalid TO zone
Packit Service 653591
   4  Invalid date
Packit Service 653591
Packit Service 653591
=item B<curr_zone>
Packit Service 653591
Packit Service 653591
   $tz->curr_zone();
Packit Service 653591
Packit Service 653591
This returns the system time zone. The system time zone is determined
Packit Service 653591
using the methods described below in the
Packit Service 653591
L</"DETERMINING THE SYSTEM TIME ZONE"> section.
Packit Service 653591
Packit Service 653591
This is the time zone that is used by default unless the SetDate
Packit Service 653591
or ForceDate config variable is set to a different zone.
Packit Service 653591
Packit Service 653591
   $tz->curr_zone(1);
Packit Service 653591
Packit Service 653591
This clears the system time zone and re-determines it using the
Packit Service 653591
methods described below.
Packit Service 653591
Packit Service 653591
The main reason to do this is if the curr_zone_methods method is
Packit Service 653591
used to change how the time zone is determined.
Packit Service 653591
Packit Service 653591
=item B<curr_zone_methods>
Packit Service 653591
Packit Service 653591
   $tz->curr_zone_methods(@methods);
Packit Service 653591
Packit Service 653591
This sets the list and order of methods to use in determining the
Packit Service 653591
local time zone. The various methods available are listed below in
Packit Service 653591
the section L</"DETERMINING THE SYSTEM TIME ZONE">.
Packit Service 653591
Packit Service 653591
Some methods may require one or more arguments. For example, the
Packit Service 653591
method named "mainvar" takes an option that is the name of a
Packit Service 653591
variable. The arguments must be included in the @methods list
Packit Service 653591
immediately after the method name (so @methods is actually a
Packit Service 653591
mixture of method names and arguments).
Packit Service 653591
Packit Service 653591
This method may not be used in any environment where taint
Packit Service 653591
checking is enabled. If it is, it will issue a warning, but
Packit Service 653591
will NOT change the method list.
Packit Service 653591
Packit Service 653591
=item B<date_period>
Packit Service 653591
Packit Service 653591
   $period = $tz->date_period($date,$zone,$wall_clock [,$isdst]);
Packit Service 653591
Packit Service 653591
This returns the period information for the given date. $date defaults
Packit Service 653591
to GMT, but may be given as local (i.e. wall clock) time if $wall_clock
Packit Service 653591
is non-zero. The period information is described in the periods method
Packit Service 653591
below.
Packit Service 653591
Packit Service 653591
If a wall clock time is given, no period is returned if the wall clock
Packit Service 653591
time doesn't ever appear (such as when a time change results in the
Packit Service 653591
clock moving forward "skipping" a period of time). If the wall clock
Packit Service 653591
time appears twice (i.e. when a time change results in the clock
Packit Service 653591
being set back), the $isdst variable is used. The standard time
Packit Service 653591
is used unless $isdst is non-zero.  $isdst is ignored except in the
Packit Service 653591
case where there are two possible periods.
Packit Service 653591
Packit Service 653591
=item B<define_abbrev>
Packit Service 653591
Packit Service 653591
   ($err,$val) = $tz->define_abbrev($abbrev,@zone);
Packit Service 653591
Packit Service 653591
When encountering an abbreviation, by default, all time zones which ever
Packit Service 653591
include the abbreviation will be examine in the order given in the
Packit Service 653591
Date::Manip::Zones manual.
Packit Service 653591
Packit Service 653591
Occasionally, it may be necessary to change the order. This is
Packit Service 653591
true if you are parsing dates in a time zone which uses an abbreviation which
Packit Service 653591
is also used in another time zone, and where the other time zone is given
Packit Service 653591
preference. As an example, the abbreviation "ADT" will default to the
Packit Service 653591
"Atlantic/Bermuda" time zone. If you are in the "America/Halifax" time zone
Packit Service 653591
(which also uses that abbreviation), you may want to change the order
Packit Service 653591
of time zones.
Packit Service 653591
Packit Service 653591
This will take an abbreviation (which must be a known
Packit Service 653591
abbreviation... there is no means of defining a totally new
Packit Service 653591
abbreviation) and a list of zones.  This will set the list of zones
Packit Service 653591
that will be checked, and the order in which they are checked, when a
Packit Service 653591
date is encountered with the given abbreviation. It is not necessary
Packit Service 653591
that the list include every zone that has ever used the abbreviation,
Packit Service 653591
but it may not include a zone that has never used it.
Packit Service 653591
Packit Service 653591
If $abbrev is "reset", all abbreviations are reset to the standard
Packit Service 653591
values.  If @zone includes only the element 'reset', the default list
Packit Service 653591
for $abbrev is restored.
Packit Service 653591
Packit Service 653591
The following error codes are returned:
Packit Service 653591
Packit Service 653591
   0  No error
Packit Service 653591
   1  $abbrev is not a valid abbreviation in any time zone
Packit Service 653591
   2  A zone (returned as $val) is not a valid time zone
Packit Service 653591
   3  A zone (returned as $val) does not use the abbreviation
Packit Service 653591
Packit Service 653591
For more information about the different zones which may correspond
Packit Service 653591
to each abbreviation, and the order in which they will be examined
Packit Service 653591
by default, refer to the Date::Manip::Zones manual.
Packit Service 653591
Packit Service 653591
=item B<define_alias>
Packit Service 653591
Packit Service 653591
   $err = $tz->define_alias($alias,$zone);
Packit Service 653591
Packit Service 653591
This will define a new alias (or override an existing alias). $zone must
Packit Service 653591
be a valid zone or an error is returned.
Packit Service 653591
Packit Service 653591
For more information about the different aliases which are set by
Packit Service 653591
default, refer to the Date::Manip::Zones manual.
Packit Service 653591
Packit Service 653591
If $alias is "reset", all aliases will be reset to the standard values.
Packit Service 653591
If $zone is "reset", $alias will be reset to the standard value.
Packit Service 653591
Packit Service 653591
=item B<define_offset>
Packit Service 653591
Packit Service 653591
   ($err,$val) = $tz->define_offset($offset, [$dstflag,] @zone);
Packit Service 653591
Packit Service 653591
This is similar to the define_abbrev method. When an offset is encountered,
Packit Service 653591
all time zones which have ever included that offset are checked. This will
Packit Service 653591
defined which time zones, and in what order, they should be checked.
Packit Service 653591
Packit Service 653591
The zones to both standard and daylight saving times which include the
Packit Service 653591
offset (if $dstflag is "std" or "dst") or to only one or the other.
Packit Service 653591
Packit Service 653591
If $offset is "reset", all lists are reset to the default values.  If
Packit Service 653591
@zone includes only the element 'reset', the default list and order is
Packit Service 653591
restored for $offset ($dstflag must not be given).
Packit Service 653591
Packit Service 653591
The following error codes are returned:
Packit Service 653591
Packit Service 653591
   0  No error
Packit Service 653591
   1  $offset is not a valid offset in any time zone
Packit Service 653591
   2  $offset is not a valid offset in the selected
Packit Service 653591
      time (if doing "dstonly" or "stdonly")
Packit Service 653591
   3  A zone (returned as $val) is not a valid time zone
Packit Service 653591
   4  A zone (returned as $val) does not use the offset
Packit Service 653591
   5  A zone (returned as $val) does not include the
Packit Service 653591
      offset in the selected time (if doing "dstonly"
Packit Service 653591
      or "stdonly")
Packit Service 653591
Packit Service 653591
   9  Offset is not a valid offset
Packit Service 653591
Packit Service 653591
=item B<periods>
Packit Service 653591
Packit Service 653591
   @periods = $tz->periods($zone,$year);
Packit Service 653591
Packit Service 653591
This returns the description of all time zone periods that begin during the
Packit Service 653591
year given. The year is measured in universal (GMT) time.
Packit Service 653591
Packit Service 653591
If no time zone period starts in the given year, nothing is returned.
Packit Service 653591
Packit Service 653591
   @periods = $tz->periods($zone,undef,$year);
Packit Service 653591
Packit Service 653591
This returns all periods that begin in any year from 0001 to $year.
Packit Service 653591
Packit Service 653591
   @periods = $tz->periods($zone,$year0,$year1);
Packit Service 653591
Packit Service 653591
This returns all periods that begin in any year from $year0 to $year1.
Packit Service 653591
Packit Service 653591
=item B<tzdata>
Packit Service 653591
Packit Service 653591
=item B<tzcode>
Packit Service 653591
Packit Service 653591
   $vers = $tz->tzdata();
Packit Service 653591
   $vers = $tz->tzcode();
Packit Service 653591
Packit Service 653591
These return the versions of the tzdata and tzcode packages used to
Packit Service 653591
generate the modules.
Packit Service 653591
Packit Service 653591
=item B<zone>
Packit Service 653591
Packit Service 653591
   $zone = $tz->zone(@args);
Packit Service 653591
   @zone = $tz->zone(@args);
Packit Service 653591
Packit Service 653591
This function will return a list of all zones, or the default zone,
Packit Service 653591
which matches all of the supplied information. In scalar context,
Packit Service 653591
it will return only the default zone. In list context, it will return
Packit Service 653591
all zones.
Packit Service 653591
Packit Service 653591
@args may include any of the following items, and the order is not
Packit Service 653591
important.
Packit Service 653591
Packit Service 653591
   A zone name or alias ($alias)
Packit Service 653591
Packit Service 653591
   A zone abbreviation ($abbrev)
Packit Service 653591
Packit Service 653591
   An offset ($offset)
Packit Service 653591
Packit Service 653591
   A dstflag ($dstflag)
Packit Service 653591
Packit Service 653591
   A date ($date)
Packit Service 653591
Packit Service 653591
It is NOT valid to include two of any of the items. Any time zone
Packit Service 653591
returned will match all of the data supplied.
Packit Service 653591
Packit Service 653591
If an error occurs, undef is returned. If no zone matches, an empty
Packit Service 653591
string, or an empty list is returned.
Packit Service 653591
Packit Service 653591
The order of the zones will be determined in the following way:
Packit Service 653591
Packit Service 653591
If $abbrev is given, the order of time zones will be determined by it
Packit Service 653591
(and $dstflag). If $dstflag is "std", all zones which match $abbrev in
Packit Service 653591
standard time are included, followed by all that match $abbrev in
Packit Service 653591
saving time (but no duplication is allowed). The reverse is true if
Packit Service 653591
$dstflag is "dst".
Packit Service 653591
Packit Service 653591
If $abbrev is not given, but $offset is, $offset (and $dstflag)
Packit Service 653591
will determine the order given. If $dstflag is "std", all zones
Packit Service 653591
which match $offset in standard time are included, followed by
Packit Service 653591
all that match $offset in saving time (but no duplication is
Packit Service 653591
allowed). The reverse is true if $dstflag is "dst".
Packit Service 653591
Packit Service 653591
If $date is given, only zones in which $date will appear in a
Packit Service 653591
zone that matches all other information are given. $date is a
Packit Service 653591
wall clock time.
Packit Service 653591
Packit Service 653591
If no $zone, $abbrev, or $offset are entered, the local time zone
Packit Service 653591
may be returned (unless $date is entered, and it doesn't exist in
Packit Service 653591
the local time zone).
Packit Service 653591
Packit Service 653591
NOTE: there is one important thing to note with respect to $dstflag
Packit Service 653591
when you are working with a timezone expressed as an offset and a date
Packit Service 653591
is passed in. In this case, the default value of $dstflag is "dst"
Packit Service 653591
(NOT "stdonly"), and you probably never want to pass in a value of
Packit Service 653591
"std" (though passing in "stdonly" is okay).
Packit Service 653591
Packit Service 653591
For standard offsets (with no minute component), there is always
Packit Service 653591
a standard timezone which matches that offset. For example,
Packit Service 653591
the timezone "+0100" matches the timezone "Etc/GMT+01", so you
Packit Service 653591
will never get a timezone in daylight saving time if $dstflag
Packit Service 653591
is "std".
Packit Service 653591
Packit Service 653591
If you want to pass in a date of 2001-07-01-00:00:00 and an timezone
Packit Service 653591
of "+0100" and you want to get a timezone that refers to that date
Packit Service 653591
as a daylight saving time date, you must use the $dstflag of "dst"
Packit Service 653591
(or "dstonly").
Packit Service 653591
Packit Service 653591
Because this is almost always the behavior desired, when a zone
Packit Service 653591
is passed in as an offset, and a date is passed in, the default
Packit Service 653591
$dstflag is "dst" instead of "std". In all other situations,
Packit Service 653591
the default is still "std".
Packit Service 653591
Packit Service 653591
If the timezone is expressed as an abbreviation, this problem
Packit Service 653591
does not occur.
Packit Service 653591
Packit Service 653591
=back
Packit Service 653591
Packit Service 653591
=head1 TIME ZONE INFORMATION IN DATE::MANIP
Packit Service 653591
Packit Service 653591
Date::Manip makes use of three potentially different time zones when
Packit Service 653591
working with a date.
Packit Service 653591
Packit Service 653591
The first time zone that may be used is the actual local time zone.
Packit Service 653591
This is the time zone that the computer is actually running in.
Packit Service 653591
Packit Service 653591
The second time zone is the working time zone. Usually, you will want
Packit Service 653591
the default time zone to be the local time zone, but occasionally, you
Packit Service 653591
may want the default time zone to be different.
Packit Service 653591
Packit Service 653591
The third time zone is the actual time zone that was parsed, or set,
Packit Service 653591
for a date. If a date contains no time zone information, it will
Packit Service 653591
default to the working time zone.
Packit Service 653591
Packit Service 653591
The local time zone is determined using the methods described in the
Packit Service 653591
following section. The preferred way is to locate the time zone in
Packit Service 653591
some system file, or using some system command, or (in the case of
Packit Service 653591
a Windows operating system) to look it up in the registry. If all
Packit Service 653591
of these methods fail, the local time zone may be set using either
Packit Service 653591
the $::TZ or $ENV{TZ} variables. Please note that these should ONLY
Packit Service 653591
be used to set the actual local time zone.
Packit Service 653591
Packit Service 653591
If you are running in one time zone, but you want to force dates to be
Packit Service 653591
specified in an alternate time zone by default, you need to set the
Packit Service 653591
working time zone. The working time zone defaults to the local time zone,
Packit Service 653591
but this can be changed using either the SetDate or ForceDate
Packit Service 653591
config variables. Refer to the Date::Manip::Config manual for more
Packit Service 653591
information.
Packit Service 653591
Packit Service 653591
Finally, when a date is actually parsed, if it contains any time zone
Packit Service 653591
information, the date is stored in that time zone.
Packit Service 653591
Packit Service 653591
=head1 DETERMINING THE SYSTEM TIME ZONE
Packit Service 653591
Packit Service 653591
There are a large number of ways available for determining the
Packit Service 653591
time zone. Some or all of them may be checked. A list of methods to use
Packit Service 653591
is provided by default, and may be overridden by the curr_zone_methods
Packit Service 653591
function described above. To override the default order and/or list of
Packit Service 653591
methods, just pass in a list of method names (with arguments where
Packit Service 653591
necessary), and only those methods will be done, and in the order
Packit Service 653591
given.
Packit Service 653591
Packit Service 653591
The following methods are available:
Packit Service 653591
Packit Service 653591
   Method     Argument(s)    Procedure
Packit Service 653591
   ======     ===========    =========
Packit Service 653591
Packit Service 653591
   main       VAR            The main variable named VAR is
Packit Service 653591
                             checked. E.g. "main TZ" checks
Packit Service 653591
                             the variable $::TZ .
Packit Service 653591
Packit Service 653591
   env        TYPE VAR       The named environment variable
Packit Service 653591
                             is checked and the type of
Packit Service 653591
                             data stored there (TYPE can
Packit Service 653591
                             be 'zone' or 'offset' which
Packit Service 653591
                             is the number of seconds from
Packit Service 653591
                             UTC).
Packit Service 653591
Packit Service 653591
   file       FILE           Look in the given file for any
Packit Service 653591
                             one of the following case
Packit Service 653591
                             insensitive lines:
Packit Service 653591
                                ZONE
Packit Service 653591
                                tz = ZONE
Packit Service 653591
                                zone = ZONE
Packit Service 653591
                                timezone = ZONE
Packit Service 653591
                             ZONE may be quoted (single or
Packit Service 653591
                             double) and whitespace is
Packit Service 653591
                             ignored (except that underscores
Packit Service 653591
                             in the zone name may be replaced
Packit Service 653591
                             by whitespace on some OSes). If
Packit Service 653591
                             the entire line is a zone, it must
Packit Service 653591
                             be the first non-blank non-comment
Packit Service 653591
                             line in the file.
Packit Service 653591
Packit Service 653591
   command    COMMAND        Runs a command which produces
Packit Service 653591
                             a time zone as the output.
Packit Service 653591
Packit Service 653591
   cmdfield   COMMAND N      Runs a command which produces
Packit Service 653591
                             whitespace separated fields,
Packit Service 653591
                             the Nth one containing the
Packit Service 653591
                             time zone (fields are numbered
Packit Service 653591
                             starting at 0, or from the
Packit Service 653591
                             end starting at -1).
Packit Service 653591
Packit Service 653591
   gmtoff                    Uses the current offset from
Packit Service 653591
                             GMT to come up with a best guess.
Packit Service 653591
Packit Service 653591
   tzdata     FILE DIR       This uses a system config file that
Packit Service 653591
                             contains a pointer to the local tzdata
Packit Service 653591
                             files to  determine the timezone.  On
Packit Service 653591
                             many operating systems, use:
Packit Service 653591
Packit Service 653591
                             tzdata /etc/localtime /usr/share/zoneinfo
Packit Service 653591
Packit Service 653591
                             FILE is the system file.  DIR is the
Packit Service 653591
                             directory where the tzdata files are stored.
Packit Service 653591
Packit Service 653591
                             The config file is either a link to a file
Packit Service 653591
                             in the tzdata directory or a copy of one
Packit Service 653591
                             of the files.
Packit Service 653591
Packit Service 653591
   registry                  Look up the value in the
Packit Service 653591
                             Windows registry. This is only
Packit Service 653591
                             available to hosts running a
Packit Service 653591
                             Windows operating system.
Packit Service 653591
Packit Service 653591
Note that the "main" and "env" methods should only be used to
Packit Service 653591
specify the actual time zone the system is running in. Use the
Packit Service 653591
SetDate and ForceDate config variables to specify an alternate
Packit Service 653591
time zone that you want to work in.
Packit Service 653591
Packit Service 653591
By default, the following methods are checked (in the order given) on
Packit Service 653591
Unix systems:
Packit Service 653591
Packit Service 653591
   main     TZ
Packit Service 653591
   env      zone TZ
Packit Service 653591
   file     /etc/TIMEZONE
Packit Service 653591
   file     /etc/timezone
Packit Service 653591
   file     /etc/sysconfig/clock
Packit Service 653591
   file     /etc/default/init
Packit Service 653591
   tzdata   /etc/localtime /usr/share/zoneinfo
Packit Service 653591
   command  "/bin/date +%Z"
Packit Service 653591
   command  "/usr/bin/date +%Z"
Packit Service 653591
   command  "/usr/local/bin/date +%Z"
Packit Service 653591
   cmdfield /bin/date             -2
Packit Service 653591
   cmdfield /usr/bin/date         -2
Packit Service 653591
   cmdfield /usr/local/bin/date   -2
Packit Service 653591
   gmtoff
Packit Service 653591
Packit Service 653591
The default methods for Windows systems are:
Packit Service 653591
Packit Service 653591
   main     TZ
Packit Service 653591
   env      zone TZ
Packit Service 653591
   registry
Packit Service 653591
   gmtoff
Packit Service 653591
Packit Service 653591
The default methods for VMS systems are:
Packit Service 653591
Packit Service 653591
   main     TZ
Packit Service 653591
   env      zone TZ
Packit Service 653591
   env      zone SYS$TIMEZONE_NAME
Packit Service 653591
   env      zone UCX$TZ
Packit Service 653591
   env      zone TCPIP$TZ
Packit Service 653591
   env      zone MULTINET_TIMEZONE
Packit Service 653591
   env      offset SYS$TIMEZONE_DIFFERENTIAL
Packit Service 653591
   gmtoff
Packit Service 653591
Packit Service 653591
The default methods for all other systems are:
Packit Service 653591
Packit Service 653591
   main     TZ
Packit Service 653591
   env      zone TZ
Packit Service 653591
   gmtoff
Packit Service 653591
Packit Service 653591
If anyone wants better support for a specific OS, please contact me and
Packit Service 653591
we'll coordinate adding it.
Packit Service 653591
Packit Service 653591
In all cases, the value returned from the method may be any of the
Packit Service 653591
following:
Packit Service 653591
Packit Service 653591
   the full name of a time zone (e.g. America/New_York)
Packit Service 653591
   or an alias
Packit Service 653591
Packit Service 653591
   an abbreviation (e.g. EDT) which will be used to
Packit Service 653591
   determine the zone if possible
Packit Service 653591
Packit Service 653591
   an offset (+hh, +hhmn, +hh:mm, +hh:mm:ss) from GMT
Packit Service 653591
Packit Service 653591
The Date::Manip::Zones module contains information about the time zones
Packit Service 653591
and aliases available, and what time zones contain the abbreviations.
Packit Service 653591
Packit Service 653591
=head1 DESIGN ISSUES
Packit Service 653591
Packit Service 653591
The design decisions made in writing this module may cause some
Packit Service 653591
questions (and probably complaints).  The time zone modules are all
Packit Service 653591
generated using scripts (included in the Date::Manip distribution)
Packit Service 653591
which use the standard tzdata tools to parse the tzdata files and
Packit Service 653591
store that information in perl modules.
Packit Service 653591
Packit Service 653591
I'd like to address some of them, to avoid answering some of the
Packit Service 653591
"why did you do it that way" remarks. I do welcome discussion about
Packit Service 653591
these decisions... but preferably after you understand why those
Packit Service 653591
decisions were made so that that we have an informed basis to begin
Packit Service 653591
a discussion.
Packit Service 653591
Packit Service 653591
=over 4
Packit Service 653591
Packit Service 653591
=item B<Why not use existing zoneinfo files>
Packit Service 653591
Packit Service 653591
Some people will probably think that I should have written an interface to
Packit Service 653591
the zoneinfo files which are distributed with most operating systems.
Packit Service 653591
Although I considered doing that, I rejected the idea for two reasons.
Packit Service 653591
Packit Service 653591
First, not all operating systems come with the zoneinfo databases in a
Packit Service 653591
user accessible state (Microsoft for example).  Even those that do
Packit Service 653591
include them store the information in various formats and locations.
Packit Service 653591
In order to bypass all that, I have included the data directly in
Packit Service 653591
these modules.
Packit Service 653591
Packit Service 653591
Second, as I was doing my initial investigations into this, I ran into
Packit Service 653591
a bug in the Solaris zoneinfo tools (long since fixed I'm sure).  I
Packit Service 653591
decided then that I didn't want to depend on an implementation where I
Packit Service 653591
could not control and fix the bugs.
Packit Service 653591
Packit Service 653591
=item B<Why not use the native tzdata files>
Packit Service 653591
Packit Service 653591
Another decision people may question is that I parse the tzdata
Packit Service 653591
files and store the data from them in a large number of perl modules
Packit Service 653591
instead of creating an interface to the tzdata files directly. This
Packit Service 653591
was done solely for the sake of speed.  Date::Manip is already a slow
Packit Service 653591
module.  I didn't want to slow it down further by doing the complex
Packit Service 653591
parsing required to interpret the tzdata files while manipulating
Packit Service 653591
dates.  By storing the data in these modules, there is little or no
Packit Service 653591
parsing done while using Date::Manip modules. It costs a little disk
Packit Service 653591
space to store this information... but very little of it is actually
Packit Service 653591
loaded at runtime (time zone data is only loaded when the time zone
Packit Service 653591
is actually referred to), so I feel it's a good tradeoff.
Packit Service 653591
Packit Service 653591
=item B<Why store the information in so many files>
Packit Service 653591
Packit Service 653591
The data from the native tzdata files are parsed and stored in two
Packit Service 653591
sets of modules. These include almost 500 Date::Manip::Offset::*
Packit Service 653591
modules and almost 450 Date::Manip::TZ::* modules.
Packit Service 653591
Packit Service 653591
I note that on my linux box, /usr/share/zoneinfo (which contains data
Packit Service 653591
files generated from the tzdata files) contains over 1700 files, so
Packit Service 653591
I'm not doing anything "new" by breaking up the information into
Packit Service 653591
separate files. And doing so has a huge impact on performance... it
Packit Service 653591
is not necessary to load and/or manipulate data from time zones which
Packit Service 653591
are not in use.
Packit Service 653591
Packit Service 653591
The minute I made the decision to distribute the timezone information
Packit Service 653591
myself, as opposed to using the system version, it was a given that
Packit Service 653591
there would be a lot of files.
Packit Service 653591
Packit Service 653591
These modules are loaded only when the time zone or offset is actually
Packit Service 653591
used, so, unless dates from around the world are being parsed, only a
Packit Service 653591
very small number of these modules will actually be loaded. In many
Packit Service 653591
applications, only a single TZ module will be loaded. If parsing
Packit Service 653591
dates which have timezone information stored as offsets, one or two
Packit Service 653591
Offset modules will also be loaded.
Packit Service 653591
Packit Service 653591
=item B<The disk space seems excessive>
Packit Service 653591
Packit Service 653591
Currently, the disk usage of the perl files is around 9 MB. Total disk
Packit Service 653591
usage for /usr/share/zoneinfo on my computer is around 4 MB. There are
Packit Service 653591
a couple of differences.
Packit Service 653591
Packit Service 653591
The primary difference is that the zoneinfo files are stored in a binary
Packit Service 653591
(and hence, more compressed) version, where the perl modules have all
Packit Service 653591
the data in pure text.
Packit Service 653591
Packit Service 653591
Since these are all automatically generated and used, it may be
Packit Service 653591
beneficial to store the data in some packed binary format instead of
Packit Service 653591
the fully expanded text form that is currently in use. This would
Packit Service 653591
decrease the disk space usage, and might improve performance. However,
Packit Service 653591
the performance improvement would happen only once per timezone, and
Packit Service 653591
would make for more complicated code, so I'm not very interested in
Packit Service 653591
pursuing this.
Packit Service 653591
Packit Service 653591
Another aspect of the current modules is that they all include pod
Packit Service 653591
documentation. Although not necessary, this allows users to easily
Packit Service 653591
see what modules handle which time zones, and that's nice. It also
Packit Service 653591
allows me to use pod_coverage tests for the module which is a nice
Packit Service 653591
check to make sure that the documentation is accurate.
Packit Service 653591
Packit Service 653591
All told, I don't consider the disk usage excessive at all.
Packit Service 653591
Packit Service 653591
=back
Packit Service 653591
Packit Service 653591
=head1 KNOWN PROBLEMS OR ISSUES
Packit Service 653591
Packit Service 653591
=over 4
Packit Service 653591
Packit Service 653591
=item B<Unable to determine Time Zone>
Packit Service 653591
Packit Service 653591
When using Date::Manip, when the module is initialized, it must be
Packit Service 653591
able to determine the local time zone. If it fails to do so, an
Packit Service 653591
error will occur:
Packit Service 653591
Packit Service 653591
   Unable to determine Time Zone
Packit Service 653591
Packit Service 653591
and the script will exit.
Packit Service 653591
Packit Service 653591
In the past, this was the most common problem with using Date::Manip .
Packit Service 653591
With the release of 6.00, this problem should be significantly less
Packit Service 653591
common. If you do get this error, please refer to the section above
Packit Service 653591
DETERMINING THE SYSTEM TIME ZONE for information about determining the
Packit Service 653591
local time zone. I am also interested in hearing about this so that I
Packit Service 653591
can update the default list of methods to be able to determine the
Packit Service 653591
local time zone better.
Packit Service 653591
Packit Service 653591
=item B<Asia/Jerusalem time zone>
Packit Service 653591
Packit Service 653591
The Asia/Jerusalem time zone has a non-standard way of specifying
Packit Service 653591
the start and end of Daylight Saving Time based on the Hebrew
Packit Service 653591
calendar.
Packit Service 653591
Packit Service 653591
As a result, there is no way to specify a simple rule to define
Packit Service 653591
time zone changes for all years in the future. As such, this module
Packit Service 653591
supports all time zone changes currently specified in the zoneinfo
Packit Service 653591
database (which currently goes to the year 2037) but does not attempt
Packit Service 653591
to correctly handle zone changes beyond that date. As a result,
Packit Service 653591
Date::Manip should not be used to parse dates in the Jerusalem
Packit Service 653591
time zone that are far enough in the future that information is not
Packit Service 653591
included in the current version of the zoneinfo database.
Packit Service 653591
Packit Service 653591
=item B<LMT and zzz abbreviations>
Packit Service 653591
Packit Service 653591
Both the LMT and zzz abbreviations are used in the zoneinfo databases.
Packit Service 653591
LMT is use for most time zones for the times before the Gregorian
Packit Service 653591
calendar was adopted, and zzz is used for a few where the time zone was
Packit Service 653591
created and no description of dates prior to that are supported. Both
Packit Service 653591
LMT and zzz are basically ignored in parsing dates (because there is
Packit Service 653591
no reasonable way to determine which zone they are referring to), and
Packit Service 653591
will be treated as the local time zone regardless.
Packit Service 653591
Packit Service 653591
=back
Packit Service 653591
Packit Service 653591
=head1 KNOWN BUGS
Packit Service 653591
Packit Service 653591
None known.
Packit Service 653591
Packit Service 653591
=head1 BUGS AND QUESTIONS
Packit Service 653591
Packit Service 653591
Please refer to the Date::Manip::Problems documentation for
Packit Service 653591
information on submitting bug reports or questions to the author.
Packit Service 653591
Packit Service 653591
=head1 SEE ALSO
Packit Service 653591
Packit Service 653591
Date::Manip        - main module documentation
Packit Service 653591
Packit Service 653591
=head1 LICENSE
Packit Service 653591
Packit Service 653591
This script is free software; you can redistribute it and/or
Packit Service 653591
modify it under the same terms as Perl itself.
Packit Service 653591
Packit Service 653591
=head1 AUTHOR
Packit Service 653591
Packit Service 653591
Sullivan Beck (sbeck@cpan.org)
Packit Service 653591
Packit Service 653591
=cut