View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0013332 | mantisbt | bugtracker | public | 2011-09-20 09:09 | 2015-07-23 17:47 |
Reporter | vincent_sels | Assigned To | vboctor | ||
Priority | normal | Severity | major | Reproducibility | always |
Status | closed | Resolution | duplicate | ||
Product Version | 1.2.8 | ||||
Summary | 0013332: Due date not saved successfully when date-format is set to 'd/m/Y' | ||||
Description | When the date-format is set to 'd/m/Y', Mantis does not correctly interpret the due date. | ||||
Additional Information | This is an issue when you have set the config date formats for example like this:
| ||||
Tags | due_date, localization, patch | ||||
Attached Files | 0001-Adds-support-for-date-format-d-m-Y.patch (5,220 bytes)
From 35800836dd315e12e7d552ee0f64519b9f60c693 Mon Sep 17 00:00:00 2001 From: Vincent Sels <vincent_sels@hotmail.com> Date: Mon, 16 Jan 2012 21:29:17 +0100 Subject: [PATCH] Adds support for date format d/m/Y When the date format is set to 'd/m/Y', the php strtotime function does not work correctly, it will try to parse the string as m/d/Y instead. The new function 'strtotime_safe' will check the $g_short_date_format setting, and if set to 'd/m/Y' it will fix this. --- bug_report.php | 9 ++------- bug_update.php | 12 ++---------- core/bug_api.php | 2 +- core/date_api.php | 23 +++++++++++++++++++++++ core/version_api.php | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/bug_report.php b/bug_report.php index 32e86f2..18d1ff6 100644 --- a/bug_report.php +++ b/bug_report.php @@ -77,14 +77,9 @@ $t_bug_data->status = config_get( 'bug_submit_status' ); $t_bug_data->summary = gpc_get_string( 'summary' ); $t_bug_data->description = gpc_get_string( 'description' ); - $t_bug_data->steps_to_reproduce = gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) ); + $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 = $t_bug_data->due_date; - } + $t_bug_data->due_date = strtotime_safe( gpc_get_string( 'due_date', null ) ); $f_file = gpc_get_file( 'file', null ); /** @todo (thraxisp) Note that this always returns a structure */ # size = 0, if no file diff --git a/bug_update.php b/bug_update.php index 6b440c4..ff6f3ce 100644 --- a/bug_update.php +++ b/bug_update.php @@ -73,22 +73,14 @@ $t_bug_data->platform = gpc_get_string( 'platform', $t_bug_data->platform ); $t_bug_data->version = gpc_get_string( 'version', $t_bug_data->version ); $t_bug_data->build = gpc_get_string( 'build', $t_bug_data->build ); - $t_bug_data->fixed_in_version = gpc_get_string( 'fixed_in_version', $t_bug_data->fixed_in_version ); + $t_bug_data->fixed_in_version = gpc_get_string( 'fixed_in_version', $t_bug_data->fixed_in_version ); $t_bug_data->view_state = gpc_get_int( 'view_state', $t_bug_data->view_state ); $t_bug_data->summary = gpc_get_string( 'summary', $t_bug_data->summary ); - $t_due_date = gpc_get_string( 'due_date', null ); + $t_bug_data->due_date = strtotime_safe( gpc_get_string( 'due_date', null ) ); if( access_has_project_level( config_get( 'roadmap_update_threshold' ), $t_bug_data->project_id ) ) { $t_bug_data->target_version = gpc_get_string( 'target_version', $t_bug_data->target_version ); } - - if( $t_due_date !== null) { - if ( is_blank ( $t_due_date ) ) { - $t_bug_data->due_date = 1; - } else { - $t_bug_data->due_date = strtotime( $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 ); diff --git a/core/bug_api.php b/core/bug_api.php index fc62c47..8760f31 100644 --- a/core/bug_api.php +++ b/core/bug_api.php @@ -171,7 +171,7 @@ class BugData { break; case 'due_date': if ( !is_numeric( $value ) ) { - $value = strtotime($value); + $value = strtotime_safe( $value ); } break; } diff --git a/core/date_api.php b/core/date_api.php index 7f6b56e..5be0409 100644 --- a/core/date_api.php +++ b/core/date_api.php @@ -307,3 +307,26 @@ function date_finish_calendar( $p_field_name, $p_button_name ) { echo "</script>\n"; } } + +/** + * Fixes 0013332: Due date not saved successfully when date-format is set to 'd/m/Y' + * The normal strtotime can't handle the format d/m/Y, since it will interpret + * it as m/d/Y. To determine whether this is the case, this function looks + * at the short_date_format setting. + * Also, if the passed argument is null and parameter $p_allow_null is false (default), + * date_get_null() is returned. + * @param string $p_date + * @param bool $p_allow_null + * @return number + */ +function strtotime_safe( $p_date, $p_allow_null = false ) { + if( !$p_allow_null && ( $p_date == null || is_blank ( $p_date ) || date_is_null( $p_date ) ) ) { + return date_get_null(); + } + + if ( config_get( 'short_date_format' ) == 'd/m/Y' ) { + return strtotime( str_replace( '/', '-', $p_date ) ); + } else { + return strtotime( $p_date ); + } +} diff --git a/core/version_api.php b/core/version_api.php index c716510..471d20e 100644 --- a/core/version_api.php +++ b/core/version_api.php @@ -49,7 +49,7 @@ class VersionData { if( $value == '' ) { $value = date_get_null(); } else { - $value = strtotime( $value ); + $value = strtotime_safe( $value ); if ( $value === false ) { trigger_error( ERROR_INVALID_DATE_FORMAT, ERROR ); } -- 1.7.6.msysgit.0 | ||||
This is a duplicate ticket of 0009668 but it could not be reproduced then. |
|
I found the problem and a possible solution. In 3 different files, the strtotime function is used. As documented on the PHP website at http://php.net/manual/en/function.strtotime.php in the third note, you can read the following: <i>Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.</i> Since create_from_format can only be used from php v5.3 onward, this was not an option for me. The only way I could fix it was by replacing the slashes with dashes manually: strtotime( str_replace( '/', '-', $t_due_date ) ); I changed this in three different files: bug_report_page.api, bug_report.api and bug_update.api The code I use is as follows for bug_update and bug_report:
The code for bug_report_page is as follows:
Would be nice to see this fixed in a future version, because this is quite a troublesome bug... |
|
This is happening here. |
|
That would be the easiest work-around. Problem is that our end-users are used to the d/m/Y format that's used in our application too, so it would be too difficult for them to use a different format in Mantis. |
|
I think I got a decent fix ready: https://github.com/mantisbt/mantisbt/pull/35 |
|