← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 17:10:45 2013
Reported on Tue Oct 15 17:11:59 2013

Filename/usr/share/koha/lib/Koha/DateUtils.pm
StatementsExecuted 30 statements in 1.46ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111608µs4.97msKoha::DateUtils::::BEGIN@23Koha::DateUtils::BEGIN@23
11182µs158µsKoha::DateUtils::::BEGIN@21Koha::DateUtils::BEGIN@21
11129µs36µsKoha::DateUtils::::BEGIN@19Koha::DateUtils::BEGIN@19
11120µs22µsKoha::DateUtils::::BEGIN@22Koha::DateUtils::BEGIN@22
11117µs32µsKoha::DateUtils::::BEGIN@20Koha::DateUtils::BEGIN@20
11116µs77µsKoha::DateUtils::::BEGIN@21.9Koha::DateUtils::BEGIN@21.9
11114µs99µsKoha::DateUtils::::BEGIN@26Koha::DateUtils::BEGIN@26
11114µs38µsKoha::DateUtils::::BEGIN@27Koha::DateUtils::BEGIN@27
11112µs15µsKoha::DateUtils::::BEGIN@24Koha::DateUtils::BEGIN@24
0000s0sKoha::DateUtils::::dt_from_stringKoha::DateUtils::dt_from_string
0000s0sKoha::DateUtils::::format_sqldatetimeKoha::DateUtils::format_sqldatetime
0000s0sKoha::DateUtils::::format_sqlduedatetimeKoha::DateUtils::format_sqlduedatetime
0000s0sKoha::DateUtils::::output_prefKoha::DateUtils::output_pref
0000s0sKoha::DateUtils::::output_pref_dueKoha::DateUtils::output_pref_due
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Koha::DateUtils;
2
3# Copyright (c) 2011 PTFS-Europe Ltd.
4# This file is part of Koha.
5#
6# Koha is free software; you can redistribute it and/or modify it under the
7# terms of the GNU General Public License as published by the Free Software
8# Foundation; either version 2 of the License, or (at your option) any later
9# version.
10#
11# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along with
16# Koha; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19345µs243µs
# spent 36µs (29+7) within Koha::DateUtils::BEGIN@19 which was called: # once (29µs+7µs) by C4::Letters::BEGIN@32 at line 19
use strict;
# spent 36µs making 1 call to Koha::DateUtils::BEGIN@19 # spent 7µs making 1 call to strict::import
20353µs246µs
# spent 32µs (17+14) within Koha::DateUtils::BEGIN@20 which was called: # once (17µs+14µs) by C4::Letters::BEGIN@32 at line 20
use warnings;
# spent 32µs making 1 call to Koha::DateUtils::BEGIN@20 # spent 14µs making 1 call to warnings::import
216116µs3296µs
# spent 158µs (82+77) within Koha::DateUtils::BEGIN@21 which was called: # once (82µs+77µs) by C4::Letters::BEGIN@32 at line 21 # spent 77µs (16+61) within Koha::DateUtils::BEGIN@21.9 which was called: # once (16µs+61µs) by Koha::DateUtils::BEGIN@21 at line 21
use 5.010;
# spent 158µs making 1 call to Koha::DateUtils::BEGIN@21 # spent 77µs making 1 call to Koha::DateUtils::BEGIN@21.9 # spent 61µs making 1 call to feature::import
22333µs224µs
# spent 22µs (20+2) within Koha::DateUtils::BEGIN@22 which was called: # once (20µs+2µs) by C4::Letters::BEGIN@32 at line 22
use DateTime;
# spent 22µs making 1 call to Koha::DateUtils::BEGIN@22 # spent 2µs making 1 call to UNIVERSAL::import
233206µs24.98ms
# spent 4.97ms (608µs+4.37) within Koha::DateUtils::BEGIN@23 which was called: # once (608µs+4.37ms) by C4::Letters::BEGIN@32 at line 23
use DateTime::Format::DateParse;
# spent 4.97ms making 1 call to Koha::DateUtils::BEGIN@23 # spent 3µs making 1 call to UNIVERSAL::import
24328µs217µs
# spent 15µs (12+2) within Koha::DateUtils::BEGIN@24 which was called: # once (12µs+2µs) by C4::Letters::BEGIN@32 at line 24
use C4::Context;
# spent 15µs making 1 call to Koha::DateUtils::BEGIN@24 # spent 2µs making 1 call to C4::Context::import
25
26339µs2184µs
# spent 99µs (14+85) within Koha::DateUtils::BEGIN@26 which was called: # once (14µs+85µs) by C4::Letters::BEGIN@32 at line 26
use base 'Exporter';
# spent 99µs making 1 call to Koha::DateUtils::BEGIN@26 # spent 85µs making 1 call to base::import
274932µs380µs
# spent 38µs (14+24) within Koha::DateUtils::BEGIN@27 which was called: # once (14µs+24µs) by C4::Letters::BEGIN@32 at line 27
use version; our $VERSION = qv('1.0.0');
# spent 38µs making 1 call to Koha::DateUtils::BEGIN@27 # spent 24µs making 1 call to version::import # spent 19µs making 1 call to version::__ANON__[version.pm:47]
28
2912µsour @EXPORT = (
30 qw( dt_from_string output_pref format_sqldatetime output_pref_due format_sqlduedatetime)
31);
32
33=head1 DateUtils
34
- -
45=head2 dt_ftom_string
46
- -
54sub dt_from_string {
55 my ( $date_string, $date_format, $tz ) = @_;
56 if ( !$tz ) {
57 $tz = C4::Context->tz;
58 }
59 if ( !$date_format ) {
60 $date_format = C4::Context->preference('dateformat');
61 }
62 if ($date_string) {
63 if ( ref($date_string) eq 'DateTime' ) { # already a dt return it
64 return $date_string;
65 }
66
67 if ( $date_format eq 'metric' ) {
68 $date_string =~ s#-#/#g;
69 $date_string =~ s/^00/01/; # system allows the 0th of the month
70 $date_string =~ s#^(\d{1,2})/(\d{1,2})#$2/$1#;
71 } else {
72 if ( $date_format eq 'iso' ) {
73 $date_string =~ s/-00/-01/;
74 if ( $date_string =~ m/^0000-0/ ) {
75 return; # invalid date in db
76 }
77 } elsif ( $date_format eq 'us' ) {
78 $date_string =~ s#-#/#g;
79 $date_string =~ s[/00/][/01/];
80 } elsif ( $date_format eq 'sql' ) {
81 $date_string =~
82s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/;
83 return if ($date_string =~ /^0000-00-00/);
84 $date_string =~ s/00T/01T/;
85 }
86 }
87 return DateTime::Format::DateParse->parse_datetime( $date_string,
88 $tz->name() );
89 }
90 return DateTime->now( time_zone => $tz );
91
92}
93
94=head2 output_pref
95
- -
111sub output_pref {
112 my $dt = shift;
113 my $force_pref = shift; # if testing we want to override Context
114 my $force_time = shift;
115 my $dateonly = shift || 0; # if you don't want the hours and minutes
116
117 return unless defined $dt;
118
119 $dt->set_time_zone( C4::Context->tz );
120
121 my $pref =
122 defined $force_pref ? $force_pref : C4::Context->preference('dateformat');
123
124 my $time_format = $force_time || C4::Context->preference('TimeFormat');
125 my $time = ( $time_format eq '12hr' ) ? '%I:%M %p' : '%H:%M';
126
127 given ($pref) {
128 when (/^iso/) {
129 return $dateonly
130 ? $dt->strftime("%Y-%m-%d")
131 : $dt->strftime("%Y-%m-%d $time");
132 }
133 when (/^metric/) {
134 return $dateonly
135 ? $dt->strftime("%d/%m/%Y")
136 : $dt->strftime("%d/%m/%Y $time");
137 }
138 when (/^us/) {
139
140 return $dateonly
141 ? $dt->strftime("%m/%d/%Y")
142 : $dt->strftime("%m/%d/%Y $time");
143 }
144 default {
145 return $dateonly
146 ? $dt->strftime("%Y-%m-%d")
147 : $dt->strftime("%Y-%m-%d $time");
148 }
149
150 }
151 return;
152}
153
154=head2 output_pref_due
155
- -
168sub output_pref_due {
169 my $disp_str = output_pref(@_);
170 $disp_str =~ s/ 23:59//;
171 return $disp_str;
172}
173
174=head2 format_sqldatetime
175
- -
183sub format_sqldatetime {
184 my $str = shift;
185 my $force_pref = shift; # if testing we want to override Context
186 my $force_time = shift;
187 my $dateonly = shift;
188
189 if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
190 my $dt = dt_from_string( $str, 'sql' );
191 return q{} unless $dt;
192 $dt->truncate( to => 'minute' );
193 return output_pref( $dt, $force_pref, $force_time, $dateonly );
194 }
195 return q{};
196}
197
198=head2 format_sqlduedatetime
199
- -
207sub format_sqlduedatetime {
208 my $str = shift;
209 my $force_pref = shift; # if testing we want to override Context
210 my $force_time = shift;
211 my $dateonly = shift;
212
213 if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
214 my $dt = dt_from_string( $str, 'sql' );
215 $dt->truncate( to => 'minute' );
216 return output_pref_due( $dt, $force_pref, $force_time, $dateonly );
217 }
218 return q{};
219}
220
22115µs1;