← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 10:04:38 2014
Reported on Tue Jun 24 10:05:12 2014

Filename/usr/local/share/perl/5.14.2/DateTime/TimeZone/OlsonDB/Zone.pm
StatementsExecuted 20 statements in 1.14ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.59ms1.79msDateTime::TimeZone::OlsonDB::Zone::::BEGIN@15DateTime::TimeZone::OlsonDB::Zone::BEGIN@15
111758µs833µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@14DateTime::TimeZone::OlsonDB::Zone::BEGIN@14
11112µs51µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@17DateTime::TimeZone::OlsonDB::Zone::BEGIN@17
11110µs13µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@9DateTime::TimeZone::OlsonDB::Zone::BEGIN@9
1119µs9µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@5DateTime::TimeZone::OlsonDB::Zone::BEGIN@5
1117µs39µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@18DateTime::TimeZone::OlsonDB::Zone::BEGIN@18
1117µs12µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@10DateTime::TimeZone::OlsonDB::Zone::BEGIN@10
1114µs4µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@12DateTime::TimeZone::OlsonDB::Zone::BEGIN@12
1114µs4µsDateTime::TimeZone::OlsonDB::Zone::::BEGIN@13DateTime::TimeZone::OlsonDB::Zone::BEGIN@13
0000s0sDateTime::TimeZone::OlsonDB::Zone::::add_changeDateTime::TimeZone::OlsonDB::Zone::add_change
0000s0sDateTime::TimeZone::OlsonDB::Zone::::add_infinite_ruleDateTime::TimeZone::OlsonDB::Zone::add_infinite_rule
0000s0sDateTime::TimeZone::OlsonDB::Zone::::expand_observancesDateTime::TimeZone::OlsonDB::Zone::expand_observances
0000s0sDateTime::TimeZone::OlsonDB::Zone::::infinite_rulesDateTime::TimeZone::OlsonDB::Zone::infinite_rules
0000s0sDateTime::TimeZone::OlsonDB::Zone::::last_changeDateTime::TimeZone::OlsonDB::Zone::last_change
0000s0sDateTime::TimeZone::OlsonDB::Zone::::last_rules_yearDateTime::TimeZone::OlsonDB::Zone::last_rules_year
0000s0sDateTime::TimeZone::OlsonDB::Zone::::nameDateTime::TimeZone::OlsonDB::Zone::name
0000s0sDateTime::TimeZone::OlsonDB::Zone::::newDateTime::TimeZone::OlsonDB::Zone::new
0000s0sDateTime::TimeZone::OlsonDB::Zone::::sorted_changesDateTime::TimeZone::OlsonDB::Zone::sorted_changes
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package DateTime::TimeZone::OlsonDB::Zone;
2{
321µ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
BEGIN {
617µs $DateTime::TimeZone::OlsonDB::Zone::AUTHORITY = 'cpan:DROLSKY';
7119µs19µs}
# spent 9µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@5
8
9222µs216µ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
use strict;
# spent 13µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@9 # spent 3µs making 1 call to strict::import
10221µs217µ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
use warnings;
# spent 12µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@10 # spent 5µs making 1 call to warnings::import
11
12219µs14µ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
use DateTime::TimeZone;
# spent 4µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@12
13222µs14µ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
use DateTime::TimeZone::OlsonDB;
# spent 4µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@13
142117µs1833µ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
use DateTime::TimeZone::OlsonDB::Change;
# spent 833µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@14
152127µs11.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
use DateTime::TimeZone::OlsonDB::Observance;
# spent 1.79ms making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@15
16
17235µs259µ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
use List::Util qw( first max );
# spent 51µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@17 # spent 8µs making 1 call to List::Util::import
182744µs271µ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
use Params::Validate qw( validate SCALAR ARRAYREF );
# spent 39µs making 1 call to DateTime::TimeZone::OlsonDB::Zone::BEGIN@18 # spent 32µs making 1 call to Exporter::import
19
20sub 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
40sub name { $_[0]->{name} }
41
42sub 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
55sub 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
117sub 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 print
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
169sub add_infinite_rule {
170 $_[0]->{infinite_rules}{ $_[1] } = $_[1];
171}
172
173sub last_change {
174 return unless @{ $_[0]->{changes} } || $_[0]->{earliest};
175 return (
176 @{ $_[0]->{changes} }
177 ? $_[0]->{changes}[-1]
178 : $_[0]->{earliest}
179 );
180}
181
182sub 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
190sub infinite_rules { values %{ $_[0]->{infinite_rules} } }
191
19213µs1;