View Issue Details

IDProjectCategoryView StatusLast Update
0012154mantisbttime trackingpublic2011-08-05 02:57
Reportervr5 Assigned Todhx  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionduplicate 
Platformx86OSFedoraOS Version12
Product Version1.2.1 
Target Version1.2.4 
Summary0012154: Incorrect calls of strtotime
Description

There are incorrect calls of strtotime in core/bugnote_api.php:

$c_to = strtotime( $p_to, SECONDS_PER_DAY - 1 ); // @23:59:59

strtotime uses second argument only when first argument is a relative time (e.g. "one day ago", "next sunday", etc.) and ignores it otherwise.

Thus results of a query to DB will not include records inserted during p_to day.
Patch calls-to-strtotime-fixed.patch fixes this.

Tagspatch
Attached Files
calls-to-strtotime-fixed.patch (859 bytes)   
--- core/bugnote_api.php.orig	2010-04-23 22:28:34.000000000 +0400
+++ core/bugnote_api.php	2010-07-10 19:37:07.000000000 +0400
@@ -589,7 +589,7 @@
  */
 function bugnote_stats_get_events_array( $p_bug_id, $p_from, $p_to ) {
 	$c_bug_id = db_prepare_int( $p_bug_id );
-	$c_to = strtotime( $p_to, SECONDS_PER_DAY - 1 ); // @23:59:59
+	$c_to = strtotime( $p_to ) +  SECONDS_PER_DAY - 1; // @23:59:59
 	$c_from = strtotime( $p_from );
 
 	$t_user_table = db_get_table( 'mantis_user_table' );
@@ -637,7 +637,7 @@
 function bugnote_stats_get_project_array( $p_project_id, $p_from, $p_to, $p_cost ) {
 	$c_project_id = db_prepare_int( $p_project_id );
 
-	$c_to = strtotime( $p_to, SECONDS_PER_DAY - 1); // @23:59:59
+	$c_to = strtotime( $p_to ) + SECONDS_PER_DAY - 1; // @23:59:59
 	$c_from = strtotime( $p_from );
 
 	if ( $c_to === false || $c_from === false ) {

Relationships

duplicate of 0012363 closeddhx billing report seems not to include enddate 

Activities

jreese

jreese

2010-08-22 17:47

reporter   ~0026403

I don't see any documentation on php.net (http://us.php.net/manual/en/function.strtotime.php) that confirms the behavior you describe. Can you provide a link to somewhere that agrees with your assessment?

vr5

vr5

2010-08-22 20:49

reporter   ~0026409

Last edited: 2010-08-22 20:50

PHP manual seem to contain all needed information for this case, though it may be not really straightforward...

Documentation for strtotime has following description of parameters:

1) "time
A date/time string. Valid formats are explained in Date and Time Formats."

According to http://us.php.net/manual/en/datetime.formats.php
There are 4 formats:
"Time Format"
"Date Format"
"Compound Format"
"Relative Format"

Mantis passes a value in format which described as "Date format"
(p_to is described as "* @param string $p_to Ending date (yyyy-mm-dd) inclusive" in core/bugnote_api.php);

2) "now
The timestamp which is used as a base for the calculation of relative dates."

Parameter "time" is not in "relative date" format, so it can be assumed that parameter "now" will not be used.

A quick test confirms it:
$ php -r "date_default_timezone_set('UTC'); echo strtotime('21 Dec 2010', 10000);"
1292889600
$ php -r "date_default_timezone_set('UTC'); echo strtotime('21 Dec 2010', 1);"
1292889600

Well, maybe PHP documentation could be better...

dhx

dhx

2010-10-22 10:13

reporter   ~0027134

Thanks vr5, I can confirm what you're saying. I fixed another problem like this recently.

I'll queue this up for fixing in 1.2.x.