View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0009272 | mantisbt | bugtracker | public | 2008-06-17 09:13 | 2015-07-14 01:40 |
Reporter | krmichal | Assigned To | |||
Priority | normal | Severity | minor | Reproducibility | always |
Status | new | Resolution | open | ||
Platform | PC | OS | Windows | OS Version | 2000 server |
Product Version | 1.2.0a1 | ||||
Summary | 0009272: 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 |
$g_short_date_format = 'd-m-y';
| ||||
Tags | due_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_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_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 ); | ||||
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 |
|
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/.
|
|
Thanks for advice and patch. I'll try to handle that + other issues aroud due_date ASAP. |
|
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 |
|
I've done a quick review for due_date_9272.diff. Here are my comments:
|
|
sorry due_date_fix_9272_2.diff got stupid error. Sorry |
|
See also duplicate issue and pull request below: |
|