Profile of DateTime/TimeZone/OlsonDB/Change.pm

← Index
NYTProf Performance Profile «line view»
For -e
Run on Thu Jun 30 16:16:00 2016
Reported on Thu Jun 30 16:16:08 2016

Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/DateTime/TimeZone/OlsonDB/Change.pm
Statements | Executed 8 statements in 918µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 22µs | 26µs | DateTime::TimeZone::OlsonDB::Change::::BEGIN@3DateTime::TimeZone::OlsonDB::Change::BEGIN@3
1 | 1 | 1 | 13µs | 20µs | DateTime::TimeZone::OlsonDB::Change::::BEGIN@4DateTime::TimeZone::OlsonDB::Change::BEGIN@4
1 | 1 | 1 | 11µs | 68µs | DateTime::TimeZone::OlsonDB::Change::::BEGIN@6DateTime::TimeZone::OlsonDB::Change::BEGIN@6
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::_debug_outputDateTime::TimeZone::OlsonDB::Change::_debug_output
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::is_dstDateTime::TimeZone::OlsonDB::Change::is_dst
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::local_start_datetimeDateTime::TimeZone::OlsonDB::Change::local_start_datetime
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::newDateTime::TimeZone::OlsonDB::Change::new
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::observanceDateTime::TimeZone::OlsonDB::Change::observance
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::offset_from_stdDateTime::TimeZone::OlsonDB::Change::offset_from_std
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::offset_from_utcDateTime::TimeZone::OlsonDB::Change::offset_from_utc
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::ruleDateTime::TimeZone::OlsonDB::Change::rule
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::short_nameDateTime::TimeZone::OlsonDB::Change::short_name
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::total_offsetDateTime::TimeZone::OlsonDB::Change::total_offset
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::two_changes_as_spanDateTime::TimeZone::OlsonDB::Change::two_changes_as_span
0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::::utc_start_datetimeDateTime::TimeZone::OlsonDB::Change::utc_start_datetime

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package DateTime::TimeZone::OlsonDB::Change;
2 | 1 | 700ns |  |  | $DateTime::TimeZone::OlsonDB::Change::VERSION = '1.98';
3 | 2 | 32µs | 2 | 30µs | # spent 26µs (22+3) within DateTime::TimeZone::OlsonDB::Change::BEGIN@3 which was called: # once (22µs+3µs) by DateTime::TimeZone::BEGIN@12 at line 3 use strict; # spent 26µs making 1 call to DateTime::TimeZone::OlsonDB::Change::BEGIN@3 # spent 4µs making 1 call to strict::import
4 | 2 | 35µs | 2 | 27µs | # spent 20µs (13+7) within DateTime::TimeZone::OlsonDB::Change::BEGIN@4 which was called: # once (13µs+7µs) by DateTime::TimeZone::BEGIN@12 at line 4 use warnings; # spent 20µs making 1 call to DateTime::TimeZone::OlsonDB::Change::BEGIN@4 # spent 7µs making 1 call to warnings::import
5 |  |  |  |  |
6 | 2 | 846µs | 2 | 124µs | # spent 68µs (11+56) within DateTime::TimeZone::OlsonDB::Change::BEGIN@6 which was called: # once (11µs+56µs) by DateTime::TimeZone::BEGIN@12 at line 6 use Params::Validate qw( validate SCALAR UNDEF OBJECT ); # spent 68µs making 1 call to DateTime::TimeZone::OlsonDB::Change::BEGIN@6 # spent 56µs making 1 call to Exporter::import
7 |  |  |  |  |
8 |  |  |  |  | sub new {
9 |  |  |  |  | my $class = shift;
10 |  |  |  |  | my %p = validate(
11 |  |  |  |  | @_, {
12 |  |  |  |  | utc_start_datetime => { type => UNDEF | OBJECT },
13 |  |  |  |  | local_start_datetime => { type => UNDEF | OBJECT },
14 |  |  |  |  | short_name => { type => SCALAR },
15 |  |  |  |  | observance => { type => OBJECT },
16 |  |  |  |  | rule => { type => OBJECT, default => undef },
17 |  |  |  |  | type => {
18 |  |  |  |  | type => SCALAR,
19 |  |  |  |  | regex => qr/^(?:observance|rule)$/
20 |  |  |  |  | },
21 |  |  |  |  | }
22 |  |  |  |  | );
23 |  |  |  |  |
24 |  |  |  |  | # These are almost always mutually exclusive, except when adding
25 |  |  |  |  | # an observance change and the last rule has no offset, but the
26 |  |  |  |  | # new observance has an anonymous rule. In that case, prefer the
27 |  |  |  |  | # offset from std defined in the observance to that in the
28 |  |  |  |  | # previous rule (what a mess!).
29 |  |  |  |  | if ( $p{type} eq 'observance' ) {
30 |  |  |  |  | $p{offset_from_std} = $p{rule}->offset_from_std if defined $p{rule};
31 |  |  |  |  | $p{offset_from_std} = $p{observance}->offset_from_std
32 |  |  |  |  | if $p{observance}->offset_from_std;
33 |  |  |  |  | $p{offset_from_std} ||= 0;
34 |  |  |  |  | }
35 |  |  |  |  | else {
36 |  |  |  |  | $p{offset_from_std} = $p{observance}->offset_from_std;
37 |  |  |  |  | $p{offset_from_std} = $p{rule}->offset_from_std if defined $p{rule};
38 |  |  |  |  | }
39 |  |  |  |  |
40 |  |  |  |  | $p{offset_from_utc} = $p{observance}->offset_from_utc;
41 |  |  |  |  |
42 |  |  |  |  | $p{is_dst} = 0;
43 |  |  |  |  | $p{is_dst} = 1 if $p{rule} && $p{rule}->offset_from_std;
44 |  |  |  |  | $p{is_dst} = 1 if $p{observance}->offset_from_std;
45 |  |  |  |  |
46 |  |  |  |  | if ( $p{short_name} =~ m{([\-\+\w]+)/([\-\+\w]+)} ) {
47 |  |  |  |  | $p{short_name} = $p{is_dst} ? $2 : $1;
48 |  |  |  |  | }
49 |  |  |  |  |
50 |  |  |  |  | return bless \%p, $class;
51 |  |  |  |  | }
52 |  |  |  |  |
53 |  |  |  |  | sub utc_start_datetime { $_[0]->{utc_start_datetime} }
54 |  |  |  |  | sub local_start_datetime { $_[0]->{local_start_datetime} }
55 |  |  |  |  | sub short_name { $_[0]->{short_name} }
56 |  |  |  |  | sub is_dst { $_[0]->{is_dst} }
57 |  |  |  |  | sub observance { $_[0]->{observance} }
58 |  |  |  |  | sub rule { $_[0]->{rule} }
59 |  |  |  |  | sub offset_from_utc { $_[0]->{offset_from_utc} }
60 |  |  |  |  | sub offset_from_std { $_[0]->{offset_from_std} }
61 |  |  |  |  | sub total_offset { $_[0]->offset_from_utc + $_[0]->offset_from_std }
62 |  |  |  |  |
63 |  |  |  |  | sub two_changes_as_span {
64 |  |  |  |  | my ( $c1, $c2, $last_total_offset ) = @_;
65 |  |  |  |  |
66 |  |  |  |  | my ( $utc_start, $local_start );
67 |  |  |  |  |
68 |  |  |  |  | if ( defined $c1->utc_start_datetime ) {
69 |  |  |  |  | $utc_start = $c1->utc_start_datetime->utc_rd_as_seconds;
70 |  |  |  |  | $local_start = $c1->local_start_datetime->utc_rd_as_seconds;
71 |  |  |  |  | }
72 |  |  |  |  | else {
73 |  |  |  |  | $utc_start = $local_start = '-inf';
74 |  |  |  |  | }
75 |  |  |  |  |
76 |  |  |  |  | my $utc_end = $c2->utc_start_datetime->utc_rd_as_seconds;
77 |  |  |  |  | my $local_end = $utc_end + $c1->total_offset;
78 |  |  |  |  |
79 |  |  |  |  | return {
80 |  |  |  |  | utc_start => $utc_start,
81 |  |  |  |  | utc_end => $utc_end,
82 |  |  |  |  | local_start => $local_start,
83 |  |  |  |  | local_end => $local_end,
84 |  |  |  |  | short_name => $c1->short_name,
85 |  |  |  |  | offset => $c1->total_offset,
86 |  |  |  |  | is_dst => $c1->is_dst,
87 |  |  |  |  | };
88 |  |  |  |  | }
89 |  |  |  |  |
90 |  |  |  |  | sub _debug_output {
91 |  |  |  |  | my $self = shift;
92 |  |  |  |  |
93 |  |  |  |  | my $obs = $self->observance;
94 |  |  |  |  |
95 |  |  |  |  | if ( $self->utc_start_datetime ) {
96 |  |  |  |  | print " UTC: ", $self->utc_start_datetime->datetime, "\n";
97 |  |  |  |  | print " Local: ", $self->local_start_datetime->datetime, "\n";
98 |  |  |  |  | }
99 |  |  |  |  | else {
100 |  |  |  |  | print " First change (starts at -inf)\n";
101 |  |  |  |  | }
102 |  |  |  |  |
103 |  |  |  |  | print " Short name: ", $self->short_name, "\n";
104 |  |  |  |  | print " UTC offset: ", $obs->offset_from_utc, "\n";
105 |  |  |  |  |
106 |  |  |  |  | if ( $obs->offset_from_std || $self->rule ) {
107 |  |  |  |  | if ( $obs->offset_from_std ) {
108 |  |  |  |  | print " Std offset: ", $obs->offset_from_std, "\n";
109 |  |  |  |  | }
110 |  |  |  |  |
111 |  |  |  |  | if ( $self->rule ) {
112 |  |  |  |  | print " Std offset: ", $self->rule->offset_from_std, ' - ',
113 |  |  |  |  | $self->rule->name, " rule\n";
114 |  |  |  |  | }
115 |  |  |  |  | }
116 |  |  |  |  | else {
117 |  |  |  |  | print " Std offset: 0 - no rule\n";
118 |  |  |  |  | }
119 |  |  |  |  |
120 |  |  |  |  | print "\n";
121 |  |  |  |  | }
122 |  |  |  |  |
123 | 1 | 4µs |  |  | 1;