← 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 11:58:52 2013
Reported on Tue Oct 15 12:01:06 2013

Filename/usr/share/koha/lib/Koha/DateUtils.pm
StatementsExecuted 30 statements in 1.34ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111825µs5.71msKoha::DateUtils::::BEGIN@23Koha::DateUtils::BEGIN@23
11171µs156µsKoha::DateUtils::::BEGIN@21Koha::DateUtils::BEGIN@21
11119µs85µsKoha::DateUtils::::BEGIN@21.7Koha::DateUtils::BEGIN@21.7
11118µs22µsKoha::DateUtils::::BEGIN@19Koha::DateUtils::BEGIN@19
11116µs89µsKoha::DateUtils::::BEGIN@26Koha::DateUtils::BEGIN@26
11115µs18µsKoha::DateUtils::::BEGIN@24Koha::DateUtils::BEGIN@24
11113µs36µsKoha::DateUtils::::BEGIN@27Koha::DateUtils::BEGIN@27
11113µs13µsKoha::DateUtils::::BEGIN@22Koha::DateUtils::BEGIN@22
11111µs24µsKoha::DateUtils::::BEGIN@20Koha::DateUtils::BEGIN@20
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
19334µs226µs
# spent 22µs (18+4) within Koha::DateUtils::BEGIN@19 which was called: # once (18µs+4µs) by C4::Letters::BEGIN@32 at line 19
use strict;
# spent 22µs making 1 call to Koha::DateUtils::BEGIN@19 # spent 4µs making 1 call to strict::import
20326µs237µs
# spent 24µs (11+13) within Koha::DateUtils::BEGIN@20 which was called: # once (11µs+13µs) by C4::Letters::BEGIN@32 at line 20
use warnings;
# spent 24µs making 1 call to Koha::DateUtils::BEGIN@20 # spent 13µs making 1 call to warnings::import
216114µs3308µs
# spent 156µs (71+85) within Koha::DateUtils::BEGIN@21 which was called: # once (71µs+85µs) by C4::Letters::BEGIN@32 at line 21 # spent 85µs (19+66) within Koha::DateUtils::BEGIN@21.7 which was called: # once (19µs+66µs) by Koha::DateUtils::BEGIN@21 at line 21
use 5.010;
# spent 156µs making 1 call to Koha::DateUtils::BEGIN@21 # spent 85µs making 1 call to Koha::DateUtils::BEGIN@21.7 # spent 66µs making 1 call to feature::import
22331µs113µs
# spent 13µs within Koha::DateUtils::BEGIN@22 which was called: # once (13µs+0s) by C4::Letters::BEGIN@32 at line 22
use DateTime;
# spent 13µs making 1 call to Koha::DateUtils::BEGIN@22
233142µs15.71ms
# spent 5.71ms (825µs+4.88) within Koha::DateUtils::BEGIN@23 which was called: # once (825µs+4.88ms) by C4::Letters::BEGIN@32 at line 23
use DateTime::Format::DateParse;
# spent 5.71ms making 1 call to Koha::DateUtils::BEGIN@23
24333µs222µs
# spent 18µs (15+3) within Koha::DateUtils::BEGIN@24 which was called: # once (15µs+3µs) by C4::Letters::BEGIN@32 at line 24
use C4::Context;
# spent 18µs making 1 call to Koha::DateUtils::BEGIN@24 # spent 3µs making 1 call to C4::Context::import
25
26337µs2163µs
# spent 89µs (16+74) within Koha::DateUtils::BEGIN@26 which was called: # once (16µs+74µs) by C4::Letters::BEGIN@32 at line 26
use base 'Exporter';
# spent 89µs making 1 call to Koha::DateUtils::BEGIN@26 # spent 74µs making 1 call to base::import
274911µs378µs
# spent 36µs (13+23) within Koha::DateUtils::BEGIN@27 which was called: # once (13µs+23µs) by C4::Letters::BEGIN@32 at line 27
use version; our $VERSION = qv('1.0.0');
# spent 36µs making 1 call to Koha::DateUtils::BEGIN@27 # spent 23µs making 1 call to version::import # spent 18µ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;