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