View Issue Details

IDProjectCategoryView StatusLast Update
0022558mantisbtbugtrackerpublic2019-12-11 16:20
Reporterrct Assigned Tosyncguru  
PrioritynormalSeveritymajorReproducibilityalways
Status assignedResolutionopen 
Product Version2.2.1 
Summary0022558: Problem with datepicker and custom date format
Description

Hi,

I've noticed a problem when you use custom date format (french here) in the project version datepicker and the due date datepicker.
One fails with ERROR_INVALID_DATE_FORMAT and the other ignore the due date.
It seems to be ok when I let the default english date format.

For the project version it fails in the class VersionData method __set on function strtotime (Parse about any English textual datetime description into a Unix timestamp. http://www.php.net/manual/en/function.strtotime.php / the date is not in english format).
For the due date the problem also comes from the strtotime function in the bug_update.php.

I dig a little more and I think there is a problem with the date format design: if it is defined at the global level you cannot define a date format matching for example a country because if some users come from another country they will have an unknown date format for them (and if they use another language there are problems with some code using the user language to decode string date format to timestamp).

Why not defining those date format in the language files?

Steps To Reproduce

$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';
$g_datetime_picker_format='DD/MM/YYYY HH:mm';

TagsNo tags attached.

Activities

vboctor

vboctor

2017-03-21 22:01

manager   ~0056156

I wonder if this is fixed by 0008957.

rct

rct

2017-05-04 07:25

reporter   ~0056772

Hello,
Any update on this?
Romain

JPK

JPK

2018-10-30 14:23

reporter   ~0060880

Last edited: 2018-10-31 12:08

View 2 revisions

I Confirm that bug in Mantis MantisBT 2.15.0

When you change date variable $g_normal_date_format in config/config_inc.php

   # --- date format settings --------
   # date format strings defaults to ISO 8601 formatting
   # go to http://www.php.net/manual/en/function.date.php
   # for detailed instructions on date formatting
   $g_normal_date_format   = 'd/m/y H:i';

a bug occurs in the project version datepicker
To resolve that, we modified the file manage_proj_ver_edit_page.php
line 103 :
remplace string_attribute( date( config_get( 'normal_date_format' ), $t_version->date_order ) )
by string_attribute( date( "Y/m/d H:i", $t_version->date_order ) )

01-version-date-picker.png (105,176 bytes)   
01-version-date-picker.png (105,176 bytes)   
ralfiii

ralfiii

2019-09-25 10:00

reporter   ~0062906

Last edited: 2019-09-25 10:01

View 3 revisions

I can confirm that the bug is still in V2.22.0
JPKs solution works just perfect.
Only "real" quote-characters need to be used instead if the quot-html-stuff

ralfiii

ralfiii

2019-09-25 10:40

reporter   ~0062907

Attached you see the same server contacted from 2 different clients.
Date on right client totally spoiled.
Again, JPK's solution resolves that here.

a.png (31,105 bytes)   
a.png (31,105 bytes)   
syncguru

syncguru

2019-12-07 18:15

developer   ~0063193

PR: https://github.com/mantisbt/mantisbt/pull/1587

@rolfiii I'd appreciate if you can test this PR and report back if it fixed the issue you are running into.

polzin

polzin

2019-12-11 16:16

reporter   ~0063255

Last edited: 2019-12-11 16:20

View 3 revisions

Isn't the real problem, that the datepicker creates a format in the localized form, but version_api.php uses "strtotime", which only accepts english dates?

Fixed it for me:

/core/version_api.php b/core/version_api.php
remove
$t_value = strtotime( $p_value );
if( $t_value === false ) { ...
insert
$t_date = date_create_from_format( config_get( 'normal_date_format' ), $p_value );
if( $t_date === false ) {
throw new ClientException(
"Invalid date format '$p_value'",
ERROR_INVALID_DATE_FORMAT,
array( $p_value ) );
}
$t_value = $t_date->getTimestamp();

polzin

polzin

2019-12-11 16:20

reporter   ~0063256

date_patch.txt (676 bytes)   
diff --git a/core/version_api.php b/core/version_api.php
index 14b521d..036fa18 100644
--- a/core/version_api.php
+++ b/core/version_api.php
@@ -111,13 +111,14 @@ class VersionData {
 					if( $p_value == '' ) {
 						$t_value = date_get_null();
 					} else {
-						$t_value = strtotime( $p_value );
-						if( $t_value === false ) {
+						$t_date = date_create_from_format( config_get( 'normal_date_format' ), $p_value );
+						if( $t_date === false ) {
 							throw new ClientException(
 								"Invalid date format '$p_value'",
 								ERROR_INVALID_DATE_FORMAT,
 								array( $p_value ) );
 						}
+						$t_value = $t_date->getTimestamp();
 					}
 				}
 		}
date_patch.txt (676 bytes)   

Issue History

Date Modified Username Field Change
2017-03-21 10:14 rct New Issue
2017-03-21 21:59 vboctor Assigned To => syncguru
2017-03-21 21:59 vboctor Status new => assigned
2017-03-21 22:01 vboctor Note Added: 0056156
2017-05-04 07:25 rct Note Added: 0056772
2018-10-30 14:23 JPK File Added: 01-version-date-picker.png
2018-10-30 14:23 JPK File Added: 02-version-project-date-picker-code.png
2018-10-30 14:23 JPK Note Added: 0060880
2018-10-31 12:08 dregad Note Edited: 0060880 View Revisions
2019-09-25 10:00 ralfiii Note Added: 0062906
2019-09-25 10:00 ralfiii Note Edited: 0062906 View Revisions
2019-09-25 10:01 ralfiii Note Edited: 0062906 View Revisions
2019-09-25 10:40 ralfiii Note Added: 0062907
2019-09-25 10:40 ralfiii File Added: a.png
2019-12-07 18:15 syncguru Note Added: 0063193
2019-12-11 16:16 polzin Note Added: 0063255
2019-12-11 16:17 polzin Note Edited: 0063255 View Revisions
2019-12-11 16:20 polzin Note Edited: 0063255 View Revisions
2019-12-11 16:20 polzin Note Added: 0063256
2019-12-11 16:20 polzin File Added: date_patch.txt