This file is indexed.

/usr/share/perl5/DateTime/TimeZone/OlsonDB.pm is in libdatetime-timezone-perl 1:2.18-1+2018d.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
package DateTime::TimeZone::OlsonDB;

use strict;
use warnings;
use namespace::autoclean;

our $VERSION = '2.18';

use DateTime::TimeZone::OlsonDB::Rule;
use DateTime::TimeZone::OlsonDB::Zone;

my $x = 1;
our %MONTHS = map { $_ => $x++ } qw( Jan Feb Mar Apr May Jun
    Jul Aug Sep Oct Nov Dec);

$x = 1;
our %DAYS = map { $_ => $x++ } qw( Mon Tue Wed Thu Fri Sat Sun );

our $PLUS_ONE_DAY_DUR  = DateTime::Duration->new( days => 1 );
our $MINUS_ONE_DAY_DUR = DateTime::Duration->new( days => -1 );

sub new {
    my $class = shift;

    return bless {
        rules => {},
        zones => {},
        links => {},
    }, $class;
}

sub parse_file {
    my $self = shift;
    my $file = shift;

    open my $fh, '<', $file
        or die "Cannot read $file: $!";

    while (<$fh>) {
        chomp;
        $self->_parse_line($_);
    }

    close $fh or die $!;
}

sub _parse_line {
    my $self = shift;
    my $line = shift;

    return if $line =~ /^\s+$/;
    return if $line =~ /^#/;

    # remove any comments at the end of the line
    $line =~ s/\s*#.+$//;

    if ( $self->{in_zone} && $line =~ /^[ \t]/ ) {
        $self->_parse_zone( $line, $self->{in_zone} );
        return;
    }

    foreach (qw( Rule Zone Link )) {
        if ( substr( $line, 0, 4 ) eq $_ ) {
            my $m = '_parse_' . lc $_;
            $self->$m($line);
        }
    }
}

## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
sub _parse_rule {
    my $self = shift;
    my $rule = shift;

    my @items = split /\s+/, $rule, 10;

    shift @items;
    my $name = shift @items;

    my %rule;
    @rule{qw( from to type in on at save letter )} = @items;
    delete $rule{letter} if $rule{letter} eq '-';

    # As of the 2003a data, there are no rules with a type set
    delete $rule{type} if $rule{type} eq '-';

    push @{ $self->{rules}{$name} },
        DateTime::TimeZone::OlsonDB::Rule->new( name => $name, %rule );

    undef $self->{in_zone};
}

sub _parse_zone {
    my $self = shift;
    my $zone = shift;
    my $name = shift;

    my $expect = $name ? 5 : 6;
    my @items = grep { defined && length } split /\s+/, $zone, $expect;

    my %obs;
    unless ($name) {
        shift @items;    # remove "Zone"
        $name = shift @items;
    }

    @obs{qw( gmtoff rules format until )} = @items;

    if ( $obs{rules} =~ /\d\d?:\d\d/ ) {
        $obs{offset_from_std} = delete $obs{rules};
    }
    else {
        delete $obs{rules} if $obs{rules} eq '-';
    }

    delete $obs{until} unless defined $obs{until};

    push @{ $self->{zones}{$name} }, \%obs;

    $self->{in_zone} = $name;
}

sub _parse_link {
    my $self = shift;
    my $link = shift;

    my @items = split /\s+/, $link, 3;

    $self->{links}{ $items[2] } = $items[1];

    undef $self->{in_zone};
}
## use critic

sub links { %{ $_[0]->{links} } }

sub zone_names { keys %{ $_[0]->{zones} } }

sub zone {
    my $self = shift;
    my $name = shift;

    die "Invalid zone name $name"
        unless exists $self->{zones}{$name};

    return DateTime::TimeZone::OlsonDB::Zone->new(
        name        => $name,
        observances => $self->{zones}{$name},
        olson_db    => $self,
    );
}

sub expanded_zone {
    my $self = shift;
    my %p    = @_;

    $p{expand_to_year} ||= (localtime)[5] + 1910;

    my $zone = $self->zone( $p{name} );

    $zone->expand_observances( $self, $p{expand_to_year} );

    return $zone;
}

sub rules_by_name {
    my $self = shift;
    my $name = shift;

    return unless defined $name;

    die "Invalid rule name $name"
        unless exists $self->{rules}{$name};

    return @{ $self->{rules}{$name} };
}

sub parse_day_spec {
    my ( $day, $month, $year ) = @_;

    return $day if $day =~ /^\d+$/;

    if ( $day =~ /^last(\w\w\w)$/ ) {
        my $dow = $DAYS{$1};

        my $last_day = DateTime->last_day_of_month(
            year      => $year,
            month     => $month,
            time_zone => 'floating',
        );

        my $dt = DateTime->new(
            year      => $year,
            month     => $month,
            day       => $last_day->day,
            time_zone => 'floating',
        );

        while ( $dt->day_of_week != $dow ) {
            $dt -= $PLUS_ONE_DAY_DUR;
        }

        return $dt->day;
    }
    elsif ( $day =~ /^(\w\w\w)([><])=(\d\d?)$/ ) {
        my $dow = $DAYS{$1};

        my $dt = DateTime->new(
            year      => $year,
            month     => $month,
            day       => $3,
            time_zone => 'floating',
        );

        my $dur = $2 eq '<' ? $MINUS_ONE_DAY_DUR : $PLUS_ONE_DAY_DUR;

        while ( $dt->day_of_week != $dow ) {
            $dt += $dur;
        }

        return $dt->day;
    }
    else {
        die "Invalid on spec for rule: $day\n";
    }
}

sub utc_datetime_for_time_spec {
    my %p = @_;

    # 'w'all - ignore it, because that's the default
    $p{spec} =~ s/w$//;

    # 'g'reenwich, 'u'tc, or 'z'ulu
    my $is_utc = $p{spec} =~ s/[guz]$//;

    # 's'tandard time - ignore DS offset
    my $is_std = $p{spec} =~ s/s$//;

    ## no critic (NamingConventions::ProhibitAmbiguousNames)
    my ( $hour, $minute, $second ) = split /:/, $p{spec};
    $minute = 0 unless defined $minute;
    $second = 0 unless defined $second;

    my $add_day = 0;
    if ( $hour == 24 ) {
        $hour    = 0;
        $add_day = 1;
    }

    my $utc;
    if ($is_utc) {
        $utc = DateTime->new(
            year      => $p{year},
            month     => $p{month},
            day       => $p{day},
            hour      => $hour,
            minute    => $minute,
            second    => $second,
            time_zone => 'floating',
        );
    }
    else {
        my $local = DateTime->new(
            year      => $p{year},
            month     => $p{month},
            day       => $p{day},
            hour      => $hour,
            minute    => $minute,
            second    => $second,
            time_zone => 'floating',
        );

        $p{offset_from_std} = 0 if $is_std;

        my $dur = DateTime::Duration->new(
            seconds => $p{offset_from_utc} + $p{offset_from_std} );

        $utc = $local - $dur;
    }

    $utc->add( days => 1 ) if $add_day;

    return $utc;
}

1;

# ABSTRACT: An object to represent an Olson time zone database

__END__

=pod

=encoding UTF-8

=head1 NAME

DateTime::TimeZone::OlsonDB - An object to represent an Olson time zone database

=head1 VERSION

version 2.18

=head1 SYNOPSIS

  none yet

=head1 DESCRIPTION

This module parses the Olson database time zone definition files and
creates various objects representing time zone data.

Each time zone is broken down into several parts.  The first piece is
an observance, which is an offset from UTC and an abbreviation.  A
single zone may contain many observances, reflecting historical
changes in that time zone over time.  An observance may also refer to
a set of rules.

Rules are named, and may apply to many different zones.  For example,
the "US" rules apply to most of the time zones in the US,
unsurprisingly.  Rules are made of an offset from standard time and a
definition of when that offset changes.  Changes can be a one time
thing, or they can recur at regular times through a span of years.

Each rule may have an associated letter, which is used to generate an
abbreviated name for the time zone, along with the offset's
abbreviation.  For example, if the offset's abbreviation is "C%sT",
and the a rule specifies the letter "S", then the abbreviation when
that rule is in effect is "CST".

=head1 USAGE

Not yet documented.  This stuff is a mess.

=head1 SUPPORT

Bugs may be submitted at L<https://github.com/houseabsolute/DateTime-TimeZone/issues>.

I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.

=head1 SOURCE

The source code repository for DateTime-TimeZone can be found at L<https://github.com/houseabsolute/DateTime-TimeZone>.

=head1 AUTHOR

Dave Rolsky <autarch@urth.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Dave Rolsky.

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

The full text of the license can be found in the
F<LICENSE> file included with this distribution.

=cut