View Issue Details

IDProjectCategoryView StatusLast Update
0031836mantisbtbugtrackerpublic2023-06-25 11:45
Reporterricardoalonsos Assigned Todregad  
PriorityhighSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version2.25.5 
Target Version2.25.6Fixed in Version2.25.6 
Summary0031836: Date conversion fails when editing a project version using a non-US date format
Description

When editing a project version, if the date format is set for a non-US format, the strtotime will fail on date conversion.

Attached is the patch to fix the issue

Steps To Reproduce
  • configure mantis to use non-US date format (DD/MM/YYYY HH:mm)
  • Access page Manage Project
  • Include and/or edit a version
  • Save
Tagspatch
Attached Files
0004-if-date-format-is-not-an-US-format-strtotime-will-fa.patch (952 bytes)   
From b7c4350fefeb202e58ada34f99561099643eebac Mon Sep 17 00:00:00 2001
From: Ricardo Alonso <ralonso@redhat.com>
Date: Mon, 19 Dec 2022 11:38:04 +0000
Subject: [PATCH] if date format is not an US format, strtotime will fail. So
 first create a datetimeimmutable with the user specified format and perform
 the string conversion

---
 core/version_api.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/version_api.php b/core/version_api.php
index d2e97e7..4f8060f 100644
--- a/core/version_api.php
+++ b/core/version_api.php
@@ -111,7 +111,7 @@ class VersionData {
 					if( $p_value == '' ) {
 						$t_value = date_get_null();
 					} else {
-						$t_value = strtotime( $p_value );
+						$t_value = DateTimeImmutable::createFromFormat( config_get('normal_date_format') , $p_value)->getTimestamp();
 						if( $t_value === false ) {
 							throw new ClientException(
 								"Invalid date format '$p_value'",
-- 
2.38.1

Relationships

has duplicate 0022704 closeddregad Due date not saved when non english date format 
has duplicate 0023257 closeddregad Due Date saves wrong values 
has duplicate 0022558 closeddregad Problem with datepicker and custom date format 

Activities

dregad

dregad

2022-12-19 09:55

developer   ~0067226

Thanks, good catch.

Your patch should indeed fix the issue from the GUI (will test to confirm), but I believe we'll probably be facing the same problem when creating a new version from the API as well (need to check).

Next time if that's possible for you, please submit your contribution as a pull request on GitHub to facilitate the review and merge process.

dregad

dregad

2023-01-06 12:32

developer   ~0067268

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

Change includes additional fixes / improvements than just this issue, refer to PR for details.

ricardoalonsos

ricardoalonsos

2023-01-06 13:32

reporter   ~0067269

I take care to generate a pull request next time.
Thank you

Related Changesets

MantisBT: master-2.25 dbafafa9

2022-12-19 06:38

ricardoalonsos

Committer: dregad


Details Diff
Fix project version edit failing with non-US dates

If $g_normal_date_format is not an US format, strtotime will fail. So
first create a datetimeimmutable with the user specified format and
perform the string conversion.

Fixes 0031836

Signed-off-by: Damien Regad <dregad@mantisbt.org>
Affected Issues
0031836
mod - core/version_api.php Diff File

MantisBT: master-2.25 a500ed68

2023-02-21 17:41

dregad

Committer: community


Details Diff
Improve conversion of date strings to unix timestamps

When editing a project version, if the date format is set for a non-US
format, the strtotime() call will fail on date conversion.

This moves the conversion logic to date_strtotime() API and makes use
of the modified API function where relevant, i.e. when date string
could be user-provided.

Fixes 0031836, PR https://github.com/mantisbt/mantisbt/pull/1864
Affected Issues
0031836
mod - bug_update.php Diff File
mod - config_defaults_inc.php Diff File
mod - core/bug_api.php Diff File
mod - core/commands/VersionAddCommand.php Diff File
mod - core/date_api.php Diff File
mod - core/version_api.php Diff File
mod - docbook/Admin_Guide/en-US/config/duedate.xml Diff File