An open API service indexing awesome lists of open source software.

https://github.com/dnmfarrell/time-tzfile


https://github.com/dnmfarrell/time-tzfile

Last synced: about 2 months ago
JSON representation

Awesome Lists containing this project

README

          

=pod

=encoding UTF-8

=head1 NAME

Time::Tzfile - read binary tzfiles into Perl data structures

=head1 VERSION

version 0.03

=head1 SYNOPSIS

use Time::Tzfile;

# get 64bit timestamps if available
my $tzdata = Time::Tzfile->parse({filename => '/usr/share/zoneinfo/Europe/London'});

# always get 32bit timestamps
my $tzdata = Time::Tzfile->parse({
filename => '/usr/share/zoneinfo/Europe/London',
use_version_one => 1,
});

# get an unassembled raw parse of the file
my $tzdata = Time::Tzfile->parse_raw({
filename => '/usr/share/zoneinfo/Europe/London'});

=head1 METHODS

=head2 parse ({filename => /path/to/tzfile, use_version_one => 1})

The C takes a hashref containing the filename of the tzfile to open
and optionally a flag to use the version one (32bit) tzfile entry. Returns an
arrayref of hashrefs:

{
epoch => 1234566789, # offset begins here
offset => 3600, # offset in seconds
type => GMT, # official abbreviation
is_dst => 0, # is daylight saving bool
}

Tzfiles can have two entries in them: the version one entry with 32bit timestamps
and the version two entry with 64bit timestamps. If the tzfile has the version
two entry, and if C is compiled with 64bit support, this method will
automatically return the version two entry. If you want to force the version one
entry, include the C flag in the method arguments.

See L<#SYNOPSIS> for examples.

N.B. AFAIK all binary tzfiles are compiled with UTC timestamps, so this method
ignores the leap, GMT and STD time entries for calculating offsets. If you
want to include them, use L<#parse_raw> as an input to your own calculations.

=head2 parse_raw ({filename => /path/to/tzfile, use_version_one => 1})

This method reads the binary file into an arrayref of arrayrefs. Use this if
you'd like to inspect the tzfile data, or use it as an input into your own
programs.

The arrayref looks like this:

[
header # version and counts for the body
transitions # historical timestamps when TZ changes occur
transition_idx # index of ttinfo structs which apply to transitions
ttinfo_structs # gmt offset, dst flag & the tz abbrev idx
tz_abbreviation # tz abbreviation string (EDT, GMT, BST etc)
leap_seconds # timestamp & offset to apply leap secs
std_wall # arrayref of std wall clock indicators
gmt_local # arrayref of gm local indicators
]

=head1 SEE ALSO

=over 4

=item * L - automatically uses text versions of the Olsen db to calculate timezone offsets

=item * L - applies TZ offsets from binary tzfiles to DateTime objects

=item * L - another module for parsing Tzfiles

=back

=head1 TZFILE FORMAT INFO

I found these resources useful guides to understanding the tzfile format

=over 4

=item * Tzfile L

=item * Very useful description of tzfile format from L

=item * Wikipedia L on the TZ database

=back

=head1 AUTHOR

David Farrell

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by David Farrell.

This is free software, licensed under:

The (two-clause) FreeBSD License

=cut