Filename | /usr/share/perl5/DateTime/Format/DateParse.pm |
Statements | Executed 20 statements in 897µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.15ms | 4.74ms | BEGIN@14 | DateTime::Format::DateParse::
1 | 1 | 1 | 19µs | 23µs | BEGIN@7 | DateTime::Format::DateParse::
1 | 1 | 1 | 15µs | 15µs | BEGIN@13 | DateTime::Format::DateParse::
1 | 1 | 1 | 12µs | 64µs | BEGIN@15 | DateTime::Format::DateParse::
1 | 1 | 1 | 9µs | 34µs | BEGIN@9 | DateTime::Format::DateParse::
1 | 1 | 1 | 7µs | 7µs | BEGIN@12 | 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 | 31µs | 2 | 27µs | # spent 23µs (19+4) within DateTime::Format::DateParse::BEGIN@7 which was called:
# once (19µs+4µs) by Koha::DateUtils::BEGIN@23 at line 7 # spent 23µs making 1 call to DateTime::Format::DateParse::BEGIN@7
# spent 4µs making 1 call to strict::import |
8 | |||||
9 | 3 | 310µs | 2 | 59µs | # spent 34µs (9+25) within DateTime::Format::DateParse::BEGIN@9 which was called:
# once (9µs+25µs) by Koha::DateUtils::BEGIN@23 at line 9 # spent 34µs making 1 call to DateTime::Format::DateParse::BEGIN@9
# spent 25µs making 1 call to vars::import |
10 | 1 | 900ns | $VERSION = '0.05'; | ||
11 | |||||
12 | 3 | 27µs | 1 | 7µs | # spent 7µs within DateTime::Format::DateParse::BEGIN@12 which was called:
# once (7µs+0s) by Koha::DateUtils::BEGIN@23 at line 12 # spent 7µs making 1 call to DateTime::Format::DateParse::BEGIN@12 |
13 | 3 | 66µs | 1 | 15µs | # spent 15µs within DateTime::Format::DateParse::BEGIN@13 which was called:
# once (15µs+0s) by Koha::DateUtils::BEGIN@23 at line 13 # spent 15µs making 1 call to DateTime::Format::DateParse::BEGIN@13 |
14 | 3 | 186µs | 2 | 4.81ms | # spent 4.74ms (1.15+3.59) within DateTime::Format::DateParse::BEGIN@14 which was called:
# once (1.15ms+3.59ms) by Koha::DateUtils::BEGIN@23 at line 14 # spent 4.74ms making 1 call to DateTime::Format::DateParse::BEGIN@14
# spent 74µs making 1 call to Exporter::import |
15 | 3 | 271µs | 2 | 117µs | # spent 64µs (12+53) within DateTime::Format::DateParse::BEGIN@15 which was called:
# once (12µs+53µs) by Koha::DateUtils::BEGIN@23 at line 15 # spent 64µs making 1 call to DateTime::Format::DateParse::BEGIN@15
# spent 53µ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 | 5µs | 1; | ||
84 | |||||
85 | __END__ |