Filename | /usr/local/share/perl/5.14.2/DateTime/TimeZone/OlsonDB/Zone.pm |
Statements | Executed 20 statements in 1.14ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.59ms | 1.79ms | BEGIN@15 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 758µs | 833µs | BEGIN@14 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 12µs | 51µs | BEGIN@17 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 10µs | 13µs | BEGIN@9 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 9µs | 9µs | BEGIN@5 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 7µs | 39µs | BEGIN@18 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 7µs | 12µs | BEGIN@10 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 4µs | 4µs | BEGIN@12 | DateTime::TimeZone::OlsonDB::Zone::
1 | 1 | 1 | 4µs | 4µs | BEGIN@13 | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | add_change | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | add_infinite_rule | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | expand_observances | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | infinite_rules | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | last_change | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | last_rules_year | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | name | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | new | DateTime::TimeZone::OlsonDB::Zone::
0 | 0 | 0 | 0s | 0s | sorted_changes | DateTime::TimeZone::OlsonDB::Zone::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::TimeZone::OlsonDB::Zone; | ||||
2 | { | ||||
3 | 2 | 1µs | $DateTime::TimeZone::OlsonDB::Zone::VERSION = '1.63'; | ||
4 | } | ||||
5 | # spent 9µs within DateTime::TimeZone::OlsonDB::Zone::BEGIN@5 which was called:
# once (9µs+0s) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 7 | ||||
6 | 1 | 7µs | $DateTime::TimeZone::OlsonDB::Zone::AUTHORITY = 'cpan:DROLSKY'; | ||
7 | 1 | 19µs | 1 | 9µs | } # spent 9µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@5 |
8 | |||||
9 | 2 | 22µs | 2 | 16µs | # spent 13µs (10+3) within DateTime::TimeZone::OlsonDB::Zone::BEGIN@9 which was called:
# once (10µs+3µs) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 9 # spent 13µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@9
# spent 3µs making 1 call to strict::import |
10 | 2 | 21µs | 2 | 17µs | # spent 12µs (7+5) within DateTime::TimeZone::OlsonDB::Zone::BEGIN@10 which was called:
# once (7µs+5µs) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 10 # spent 12µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@10
# spent 5µs making 1 call to warnings::import |
11 | |||||
12 | 2 | 19µs | 1 | 4µs | # spent 4µs within DateTime::TimeZone::OlsonDB::Zone::BEGIN@12 which was called:
# once (4µs+0s) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 12 # spent 4µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@12 |
13 | 2 | 22µs | 1 | 4µs | # spent 4µs within DateTime::TimeZone::OlsonDB::Zone::BEGIN@13 which was called:
# once (4µs+0s) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 13 # spent 4µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@13 |
14 | 2 | 117µs | 1 | 833µs | # spent 833µs (758+74) within DateTime::TimeZone::OlsonDB::Zone::BEGIN@14 which was called:
# once (758µs+74µs) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 14 # spent 833µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@14 |
15 | 2 | 127µs | 1 | 1.79ms | # spent 1.79ms (1.59+193µs) within DateTime::TimeZone::OlsonDB::Zone::BEGIN@15 which was called:
# once (1.59ms+193µs) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 15 # spent 1.79ms making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@15 |
16 | |||||
17 | 2 | 35µs | 2 | 59µs | # spent 51µs (12+39) within DateTime::TimeZone::OlsonDB::Zone::BEGIN@17 which was called:
# once (12µs+39µs) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 17 # spent 51µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@17
# spent 8µs making 1 call to List::Util::import |
18 | 2 | 744µs | 2 | 71µs | # spent 39µs (7+32) within DateTime::TimeZone::OlsonDB::Zone::BEGIN@18 which was called:
# once (7µs+32µs) by DateTime::TimeZone::OlsonDB::BEGIN@15 at line 18 # spent 39µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@18
# spent 32µs making 1 call to Exporter::import |
19 | |||||
20 | sub new { | ||||
21 | my $class = shift; | ||||
22 | my %p = validate( | ||||
23 | @_, { | ||||
24 | name => { type => SCALAR }, | ||||
25 | observances => { type => ARRAYREF }, | ||||
26 | olson_db => 1, | ||||
27 | } | ||||
28 | ); | ||||
29 | |||||
30 | my $self = { | ||||
31 | name => $p{name}, | ||||
32 | observances => $p{observances}, | ||||
33 | changes => [], | ||||
34 | infinite_rules => {}, | ||||
35 | }; | ||||
36 | |||||
37 | return bless $self, $class; | ||||
38 | } | ||||
39 | |||||
40 | sub name { $_[0]->{name} } | ||||
41 | |||||
42 | sub last_rules_year { | ||||
43 | my $self = shift; | ||||
44 | my $odb = shift; | ||||
45 | |||||
46 | my $last_rule = $self->{observances}[-1]{rules}; | ||||
47 | |||||
48 | return unless $last_rule; | ||||
49 | |||||
50 | my @rules = $odb->rules_by_name($last_rule); | ||||
51 | |||||
52 | return $rules[-1]->min_year(); | ||||
53 | } | ||||
54 | |||||
55 | sub expand_observances { | ||||
56 | my $self = shift; | ||||
57 | my $odb = shift; | ||||
58 | my $max_year = shift; | ||||
59 | |||||
60 | my $prev_until; | ||||
61 | for ( my $x = 0; $x < @{ $self->{observances} }; $x++ ) { | ||||
62 | my %p = %{ $self->{observances}[$x] }; | ||||
63 | |||||
64 | my $rules_name = delete $p{rules}; | ||||
65 | |||||
66 | my $last_offset_from_std | ||||
67 | = $self->last_change ? $self->last_change->offset_from_std : 0; | ||||
68 | my $last_offset_from_utc | ||||
69 | = $self->last_change ? $self->last_change->offset_from_utc : 0; | ||||
70 | |||||
71 | my $obs = DateTime::TimeZone::OlsonDB::Observance->new( | ||||
72 | %p, | ||||
73 | utc_start_datetime => $prev_until, | ||||
74 | rules => [ $odb->rules_by_name($rules_name) ], | ||||
75 | last_offset_from_utc => $last_offset_from_utc, | ||||
76 | last_offset_from_std => $last_offset_from_std, | ||||
77 | ); | ||||
78 | |||||
79 | my $rule = $obs->first_rule; | ||||
80 | my $letter = $rule ? $rule->letter : ''; | ||||
81 | |||||
82 | my $change = DateTime::TimeZone::OlsonDB::Change->new( | ||||
83 | type => 'observance', | ||||
84 | utc_start_datetime => $obs->utc_start_datetime, | ||||
85 | local_start_datetime => $obs->local_start_datetime, | ||||
86 | short_name => sprintf( $obs->format, $letter ), | ||||
87 | observance => $obs, | ||||
88 | $rule ? ( rule => $rule ) : (), | ||||
89 | ); | ||||
90 | |||||
91 | if ($DateTime::TimeZone::OlsonDB::DEBUG) { | ||||
92 | print "Adding observance change ...\n"; | ||||
93 | |||||
94 | $change->_debug_output; | ||||
95 | } | ||||
96 | |||||
97 | $self->add_change($change); | ||||
98 | |||||
99 | if ( $obs->rules ) { | ||||
100 | $obs->expand_from_rules( $self, $max_year ); | ||||
101 | } | ||||
102 | |||||
103 | $prev_until = $obs->until( | ||||
104 | $self->last_change ? $self->last_change->offset_from_std : 0 ); | ||||
105 | |||||
106 | # last observance | ||||
107 | if ( $x == $#{ $self->{observances} } ) { | ||||
108 | foreach my $rule ( $obs->rules ) { | ||||
109 | if ( $rule->is_infinite ) { | ||||
110 | $self->add_infinite_rule($rule); | ||||
111 | } | ||||
112 | } | ||||
113 | } | ||||
114 | } | ||||
115 | } | ||||
116 | |||||
117 | sub add_change { | ||||
118 | my $self = shift; | ||||
119 | my $change = shift; | ||||
120 | |||||
121 | if ( defined $change->utc_start_datetime ) { | ||||
122 | if ( @{ $self->{changes} } | ||||
123 | && $self->{changes}[-1]->utc_start_datetime | ||||
124 | && $self->{changes}[-1]->utc_start_datetime | ||||
125 | == $change->utc_start_datetime ) { | ||||
126 | if ( $self->{changes}[-1]->rule && $change->observance ) { | ||||
127 | |||||
128 | " Ignoring previous rule change, that starts the same time as current observance change\n\n" | ||||
129 | if $DateTime::TimeZone::OlsonDB::DEBUG; | ||||
130 | |||||
131 | $self->{changes}[-1] = $change; | ||||
132 | |||||
133 | return; | ||||
134 | } | ||||
135 | |||||
136 | die | ||||
137 | "Cannot add two different changes that have the same UTC start datetime!\n"; | ||||
138 | } | ||||
139 | |||||
140 | my $last_change = $self->last_change; | ||||
141 | |||||
142 | if ( $last_change->short_name eq $change->short_name | ||||
143 | && $last_change->total_offset == $change->total_offset | ||||
144 | && $last_change->is_dst == $change->is_dst | ||||
145 | && $last_change->observance eq $change->observance ) { | ||||
146 | my $last_rule = $last_change->rule || ''; | ||||
147 | my $new_rule = $change->rule || ''; | ||||
148 | |||||
149 | if ( $last_rule eq $new_rule ) { | ||||
150 | print "Skipping identical change\n" | ||||
151 | if $DateTime::TimeZone::OlsonDB::DEBUG; | ||||
152 | |||||
153 | return; | ||||
154 | } | ||||
155 | } | ||||
156 | |||||
157 | push @{ $self->{changes} }, $change; | ||||
158 | } | ||||
159 | else { | ||||
160 | if ( $self->{earliest} ) { | ||||
161 | die "There can only be one earliest time zone change!"; | ||||
162 | } | ||||
163 | else { | ||||
164 | $self->{earliest} = $change; | ||||
165 | } | ||||
166 | } | ||||
167 | } | ||||
168 | |||||
169 | sub add_infinite_rule { | ||||
170 | $_[0]->{infinite_rules}{ $_[1] } = $_[1]; | ||||
171 | } | ||||
172 | |||||
173 | sub last_change { | ||||
174 | return unless @{ $_[0]->{changes} } || $_[0]->{earliest}; | ||||
175 | return ( | ||||
176 | @{ $_[0]->{changes} } | ||||
177 | ? $_[0]->{changes}[-1] | ||||
178 | : $_[0]->{earliest} | ||||
179 | ); | ||||
180 | } | ||||
181 | |||||
182 | sub sorted_changes { | ||||
183 | ( | ||||
184 | ( defined $_[0]->{earliest} ? $_[0]->{earliest} : () ), | ||||
185 | sort { $a->utc_start_datetime <=> $b->utc_start_datetime } | ||||
186 | @{ $_[0]->{changes} } | ||||
187 | ); | ||||
188 | } | ||||
189 | |||||
190 | sub infinite_rules { values %{ $_[0]->{infinite_rules} } } | ||||
191 | |||||
192 | 1 | 3µs | 1; |