| Filename | /usr/share/perl5/DateTime/Format/DateParse.pm |
| Statements | Executed 14 statements in 990µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.30ms | 6.10ms | DateTime::Format::DateParse::BEGIN@14 |
| 1 | 1 | 1 | 11µs | 22µs | DateTime::Format::DateParse::BEGIN@7 |
| 1 | 1 | 1 | 8µs | 34µs | DateTime::Format::DateParse::BEGIN@15 |
| 1 | 1 | 1 | 7µs | 27µs | DateTime::Format::DateParse::BEGIN@9 |
| 1 | 1 | 1 | 6µs | 6µs | DateTime::Format::DateParse::BEGIN@13 |
| 1 | 1 | 1 | 4µs | 4µs | DateTime::Format::DateParse::BEGIN@12 |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::DateParse::parse_datetime |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Format::DateParse; | ||||
| 2 | |||||
| 3 | # Copyright (C) 2005-6 Joshua Hoblitt | ||||
| 4 | # | ||||
| 5 | # $Id: DateParse.pm 4429 2010-04-10 19:14:33Z jhoblitt $ | ||||
| 6 | |||||
| 7 | 2 | 29µs | 2 | 33µs | # spent 22µs (11+11) within DateTime::Format::DateParse::BEGIN@7 which was called:
# once (11µs+11µs) by Koha::DateUtils::BEGIN@23 at line 7 # spent 22µs making 1 call to DateTime::Format::DateParse::BEGIN@7
# spent 11µs making 1 call to strict::import |
| 8 | |||||
| 9 | 2 | 28µs | 2 | 48µs | # spent 27µs (7+20) within DateTime::Format::DateParse::BEGIN@9 which was called:
# once (7µs+20µs) by Koha::DateUtils::BEGIN@23 at line 9 # spent 27µs making 1 call to DateTime::Format::DateParse::BEGIN@9
# spent 20µs making 1 call to vars::import |
| 10 | 1 | 400ns | $VERSION = '0.05'; | ||
| 11 | |||||
| 12 | 2 | 19µs | 1 | 4µs | # spent 4µs within DateTime::Format::DateParse::BEGIN@12 which was called:
# once (4µs+0s) by Koha::DateUtils::BEGIN@23 at line 12 # spent 4µs making 1 call to DateTime::Format::DateParse::BEGIN@12 |
| 13 | 2 | 23µs | 1 | 6µs | # spent 6µs within DateTime::Format::DateParse::BEGIN@13 which was called:
# once (6µs+0s) by Koha::DateUtils::BEGIN@23 at line 13 # spent 6µs making 1 call to DateTime::Format::DateParse::BEGIN@13 |
| 14 | 2 | 672µs | 2 | 6.14ms | # spent 6.10ms (1.30+4.80) within DateTime::Format::DateParse::BEGIN@14 which was called:
# once (1.30ms+4.80ms) by Koha::DateUtils::BEGIN@23 at line 14 # spent 6.10ms making 1 call to DateTime::Format::DateParse::BEGIN@14
# spent 35µs making 1 call to Exporter::import |
| 15 | 2 | 216µs | 2 | 61µs | # spent 34µs (8+27) within DateTime::Format::DateParse::BEGIN@15 which was called:
# once (8µs+27µs) by Koha::DateUtils::BEGIN@23 at line 15 # spent 34µs making 1 call to DateTime::Format::DateParse::BEGIN@15
# spent 27µs making 1 call to Exporter::import |
| 16 | |||||
| 17 | sub parse_datetime { | ||||
| 18 | my ($class, $date, $zone) = @_; | ||||
| 19 | |||||
| 20 | # str2time() calls strptime() internally so it's more efficent to use | ||||
| 21 | # strptime() directly. However, the extra validation done by using | ||||
| 22 | # DateTime->new() instad of DateTime->from_epoch() may make it into a net | ||||
| 23 | # loss. In the end, it turns out that strptime()'s offset information is | ||||
| 24 | # needed anyways. | ||||
| 25 | my @t = strptime( $date, $zone ); | ||||
| 26 | |||||
| 27 | return undef unless @t; | ||||
| 28 | |||||
| 29 | my ($ss, $mm, $hh, $day, $month, $year, $offset) = @t; | ||||
| 30 | |||||
| 31 | my %p; | ||||
| 32 | if ( $ss ) { | ||||
| 33 | my $fraction = $ss - int( $ss ); | ||||
| 34 | if ($fraction) { | ||||
| 35 | my $nano = $fraction * 1e9; | ||||
| 36 | if ( $nano != int( $nano ) ) { | ||||
| 37 | $nano++ if $nano - int( $nano ) >= 0.5; | ||||
| 38 | } | ||||
| 39 | $p{ nanosecond } = int( $nano ); | ||||
| 40 | } | ||||
| 41 | $p{ second } = int $ss; | ||||
| 42 | } | ||||
| 43 | $p{ minute } = $mm if $mm; | ||||
| 44 | $p{ hour } = $hh if $hh; | ||||
| 45 | $p{ day } = $day if $day; | ||||
| 46 | $p{ month } = $month + 1 if $month; | ||||
| 47 | $p{ year } = $year ? $year + 1900 : DateTime->now->year; | ||||
| 48 | |||||
| 49 | # unless there is an explict ZONE, Date::Parse seems to parse date only | ||||
| 50 | # formats, eg. "1995-01-24", as being in the 'local' timezone. | ||||
| 51 | unless ( defined $zone || defined $offset ) { | ||||
| 52 | return DateTime->new( | ||||
| 53 | %p, | ||||
| 54 | time_zone => 'local', | ||||
| 55 | ); | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | if ( $zone ) { | ||||
| 59 | if ( DateTime::TimeZone->is_valid_name( $zone ) ) { | ||||
| 60 | return DateTime->new( | ||||
| 61 | %p, | ||||
| 62 | time_zone => $zone, | ||||
| 63 | ); | ||||
| 64 | } else { | ||||
| 65 | # attempt to convert Time::Zone tz's into an offset | ||||
| 66 | return DateTime->new( | ||||
| 67 | %p, | ||||
| 68 | time_zone => | ||||
| 69 | # not an Olson timezone, no DST info | ||||
| 70 | DateTime::TimeZone::offset_as_string( tz_offset( $zone ) ), | ||||
| 71 | ); | ||||
| 72 | } | ||||
| 73 | } | ||||
| 74 | |||||
| 75 | return DateTime->new( | ||||
| 76 | %p, | ||||
| 77 | time_zone => | ||||
| 78 | # not an Olson timezone, no DST info | ||||
| 79 | DateTime::TimeZone::offset_as_string( $offset ), | ||||
| 80 | ); | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | 1 | 2µs | 1; | ||
| 84 | |||||
| 85 | __END__ |