| 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 638µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 15µs | 18µs | DateTime::TimeZone::OlsonDB::Change::BEGIN@3 |
| 1 | 1 | 1 | 8µs | 12µs | DateTime::TimeZone::OlsonDB::Change::BEGIN@4 |
| 1 | 1 | 1 | 8µs | 44µs | DateTime::TimeZone::OlsonDB::Change::BEGIN@6 |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::_debug_output |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::is_dst |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::local_start_datetime |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::new |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::observance |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::offset_from_std |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::offset_from_utc |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::rule |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::short_name |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::total_offset |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::two_changes_as_span |
| 0 | 0 | 0 | 0s | 0s | DateTime::TimeZone::OlsonDB::Change::utc_start_datetime |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::TimeZone::OlsonDB::Change; | ||||
| 2 | 1 | 400ns | $DateTime::TimeZone::OlsonDB::Change::VERSION = '1.98'; | ||
| 3 | 2 | 22µs | 2 | 20µs | # spent 18µs (15+2) within DateTime::TimeZone::OlsonDB::Change::BEGIN@3 which was called:
# once (15µs+2µs) by DateTime::TimeZone::BEGIN@12 at line 3 # spent 18µs making 1 call to DateTime::TimeZone::OlsonDB::Change::BEGIN@3
# spent 2µs making 1 call to strict::import |
| 4 | 2 | 26µs | 2 | 17µs | # spent 12µs (8+5) within DateTime::TimeZone::OlsonDB::Change::BEGIN@4 which was called:
# once (8µs+5µs) by DateTime::TimeZone::BEGIN@12 at line 4 # spent 12µs making 1 call to DateTime::TimeZone::OlsonDB::Change::BEGIN@4
# spent 5µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 2 | 588µs | 2 | 80µs | # spent 44µs (8+36) within DateTime::TimeZone::OlsonDB::Change::BEGIN@6 which was called:
# once (8µs+36µs) by DateTime::TimeZone::BEGIN@12 at line 6 # spent 44µs making 1 call to DateTime::TimeZone::OlsonDB::Change::BEGIN@6
# spent 36µ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 | 3µs | 1; |