View Issue Details

IDProjectCategoryView StatusLast Update
0009272mantisbtbugtrackerpublic2015-07-14 01:40
Reporterkrmichal Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformPCOSWindowsOS Version2000 server
Product Version1.2.0a1 
Summary0009272: due_date conversion problem when using custom date format
Description

When using custom date format ('d-m-y') the content of due_date field is written incorrectly to database (mysql in my case), and thus in application year is switched with day. After dropping custom date format everything works fine (I mean adding new dates. Dates already in database are still wrong).

Steps To Reproduce
  1. Set custom date format. I use:

$g_short_date_format = 'd-m-y';
$g_normal_date_format = 'd-m-y H:i';
$g_complete_date_format = 'd-m-y H:i T';

  1. Choose any bug, click Update and set new due_date.
  2. Write changes.
  3. Date written has year and day fields switched.
Tagsdue_date, patch
Attached Files
due_date_9272.diff (5,065 bytes)   
Index: bug_update_advanced_page.php
===================================================================
--- bug_update_advanced_page.php	(revision 5470)
+++ bug_update_advanced_page.php	(working copy)
@@ -190,7 +190,10 @@
 ?>
 	</td>
 
-<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+<?php 
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
+	if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
 	<!-- Due Date -->
 	<td class="category">
 		<?php echo lang_get( 'due_date' ) ?>
@@ -203,7 +206,7 @@
 	}
 	if ( $t_can_update_due_date ) {
 		$t_date_to_display = '';
-		if ( ! date_is_null( $t_bug->due_date ) ) {
+	    if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
 		}
 	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
@@ -211,7 +214,7 @@
 	?>
 	</td>
 	<?php } else {
-		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+		if ( ! date_is_null($t_bug->due_date) ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
 	</td>
 <?php } else { ?>
 		<!-- spacer -->
Index: bug_report.php
===================================================================
--- bug_report.php	(revision 5470)
+++ bug_report.php	(working copy)
@@ -55,12 +55,35 @@
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+
 	if ( is_blank ( $t_bug_data->due_date ) ) {
-		$t_bug_data->due_date = date_get_null( );
-	} else {
-		$t_bug_data->due_date = db_unixtimestamp ( $t_bug_data->due_date, true ) + 1;
-	}	
+                $t_bug_data->due_date = date_get_null( );
+        } else {
+            $t_due_date = date($t_bug_data->due_date);
+            #get delimiter
+            $date_format_strings = array("m", "d", "y", "M", "D", "Y");
+            $date_delimiter = str_replace($date_format_strings, "", config_get('short_date_format'));
+            $date_delimiter = $date_delimiter[0];
 
+            $t_due_date_tmp = explode($date_delimiter, $t_bug_data->due_date);
+            $date_format_order = explode($date_delimiter, config_get('short_date_format'));
+            $i = 0;
+            foreach ( $date_format_order as $key) {
+                switch($key) {
+                    case 'd': $t_due_date_day = $t_due_date_tmp[$i];
+                    break;
+                    case 'm': $t_due_date_month = $t_due_date_tmp[$i];
+                    break;
+                    case 'Y': $t_due_date_year = $t_due_date_tmp[$i];
+                    break;
+                }
+                $i = $i+1;
+            }
+            $t_due_date =  gmmktime(0, 0, 1, $t_due_date_month, $t_due_date_day, $t_due_date_year);
+            $t_bug_data->due_date = $t_due_date;
+        }
+
+
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
 	$f_report_stay			= gpc_get_bool( 'report_stay', false );
Index: bug_update.php
===================================================================
--- bug_update.php	(revision 5470)
+++ bug_update.php	(working copy)
@@ -82,9 +82,31 @@
 	if ( is_blank ( $t_bug_data->due_date ) ) {
 		$t_bug_data->due_date = date_get_null( );
 	} else {
-		$t_bug_data->due_date = db_unixtimestamp ( $t_bug_data->due_date, true ) + 1;
+	    $t_due_date = date($t_bug_data->due_date);
+    	    #get delimiter
+	    $date_format_strings = array("m", "d", "y", "M", "D", "Y");
+	    $date_delimiter = str_replace($date_format_strings, "", config_get('short_date_format'));
+	    $date_delimiter = $date_delimiter[0];
+	    
+	    $t_due_date_tmp = explode($date_delimiter, $t_bug_data->due_date);
+	    $date_format_order = explode($date_delimiter, config_get('short_date_format'));
+	    $i = 0;
+	    foreach ( $date_format_order as $key) {
+	        switch($key) {
+	    	    case 'd': $t_due_date_day = $t_due_date_tmp[$i];
+		    break;
+		    case 'm': $t_due_date_month = $t_due_date_tmp[$i];
+		    break;
+		    case 'Y': $t_due_date_year = $t_due_date_tmp[$i];
+		    break;
+		}
+	        $i = $i+1;
+	    }
+	    $t_due_date =  gmmktime(0, 0, 1, $t_due_date_month, $t_due_date_day, $t_due_date_year);
+	    $t_bug_data->due_date = $t_due_date;	
 	}
 	
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
due_date_9272.diff (5,065 bytes)   
due_date_fix_9272_2.diff (4,618 bytes)   
Index: bug_update_advanced_page.php
===================================================================
--- bug_update_advanced_page.php	(revision 5521)
+++ bug_update_advanced_page.php	(working copy)
@@ -190,7 +190,10 @@
 ?>
 	</td>
 
-<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+<?php 
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
+	if ( $t_can_update_due_date ) { ?>
 	<!-- Due Date -->
 	<td class="category">
 		<?php echo lang_get( 'due_date' ) ?>
@@ -203,7 +206,7 @@
 	}
 	if ( access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id ) ) {
 		$t_date_to_display = '';
-		if ( ! date_is_null( $t_bug->due_date ) ) {
+	    if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
 		}
 	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
@@ -212,7 +215,10 @@
 	?>
 	</td>
 	<?php } else {
-		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+		if ( ! date_is_null($t_bug->due_date) ) {
+		    print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); 
+		}
+	}?>
 	</td>
 <?php } else { ?>
 		<!-- spacer -->
Index: core/date_api.php
===================================================================
--- core/date_api.php	(revision 5521)
+++ core/date_api.php	(working copy)
@@ -38,6 +38,34 @@
 	function date_get_null() {
 		return db_unixtimestamp( db_null_date() );
 	}
+	
+	# --------------------
+	# converts date from user defined (short_date_format) string to timestamp
+	function date_remake( $p_date ) {
+            $t_due_date = $p_date;
+            #get delimiter
+            $date_format_strings = array( "m", "d", "y", "M", "D", "Y" );
+            $date_delimiter = str_replace( $date_format_strings, "", config_get( 'short_date_format' ) );
+            $date_delimiter = $date_delimiter[0];
+	    
+            $t_due_date_tmp = explode( $date_delimiter, $t_bug_data->due_date );
+	    $date_format_order = explode( $date_delimiter, config_get( 'short_date_format' ) );
+	    $i = 0;
+	    foreach ( $date_format_order as $key ) {
+		switch( $key ) {
+		    case 'd': $t_due_date_day = $t_due_date_tmp[$i];
+		    break;
+		    case 'm': $t_due_date_month = $t_due_date_tmp[$i];
+		    break;
+		    case 'Y': $t_due_date_year = $t_due_date_tmp[$i];
+		    break;
+		}
+		$i = $i+1;
+	    }
+	    $t_due_date =  gmmktime( 0, 0, 1, $t_due_date_month, $t_due_date_day, $t_due_date_year );
+            return $t_due_date;
+	}
+	
 
 	# --------------------
 	# prints the date given the formating string
Index: bug_report.php
===================================================================
--- bug_report.php	(revision 5521)
+++ bug_report.php	(working copy)
@@ -55,12 +55,14 @@
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+
 	if ( is_blank ( $t_bug_data->due_date ) ) {
-		$t_bug_data->due_date = date_get_null( );
-	} else {
-		$t_bug_data->due_date = db_unixtimestamp ( $t_bug_data->due_date, true ) + 1;
-	}	
+                $t_bug_data->due_date = date_get_null( );
+        } else {
+            $t_bug_data->due_date = date_remake( $t_bug_data->due_date );
+        }
 
+
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
 	$f_report_stay			= gpc_get_bool( 'report_stay', false );
Index: bug_update.php
===================================================================
--- bug_update.php	(revision 5521)
+++ bug_update.php	(working copy)
@@ -80,9 +80,10 @@
 	if ( is_blank ( $t_bug_data->due_date ) ) {
 		$t_bug_data->due_date = date_get_null( );
 	} else {
-		$t_bug_data->due_date = db_unixtimestamp ( $t_bug_data->due_date, true ) + 1;
+	    $t_bug_data->due_date = date_remake( $t_bug_data->due_date);
 	}
 	
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
due_date_fix_9272_2.diff (4,618 bytes)   
due_date_fix_9272_2b.diff (5,919 bytes)   
Index: bug_update_advanced_page.php
===================================================================
--- bug_update_advanced_page.php	(revision 5521)
+++ bug_update_advanced_page.php	(working copy)
@@ -190,7 +190,10 @@
 ?>
 	</td>
 
-<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+<?php 
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
+	if ( $t_can_update_due_date ) { ?>
 	<!-- Due Date -->
 	<td class="category">
 		<?php echo lang_get( 'due_date' ) ?>
@@ -203,7 +206,7 @@
 	}
 	if ( access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id ) ) {
 		$t_date_to_display = '';
-		if ( ! date_is_null( $t_bug->due_date ) ) {
+	    if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
 		}
 	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
@@ -212,7 +215,10 @@
 	?>
 	</td>
 	<?php } else {
-		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+		if ( ! date_is_null($t_bug->due_date) ) {
+		    print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); 
+		}
+	}?>
 	</td>
 <?php } else { ?>
 		<!-- spacer -->
Index: admin/schema.php
===================================================================
--- admin/schema.php	(revision 5521)
+++ admin/schema.php	(working copy)
@@ -404,8 +404,8 @@
 	" ) );
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
-$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
-    due_date        T       NOTNULL DEFAULT '" . db_null_date() . "' " ) );
+#$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+#    due_date        T       NOTNULL DEFAULT '" . db_null_date() . "' " ) );
 
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_custom_field_table' ), "
   filter_by 		L 		NOTNULL DEFAULT \" '1' \"" ) );
Index: core/date_api.php
===================================================================
--- core/date_api.php	(revision 5521)
+++ core/date_api.php	(working copy)
@@ -38,6 +38,32 @@
 	function date_get_null() {
 		return db_unixtimestamp( db_null_date() );
 	}
+	
+	# --------------------
+	# converts date from user defined (short_date_format) string to timestamp
+	function date_remake( $p_date ) {
+            #get delimiter
+            $date_format_strings = array( "m", "d", "y", "M", "D", "Y" );
+            $date_delimiter = str_replace( $date_format_strings, "", config_get( 'short_date_format' ) );
+            $date_delimiter = $date_delimiter[0];
+	    
+            $t_due_date = explode( $date_delimiter, $p_date );
+	    $date_format_order = explode( $date_delimiter, config_get( 'short_date_format' ) );
+	    $i = 0;
+	    foreach ( $date_format_order as $key ) {
+		switch( $key ) {
+		    case 'd': $t_due_date_day = $t_due_date[$i];
+		    break;
+		    case 'm': $t_due_date_month = $t_due_date[$i];
+		    break;
+		    case 'Y': $t_due_date_year = $t_due_date[$i];
+		    break;
+		}
+		$i = $i+1;
+	    }
+	    return  gmmktime( 0, 0, 1, $t_due_date_month, $t_due_date_day, $t_due_date_year );
+	}
+	
 
 	# --------------------
 	# prints the date given the formating string
Index: core/custom_field_api.php
===================================================================
--- core/custom_field_api.php	(revision 5521)
+++ core/custom_field_api.php	(working copy)
@@ -741,6 +741,7 @@
                         ( pt.view_state = $t_priv and pult.user_id = $t_user_id ) OR 
                         ( pult.user_id is null and ut.access_level $t_access_clause ) )
                     ORDER BY cft.name ASC";
+//                    GROUP BY cft.id, cft.name
     		} else {
                 if ( is_array( $p_project_id ) ) {
                     if ( 1 == count( $p_project_id ) ) {
Index: bug_report.php
===================================================================
--- bug_report.php	(revision 5521)
+++ bug_report.php	(working copy)
@@ -55,12 +55,14 @@
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+
 	if ( is_blank ( $t_bug_data->due_date ) ) {
-		$t_bug_data->due_date = date_get_null( );
-	} else {
-		$t_bug_data->due_date = db_unixtimestamp ( $t_bug_data->due_date, true ) + 1;
-	}	
+                $t_bug_data->due_date = date_get_null( );
+        } else {
+            $t_bug_data->due_date = date_remake( $t_bug_data->due_date );
+        }
 
+
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
 	$f_report_stay			= gpc_get_bool( 'report_stay', false );
Index: bug_update.php
===================================================================
--- bug_update.php	(revision 5521)
+++ bug_update.php	(working copy)
@@ -80,9 +80,10 @@
 	if ( is_blank ( $t_bug_data->due_date ) ) {
 		$t_bug_data->due_date = date_get_null( );
 	} else {
-		$t_bug_data->due_date = db_unixtimestamp ( $t_bug_data->due_date, true ) + 1;
+	    $t_bug_data->due_date = date_remake( $t_bug_data->due_date);
 	}
 	
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
due_date_fix_9272_2b.diff (5,919 bytes)   

Relationships

has duplicate 0013332 closedvboctor Due date not saved successfully when date-format is set to 'd/m/Y' 
related to 0008942 closedatrol due date feature 

Activities

mkornatzki

mkornatzki

2008-06-19 03:18

reporter   ~0018136

i also realize a problem with a localized date. you have to correct bug_report.php and bug_update.php.

if you replace the else-sector as follows you can store due_date with a localized format. There is also a bug in the calendar if you change the $g_short_date_format

if ( is_blank ( $t_bug_data->due_date ) ) {
    $t_bug_data->due_date = date_get_null( );
} else {
    $t_due_date = date($t_bug_data->due_date);
    #get delimiter
    $date_format_strings = array(&quot;m&quot;, &quot;d&quot;, &quot;y&quot;, &quot;M&quot;, &quot;D&quot;, &quot;Y&quot;);
    $date_delimiter = str_replace($date_format_strings, &quot;&quot;, config_get('short_date_format'));
    $date_delimiter = $date_delimiter[0];

    $t_due_date_tmp = explode($date_delimiter, $t_bug_data->due_date);
    $date_format_order = explode($date_delimiter, config_get('short_date_format'));
    $i = 0;
    foreach ( $date_format_order as $key) {
        switch($key) {
            case 'd': $t_due_date_day = $t_due_date_tmp[$i];
            break;
            case 'm': $t_due_date_month = $t_due_date_tmp[$i];
            break;
            case 'Y': $t_due_date_year = $t_due_date_tmp[$i];
            break;
        }
        $i = $i+1;
    }
    $t_due_date = mktime(5, 0, 0, $t_due_date_month, $t_due_date_day, $t_due_date_year);
    $t_bug_data->due_date = $t_due_date;
}
mkornatzki

mkornatzki

2008-06-27 10:08

reporter   ~0018203

now i have a fix for the calender. you have to download the language files for the calendar from http://www.dynarch.com/projects/calendar/.
then you have to edit the date.api:

  • in function date_print_calendar
    replace
    echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n";
    with
    echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-" . lang_get_current_locale(). ".js\"></script>\n";

    and add
    $t_new_format = str_replace( '.', '.%', $t_new_format );
    after
    $t_new_format = str_replace( '-', '-%', $t_format );

  • in function date_finish_calendar add
    $t_new_format = str_replace( '.', '.%', $t_new_format );
    after
    $t_new_format = str_replace( '-', '-%', $t_format );

  • in lang_api.php add the following function

    return value on top of the language stack

    return default if stack is empty

    function lang_get_current_locale( ) {
    $t_lang = lang_get_current();
    if ($t_lang == 'german') {
    $t_lang = 'de';
    } else {
    $t_lang = 'en';
    }

    return $t_lang;

    }

smig1o

smig1o

2008-07-03 02:33

reporter   ~0018285

Thanks for advice and patch.
Right now I am really busy. I think I'll find some free time at the begining of next month (August).
Right now I can tell you about just one problem.
So far Mantis doesnt provide all localized calendar files so lang_get_current_locale() wont help much. Ask some >Mantis god< to add localized files so it will be usefull ;)

I'll try to handle that + other issues aroud due_date ASAP.

smig1o

smig1o

2008-07-31 07:27

reporter   ~0018953

I have created patch according to your suggestion about handling short date format. I hope It will be commited soon.

Once again thanks for your help

vboctor

vboctor

2008-08-22 03:48

manager   ~0019205

I've done a quick review for due_date_9272.diff. Here are my comments:

  1. Aren't you passing the date value to date() function as a format parameter?
  2. There is redundant code between bug_report / bug_update. This should be pushed to core\date_api.php potentially.
  3. Rather than doing an access_has_bug_level() twice in bug_update_advanced_page.php, use $t_can_update_due_date.
  4. Follow Mantis standards and make sure the body for if statements is always included between {}.
  5. Follow Mantis standard in spacing. For example, date(x) -> date( x )
smig1o

smig1o

2008-08-22 04:50

reporter   ~0019207

sorry due_date_fix_9272_2.diff got stupid error. Sorry

vboctor

vboctor

2015-07-14 01:40

manager   ~0051054

See also duplicate issue and pull request below:
https://github.com/mantisbt/mantisbt/pull/35