Filename | /usr/share/perl5/DateTime/Format/DateParse.pm |
Statements | Executed 20 statements in 592µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 941µs | 4.17ms | BEGIN@14 | DateTime::Format::DateParse::
1 | 1 | 1 | 26µs | 32µs | BEGIN@7 | DateTime::Format::DateParse::
1 | 1 | 1 | 22µs | 70µs | BEGIN@9 | DateTime::Format::DateParse::
1 | 1 | 1 | 15µs | 16µs | BEGIN@13 | DateTime::Format::DateParse::
1 | 1 | 1 | 13µs | 15µs | BEGIN@12 | DateTime::Format::DateParse::
1 | 1 | 1 | 12µs | 58µs | BEGIN@15 | DateTime::Format::DateParse::
0 | 0 | 0 | 0s | 0s | parse_datetime | DateTime::Format::DateParse::
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 | 3 | 89µs | 2 | 38µs | # spent 32µs (26+6) within DateTime::Format::DateParse::BEGIN@7 which was called:
# once (26µs+6µs) by Koha::DateUtils::BEGIN@23 at line 7 # spent 32µs making 1 call to DateTime::Format::DateParse::BEGIN@7
# spent 6µs making 1 call to strict::import |
8 | |||||
9 | 3 | 50µs | 2 | 118µs | # spent 70µs (22+48) within DateTime::Format::DateParse::BEGIN@9 which was called:
# once (22µs+48µs) by Koha::DateUtils::BEGIN@23 at line 9 # spent 70µs making 1 call to DateTime::Format::DateParse::BEGIN@9
# spent 48µs making 1 call to vars::import |
10 | 1 | 700ns | $VERSION = '0.05'; | ||
11 | |||||
12 | 3 | 26µs | 2 | 17µs | # spent 15µs (13+2) within DateTime::Format::DateParse::BEGIN@12 which was called:
# once (13µs+2µs) by Koha::DateUtils::BEGIN@23 at line 12 # spent 15µs making 1 call to DateTime::Format::DateParse::BEGIN@12
# spent 2µs making 1 call to UNIVERSAL::import |
13 | 3 | 30µs | 2 | 17µs | # spent 16µs (15+1) within DateTime::Format::DateParse::BEGIN@13 which was called:
# once (15µs+1µs) by Koha::DateUtils::BEGIN@23 at line 13 # spent 16µs making 1 call to DateTime::Format::DateParse::BEGIN@13
# spent 1µs making 1 call to UNIVERSAL::import |
14 | 3 | 138µs | 2 | 4.23ms | # spent 4.17ms (941µs+3.23) within DateTime::Format::DateParse::BEGIN@14 which was called:
# once (941µs+3.23ms) by Koha::DateUtils::BEGIN@23 at line 14 # spent 4.17ms making 1 call to DateTime::Format::DateParse::BEGIN@14
# spent 54µs making 1 call to Exporter::import |
15 | 3 | 253µs | 2 | 103µs | # spent 58µs (12+46) within DateTime::Format::DateParse::BEGIN@15 which was called:
# once (12µs+46µs) by Koha::DateUtils::BEGIN@23 at line 15 # spent 58µs making 1 call to DateTime::Format::DateParse::BEGIN@15
# spent 46µ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 | 4µs | 1; | ||
84 | |||||
85 | __END__ |