← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 19:05:14 2015
Reported on Fri Jul 31 19:08:10 2015

Filename/var/www/foswiki11/lib/Foswiki/Plugins/TimeCalcPlugin.pm
StatementsExecuted 56 statements in 1.75ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.83ms7.49msFoswiki::Plugins::TimeCalcPlugin::::BEGIN@39Foswiki::Plugins::TimeCalcPlugin::BEGIN@39
11141µs134µsFoswiki::Plugins::TimeCalcPlugin::::initPluginFoswiki::Plugins::TimeCalcPlugin::initPlugin
21138µs858µsFoswiki::Plugins::TimeCalcPlugin::::_TIMESHOWSTOREFoswiki::Plugins::TimeCalcPlugin::_TIMESHOWSTORE
11116µs41µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@38Foswiki::Plugins::TimeCalcPlugin::BEGIN@38
11114µs27µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@33Foswiki::Plugins::TimeCalcPlugin::BEGIN@33
11112µs15µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@227Foswiki::Plugins::TimeCalcPlugin::BEGIN@227
11112µs14µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@460Foswiki::Plugins::TimeCalcPlugin::BEGIN@460
1119µs15µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@34Foswiki::Plugins::TimeCalcPlugin::BEGIN@34
1114µs4µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@36Foswiki::Plugins::TimeCalcPlugin::BEGIN@36
1114µs4µsFoswiki::Plugins::TimeCalcPlugin::::BEGIN@37Foswiki::Plugins::TimeCalcPlugin::BEGIN@37
0000s0sFoswiki::Plugins::TimeCalcPlugin::::_ADDWORKINGDAYSFoswiki::Plugins::TimeCalcPlugin::_ADDWORKINGDAYS
0000s0sFoswiki::Plugins::TimeCalcPlugin::::_CALENDARDAYSFoswiki::Plugins::TimeCalcPlugin::_CALENDARDAYS
0000s0sFoswiki::Plugins::TimeCalcPlugin::::_WORKINGDAYSFoswiki::Plugins::TimeCalcPlugin::_WORKINGDAYS
0000s0sFoswiki::Plugins::TimeCalcPlugin::::_loadWorkingDaysFoswiki::Plugins::TimeCalcPlugin::_loadWorkingDays
0000s0sFoswiki::Plugins::TimeCalcPlugin::::_returnNoonOfDateFoswiki::Plugins::TimeCalcPlugin::_returnNoonOfDate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
2#
3# Copyright (C) 2010 Kenneth Lavrsen, kenneth@lavrsen.dk
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version 2
8# of the License, or (at your option) any later version. For
9# more details read LICENSE in the root of this distribution.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14#
15# For licensing info read LICENSE file in the Foswiki root.
16
17=pod
18
19---+ package TimeCalcPlugin
20
21__NOTE:__ When writing handlers, keep in mind that these may be invoked
22on included topics. For example, if a plugin generates links to the current
23topic, these need to be generated before the afterCommonTagsHandler is run,
24as at that point in the rendering loop we have lost the information that we
25the text had been included from another topic.
26
27=cut
28
29package Foswiki::Plugins::TimeCalcPlugin;
30
31
32# Always use strict to enforce variable scoping
33228µs240µs
# spent 27µs (14+13) within Foswiki::Plugins::TimeCalcPlugin::BEGIN@33 which was called: # once (14µs+13µs) by Foswiki::Plugin::BEGIN@2.34 at line 33
use strict;
# spent 27µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@33 # spent 13µs making 1 call to strict::import
34228µs220µs
# spent 15µs (9+5) within Foswiki::Plugins::TimeCalcPlugin::BEGIN@34 which was called: # once (9µs+5µs) by Foswiki::Plugin::BEGIN@2.34 at line 34
use warnings;
# spent 15µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@34 # spent 5µs making 1 call to warnings::import
35
36219µs14µs
# spent 4µs within Foswiki::Plugins::TimeCalcPlugin::BEGIN@36 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.34 at line 36
use Foswiki::Func (); # The plugins API
# spent 4µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@36
37220µs14µs
# spent 4µs within Foswiki::Plugins::TimeCalcPlugin::BEGIN@37 which was called: # once (4µs+0s) by Foswiki::Plugin::BEGIN@2.34 at line 37
use Foswiki::Plugins (); # For the API version
# spent 4µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@37
38229µs266µs
# spent 41µs (16+25) within Foswiki::Plugins::TimeCalcPlugin::BEGIN@38 which was called: # once (16µs+25µs) by Foswiki::Plugin::BEGIN@2.34 at line 38
use Time::Local;
# spent 41µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@38 # spent 25µs making 1 call to Exporter::import
392667µs17.49ms
# spent 7.49ms (4.83+2.66) within Foswiki::Plugins::TimeCalcPlugin::BEGIN@39 which was called: # once (4.83ms+2.66ms) by Foswiki::Plugin::BEGIN@2.34 at line 39
use Time::ParseDate (); # For relative dates
# spent 7.49ms making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@39
40
41# $VERSION is referred to by Foswiki, and is the only global variable that
42# *must* exist in this package. This should always be in the format
43# $Rev: 10080 (2010-11-26) $ so that Foswiki can determine the checked-in status of the
44# extension.
451600nsour $VERSION = '1,5';
46
47# $RELEASE is used in the "Find More Extensions" automation in configure.
48# It is a manually maintained string used to identify functionality steps.
49# You can use any of the following formats:
50# tuple - a sequence of integers separated by . e.g. 1.2.3. The numbers
51# usually refer to major.minor.patch release or similar. You can
52# use as many numbers as you like e.g. '1' or '1.2.3.4.5'.
53# isodate - a date in ISO8601 format e.g. 2009-08-07
54# date - a date in 1 Jun 2009 format. Three letter English month names only.
55# Note: it's important that this string is exactly the same in the extension
56# topic - if you use %$RELEASE% with BuildContrib this is done automatically.
571200nsour $RELEASE = '1.5';
58
59# Short description of this plugin
60# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
611300nsour $SHORTDESCRIPTION = 'Perform calculations on time and dates';
62
63# You must set $NO_PREFS_IN_TOPIC to 0 if you want your plugin to use
64# preferences set in the plugin topic. This is required for compatibility
65# with older plugins, but imposes a significant performance penalty, and
66# is not recommended. Instead, leave $NO_PREFS_IN_TOPIC at 1 and use
67# =$Foswiki::cfg= entries, or if you want the users
68# to be able to change settings, then use standard Foswiki preferences that
69# can be defined in your %USERSWEB%.SitePreferences and overridden at the web
70# and topic level.
71#
72# %SYSTEMWEB%.DevelopingPlugins has details of how to define =$Foswiki::cfg=
73# entries so they can be used with =configure=.
741100nsour $NO_PREFS_IN_TOPIC = 1;
75
76# Storage hash for the user defined variables
771200nsmy %storage;
78
79# hash of working days
8010smy %workingDays;
81
82=begin TML
83
84---++ initPlugin($topic, $web, $user) -> $boolean
85 * =$topic= - the name of the topic in the current CGI query
86 * =$web= - the name of the web in the current CGI query
87 * =$user= - the login name of the user
88 * =$installWeb= - the name of the web the plugin topic is in
89 (usually the same as =$Foswiki::cfg{SystemWebName}=)
90
91*REQUIRED*
92
93Called to initialise the plugin. If everything is OK, should return
94a non-zero value. On non-fatal failure, should write a message
95using =Foswiki::Func::writeWarning= and return 0. In this case
96%<nop>FAILEDPLUGINS% will indicate which plugins failed.
97
98In the case of a catastrophic failure that will prevent the whole
99installation from working safely, this handler may use 'die', which
100will be trapped and reported in the browser.
101
102__Note:__ Please align macro names with the Plugin name, e.g. if
103your Plugin is called !FooBarPlugin, name macros FOOBAR and/or
104FOOBARSOMETHING. This avoids namespace issues.
105
106=cut
107
108
# spent 134µs (41+92) within Foswiki::Plugins::TimeCalcPlugin::initPlugin which was called: # once (41µs+92µs) by Foswiki::Plugin::__ANON__[/var/www/foswiki11/lib/Foswiki/Plugin.pm:241] at line 234 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
sub initPlugin {
10912µs my( $topic, $web, $user, $installWeb ) = @_;
110
111 # check for Plugins.pm versions
112115µs18µs if ( $Foswiki::Plugins::VERSION < 2.0 ) {
# spent 8µs making 1 call to version::vxs::VCMP
113 Foswiki::Func::writeWarning( 'Version mismatch between ',
114 __PACKAGE__, ' and Plugins.pm' );
115 return 0;
116 }
117
11815µs126µs Foswiki::Func::registerTagHandler( 'WORKINGDAYS', \&_WORKINGDAYS );
# spent 26µs making 1 call to Foswiki::Func::registerTagHandler
11915µs120µs Foswiki::Func::registerTagHandler( 'ADDWORKINGDAYS', \&_ADDWORKINGDAYS );
# spent 20µs making 1 call to Foswiki::Func::registerTagHandler
12014µs120µs Foswiki::Func::registerTagHandler( 'TIMESHOWSTORE', \&_TIMESHOWSTORE );
# spent 20µs making 1 call to Foswiki::Func::registerTagHandler
12112µs118µs Foswiki::Func::registerTagHandler( 'CALENDARDAYS', \&_CALENDARDAYS );
# spent 18µs making 1 call to Foswiki::Func::registerTagHandler
122
123 # Plugin correctly initialized
12415µs return 1;
125}
126
127sub _returnNoonOfDate {
128 my ( $indate ) = @_;
129
130 my ( $sec, $min, $hour, $day, $mon, $year, $wday, $yday ) = gmtime($indate);
131 return timegm( 0, 0, 12, $day, $mon, $year );
132}
133
134sub _loadWorkingDays {
135 # We assume there is at least one working day in a week so no empty string
136 my $config = Foswiki::Func::getPreferencesValue('TIMECALCPLUGIN_WORKINGDAYS') ||
137 $Foswiki::cfg{TimeCalcPlugin}{WorkingDays} ||
138 "Monday, Tuesday, Wednesday, Thursday, Friday";
139 my $i = 0;
140 my $count = 0;
141 my @weekdays = ( 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
142 'Thursday', 'Friday', 'Saturday' );
143 foreach my $weekday ( @weekdays) {
144 $workingDays{ $i } = $config =~ /$weekday/i;
145 $count++ if $workingDays{ $i };
146 $i++;
147 }
148 $workingDays{ 'count' } = $count;
149 return 1;
150}
151
152sub _WORKINGDAYS {
153 my($session, $params, $theTopic, $theWeb) = @_;
154 # $session - a reference to the Foswiki session object
155 # (you probably won't need it, but documented in Foswiki.pm)
156 # $params= - a reference to a Foswiki::Attrs object containing
157 # parameters.
158 # This can be used as a simple hash that maps parameter names
159 # to values, with _DEFAULT being the name for the default
160 # (unnamed) parameter.
161 # $topic - name of the topic in the query
162 # $web - name of the web in the query
163 # $topicObject - a reference to a Foswiki::Meta object containing the
164 # topic the macro is being rendered in (new for foswiki 1.1.x)
165 # Return: the result of processing the macro. This will replace the
166 # macro call in the final text.
167
168 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
169 # $params->{_DEFAULT} will be 'hamburger'
170 # $params->{sideorder} will be 'onions'
171
172 # We load $workingDays if this is first time we run
173 _loadWorkingDays() unless defined $workingDays{ 0 };
174
175 # To do - we need to be able to also accept serialized date
176 my $startdate = $params->{startdate};
177 if ( defined $startdate ) {
178 if ( $startdate =~ /^\s*\$(\w+)/ ) {
179 # if storage does exist the startdate is undefined
180 $startdate = $storage{ $1 };
181 $startdate = _returnNoonOfDate( $startdate ) if defined $startdate;
182 }
183 else {
184 $startdate = _returnNoonOfDate( Foswiki::Time::parseTime( $startdate ) );
185 }
186 }
187 $startdate = _returnNoonOfDate( time() ) unless defined $startdate;
188
189 my $enddate = $params->{enddate};
190 if ( defined $enddate ) {
191 if ( $enddate =~ /^\s*\$(\w+)/ ) {
192 # if storage does exist the startdate is undefined
193 $enddate = $storage{ $1 };
194 $enddate = _returnNoonOfDate( $enddate ) if defined $enddate;
195 }
196 else {
197 $enddate = _returnNoonOfDate( Foswiki::Time::parseTime( $enddate ) );
198 }
199 }
200 $enddate = _returnNoonOfDate( time() ) unless defined $enddate;
201
202 my $holidaysin = defined $params->{holidays} ? $params->{holidays} :
203 ( Foswiki::Func::getPreferencesValue('TIMECALCPLUGIN_HOLIDAYS') || '' );
204
205 my $includestart = defined $params->{includestart} ?
206 Foswiki::Func::isTrue( $params->{includestart} ) : 0;
207 my $includeend = defined $params->{includeend} ?
208 Foswiki::Func::isTrue( $params->{includeend} ) : 1;
209 my $storageBin = $params->{store};
210
211 # To do - we need to be able to also accept serialized date
212 my %holidays = ();
213 if ( $holidaysin ) {
214 foreach my $holiday ( split( /\s*,\s*/, $holidaysin ) ) {
215 $holidays{ _returnNoonOfDate( Foswiki::Time::parseTime( $holiday ) ) } = 1;
216 }
217 }
218
219 # Calculate working days between two times.
220 # Times are standard system times (secs since 1970).
221 # Working days are Monday through Friday (sorry, Israel!)
222 # A day has 60 * 60 * 24 = 86400 sec. There can be exceptions to this
223 # by a few seconds but in practical life it should be OK.
224
225 # We allow the two dates to be swapped around
226 ( $startdate, $enddate ) = ( $enddate, $startdate ) if ( $startdate > $enddate );
2272811µs217µs
# spent 15µs (12+2) within Foswiki::Plugins::TimeCalcPlugin::BEGIN@227 which was called: # once (12µs+2µs) by Foswiki::Plugin::BEGIN@2.34 at line 227
use integer;
# spent 15µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@227 # spent 2µs making 1 call to integer::import
228 $startdate -= 86400 if $includestart;
229 $enddate -= 86400 unless $includeend;
230 my $elapsed_days = int( ( $enddate - $startdate ) / 86400 );
231 my $whole_weeks = int( $elapsed_days / 7 );
232 my $extra_days = $elapsed_days - ( $whole_weeks * 7 );
233 my $work_days = $elapsed_days -
234 ( $whole_weeks * ( 7 - $workingDays{ 'count' } ) );
235
236 for ( my $i = 0 ; $i < $extra_days ; $i++ ) {
237 my $tempwday = ( gmtime( $enddate - $i * 86400 ) )[6];
238 if ( !$workingDays{ $tempwday } ) {
239 $work_days--;
240 }
241 }
242
243 foreach my $holiday ( keys %holidays ) {
244 my $weekday = ( gmtime( $holiday ) )[6];
245 if ( $holiday >= $startdate && $holiday <= $enddate &&
246 $workingDays{ $weekday } ) {
247 $work_days--;
248 }
249 }
250
251 return $work_days;
252
253}
254
255sub _ADDWORKINGDAYS {
256 my($session, $params, $theTopic, $theWeb) = @_;
257 # $session - a reference to the Foswiki session object
258 # (you probably won't need it, but documented in Foswiki.pm)
259 # $params= - a reference to a Foswiki::Attrs object containing
260 # parameters.
261 # This can be used as a simple hash that maps parameter names
262 # to values, with _DEFAULT being the name for the default
263 # (unnamed) parameter.
264 # $topic - name of the topic in the query
265 # $web - name of the web in the query
266 # $topicObject - a reference to a Foswiki::Meta object containing the
267 # topic the macro is being rendered in (new for foswiki 1.1.x)
268 # Return: the result of processing the macro. This will replace the
269 # macro call in the final text.
270
271 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
272 # $params->{_DEFAULT} will be 'hamburger'
273 # $params->{sideorder} will be 'onions'
274
275 # We load $workingDays if this is first time we run
276 _loadWorkingDays() unless defined $workingDays{ 0 };
277
278 my $formatString = defined $params->{_DEFAULT} ?
279 $params->{_DEFAULT} :
280 $Foswiki::cfg{DefaultDateFormat};
281
282 my $delta = defined $params->{delta} ? $params->{delta} : 0;
283 my $direction = $delta < 0 ? -1 : 1;
284
285 my $dateString = $params->{date};
286
287 my $date = undef;
288
289 if ( defined $dateString ) {
290 my $tmpdate = undef;
291 foreach my $indate ( split( /\s*,\s*/, $dateString ) ) {
292 if ( $indate =~ /^\s*\$(\w+)/ ) {
293 # If storage does not exist it is ignorred
294 $tmpdate = _returnNoonOfDate( $storage{ $1 } )
295 if defined $storage{ $1 };
296 }
297 else {
298 # If parseTime cannot understand the input it returns undef
299 $tmpdate = _returnNoonOfDate( Foswiki::Time::parseTime( $indate ) );
300 }
301
302 # Choose date that creates the critical path
303 if ( defined $date ) {
304 $date = $direction * $date > $direction * $tmpdate ?
305 $date : $tmpdate;
306 }
307 else {
308 $date = $tmpdate;
309 }
310 }
311 }
312
313 # If none of the dates or $strings could be turned into dates
314 # above, we default the date to today
315 $date = _returnNoonOfDate( time() ) unless defined $date;
316
317 my $holidaysin = defined $params->{holidays} ?
318 $params->{holidays} : '';
319 my $storageBin = $params->{store};
320
321
322 # We put holidays in a hash instead of array to prune out duplicates
323 my %holidays = ();
324 if ( $holidaysin ) {
325 foreach my $holiday ( split( /\s*,\s*/, $holidaysin ) ) {
326 $holidays{ _returnNoonOfDate( Foswiki::Time::parseTime( $holiday ) ) } = 1;
327 }
328 }
329
330 while ( $delta !=0 ) {
331 $date += $direction * 86400;
332
333 my $tempwday = ( gmtime( $date ) )[6];
334 if ( $workingDays{ $tempwday } && !$holidays{ $date } ) {
335 $delta -= $direction;
336 }
337 }
338
339 $storage{ $storageBin } = $date if defined $storageBin;
340
341 return Foswiki::Time::formatTime($date, $formatString, gmtime);
342}
343
344
# spent 858µs (38+820) within Foswiki::Plugins::TimeCalcPlugin::_TIMESHOWSTORE which was called 2 times, avg 429µs/call: # 2 times (38µs+820µs) by Foswiki::Func::__ANON__[/var/www/foswiki11/lib/Foswiki/Func.pm:611] at line 609 of /var/www/foswiki11/lib/Foswiki/Func.pm, avg 429µs/call
sub _TIMESHOWSTORE {
34522µs my($session, $params, $theTopic, $theWeb) = @_;
346 # $session - a reference to the Foswiki session object
347 # (you probably won't need it, but documented in Foswiki.pm)
348 # $params= - a reference to a Foswiki::Attrs object containing
349 # parameters.
350 # This can be used as a simple hash that maps parameter names
351 # to values, with _DEFAULT being the name for the default
352 # (unnamed) parameter.
353 # $topic - name of the topic in the query
354 # $web - name of the web in the query
355 # $topicObject - a reference to a Foswiki::Meta object containing the
356 # topic the macro is being rendered in (new for foswiki 1.1.x)
357 # Return: the result of processing the macro. This will replace the
358 # macro call in the final text.
359
360 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
361 # $params->{_DEFAULT} will be 'hamburger'
362 # $params->{sideorder} will be 'onions'
363
36422µs my $formatString = defined $params->{_DEFAULT} ?
365 $params->{_DEFAULT} :
366 $Foswiki::cfg{DefaultDateFormat};
367
36821µs my $datetime = $params->{time};
36921µs if ( defined $datetime ) {
37022µs if ( $datetime =~ /^\s*\$(\w+)/ ) {
371 # if storage does not exist the startdate is undefined
372 $datetime = $storage{ $1 };
373 }
374 else {
37523µs290µs $datetime = Foswiki::Time::parseTime( $datetime );
# spent 90µs making 2 calls to Foswiki::Time::parseTime, avg 45µs/call
376 }
377 }
3782300ns $datetime = time() unless defined $datetime;
379
38021µs my $relativeTime = defined $params->{delta} ?
381 $params->{delta} :
382 0;
383
38427µs2687µs my $calculatedTime = Time::ParseDate::parsedate( $relativeTime,
# spent 687µs making 2 calls to Time::ParseDate::parsedate, avg 343µs/call
385 NO_RELATIVE => 0,
386 DATE_REQUIRED => 1,
387 UK => 1,
388 NOW => $datetime,
389 PREFER_FUTURE => 1,
390 GMT => 1 );
391
3922300ns $datetime = $calculatedTime if defined $calculatedTime;
393
39421µs my $storageBin = $params->{store};
395
3962200ns $storage{ $storageBin } = $datetime if defined $storageBin;
397
398212µs243µs return Foswiki::Time::formatTime($datetime, $formatString, gmtime);
# spent 43µs making 2 calls to Foswiki::Time::formatTime, avg 22µs/call
399}
400
401
402sub _CALENDARDAYS {
403 my($session, $params, $theTopic, $theWeb) = @_;
404 # $session - a reference to the Foswiki session object
405 # (you probably won't need it, but documented in Foswiki.pm)
406 # $params= - a reference to a Foswiki::Attrs object containing
407 # parameters.
408 # This can be used as a simple hash that maps parameter names
409 # to values, with _DEFAULT being the name for the default
410 # (unnamed) parameter.
411 # $topic - name of the topic in the query
412 # $web - name of the web in the query
413 # $topicObject - a reference to a Foswiki::Meta object containing the
414 # topic the macro is being rendered in (new for foswiki 1.1.x)
415 # Return: the result of processing the macro. This will replace the
416 # macro call in the final text.
417
418 # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}%
419 # $params->{_DEFAULT} will be 'hamburger'
420 # $params->{sideorder} will be 'onions'
421
422
423 # To do - we need to be able to also accept serialized date
424 my $startdate = $params->{startdate};
425 if ( defined $startdate ) {
426 if ( $startdate =~ /^\s*\$(\w+)/ ) {
427 # if storage does exist the startdate is undefined
428 $startdate = $storage{ $1 };
429 $startdate = _returnNoonOfDate( $startdate ) if defined $startdate;
430 }
431 else {
432 $startdate = _returnNoonOfDate( Foswiki::Time::parseTime( $startdate ) );
433 }
434 }
435 $startdate = _returnNoonOfDate( time() ) unless defined $startdate;
436
437 my $enddate = $params->{enddate};
438 if ( defined $enddate ) {
439 if ( $enddate =~ /^\s*\$(\w+)/ ) {
440 # if storage does exist the startdate is undefined
441 $enddate = $storage{ $1 };
442 $enddate = _returnNoonOfDate( $enddate ) if defined $enddate;
443 }
444 else {
445 $enddate = _returnNoonOfDate( Foswiki::Time::parseTime( $enddate ) );
446 }
447 }
448 $enddate = _returnNoonOfDate( time() ) unless defined $enddate;
449
450 my $includestart = defined $params->{includestart} ?
451 Foswiki::Func::isTrue( $params->{includestart} ) : 0;
452 my $includeend = defined $params->{includeend} ?
453 Foswiki::Func::isTrue( $params->{includeend} ) : 1;
454
455 # Calculate working days between two times.
456 # Times are standard system times (secs since 1970).
457
458 # We allow the two dates to be swapped around
459 ( $startdate, $enddate ) = ( $enddate, $startdate ) if ( $startdate > $enddate );
460270µs216µs
# spent 14µs (12+2) within Foswiki::Plugins::TimeCalcPlugin::BEGIN@460 which was called: # once (12µs+2µs) by Foswiki::Plugin::BEGIN@2.34 at line 460
use integer;
# spent 14µs making 1 call to Foswiki::Plugins::TimeCalcPlugin::BEGIN@460 # spent 2µs making 1 call to integer::import
461 $startdate -= 86400 if $includestart;
462 $enddate -= 86400 unless $includeend;
463 my $elapsed_days = int( ( $enddate - $startdate ) / 86400 );
464
465 return $elapsed_days;
466
467}
468
46914µs1;