Scroll to navigation

DateTime::TimeZone::Tzfile(3) User Contributed Perl Documentation DateTime::TimeZone::Tzfile(3)

NAME

DateTime::TimeZone::Tzfile - tzfile (zoneinfo) timezone files

SYNOPSIS

    use DateTime::TimeZone::Tzfile;
    $tz = DateTime::TimeZone::Tzfile->new(
            name => "local timezone",
            filename => "/etc/localtime");
    $tz = DateTime::TimeZone::Tzfile->new("/etc/localtime");
    if($tz->is_floating) { ...
    if($tz->is_utc) { ...
    if($tz->is_olson) { ...
    $category = $tz->category;
    $tz_string = $tz->name;
    if($tz->has_dst_changes) { ...
    if($tz->is_dst_for_datetime($dt)) { ...
    $offset = $tz->offset_for_datetime($dt);
    $abbrev = $tz->short_name_for_datetime($dt);
    $offset = $tz->offset_for_local_datetime($dt);

DESCRIPTION

An instance of this class represents a timezone that was encoded in a file in the tzfile(5) format. These can express arbitrary patterns of offsets from Universal Time, changing over time. Offsets and change times are limited to a resolution of one second.

This class implements the DateTime::TimeZone interface, so that its instances can be used with DateTime objects.

CONSTRUCTOR

Reads and parses a tzfile(5) format file, then constructs and returns a DateTime-compatible timezone object that implements the timezone encoded in the file. The following attributes may be given:
Name for the timezone object. This will be returned by the "name" method described below, and will be included in certain error messages.
The string or "undef" that will be returned by the "category" method described below. Default "undef".
The truth value that will be returned by the "is_olson" method described below. Default false.
Name of the file from which to read the timezone data. The filename must be understood by IO::File.
An IO::Handle object from which the timezone data can be read. This does not need to be a regular seekable file; it is read sequentially. After the constructor has finished, the handle can still be used to read any data that follows the timezone data.

Either a filename or filehandle must be given. If a timezone name is not given, then the filename is used instead if supplied; a timezone name must be given explicitly if no filename is given.

Simpler way to invoke the above constructor in the usual case. Only the filename is given; this will also be used as the timezone name.

METHODS

These methods are all part of the DateTime::TimeZone interface. See that class for the general meaning of these methods; the documentation below only comments on the specific behaviour of this class.

Identification

$tz->is_floating
Returns false.
$tz->is_utc
Returns false.
$tz->is_olson
Returns the truth value that was provided to the constructor for this purpose, default false. This nominally indicates whether the timezone data is from the Olson database. The files interpreted by this class are very likely to be from the Olson database, but there is no explicit indicator for this in the file, so this information must be supplied to the constructor if required.
$tz->category
Returns the value that was provided to the constructor for this purpose, default "undef". This is intended to indicate the general region (continent or ocean) in which a geographical timezone is used, when the timezone is named according to the hierarchical scheme of the Olson timezone database.
$tz->name
Returns the timezone name. Usually this is the filename that was supplied to the constructor, but it can be overridden by the constructor's name attribute.

Offsets

$tz->has_dst_changes
Returns a truth value indicating whether any of the observances in the file are marked as DST. These DST flags are potentially arbitrary, and don't affect any of the zone's behaviour.
$tz->offset_for_datetime(DT)
DT must be a DateTime-compatible object (specifically, it must implement the "utc_rd_values" method). Returns the offset from UT that is in effect at the instant represented by DT, in seconds.
$tz->is_dst_for_datetime(DT)
DT must be a DateTime-compatible object (specifically, it must implement the "utc_rd_values" method). Returns a truth value indicating whether the timezone's observance at the instant represented by DT is marked as DST. This DST flag is potentially arbitrary, and doesn't affect anything else.
$tz->short_name_for_datetime(DT)
DT must be a DateTime-compatible object (specifically, it must implement the "utc_rd_values" method). Returns the abbreviation used to label the time scale at the instant represented by DT. This abbreviation is potentially arbitrary, and does not uniquely identify either the timezone or the offset.
$tz->offset_for_local_datetime(DT)
DT must be a DateTime-compatible object (specifically, it must implement the "local_rd_values" method). Takes the local time represented by DT (regardless of what absolute time it also represents), and interprets that as a local time in the timezone of the timezone object (not the timezone used in DT). Returns the offset from UT that is in effect at that local time, in seconds.

If the local time given is ambiguous due to a nearby offset change, the numerically lowest offset (usually the standard one) is returned with no warning of the situation. (Equivalently: the latest possible absolute time is indicated.) If the local time given does not exist due to a nearby offset change, the method "die"s saying so.

SEE ALSO

DateTime, DateTime::TimeZone, DateTime::TimeZone::Olson, Time::OlsonTZ::Data, Time::OlsonTZ::Download, tzfile(5)

AUTHOR

Andrew Main (Zefram) <zefram@fysh.org>

COPYRIGHT

Copyright (C) 2007, 2009, 2010, 2011, 2012, 2013, 2017 Andrew Main (Zefram) <zefram@fysh.org>

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2021-04-07 perl v5.26.3