Relationship Graph

Relationship Graph
related to related to child of child of duplicate of duplicate of

View Issue Details

IDProjectCategoryView StatusLast Update
0034928mantisbtbugtrackerpublic2025-09-21 06:48
Reporterfilipesantos Assigned Todregad  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.27.0 
Target Version2.28.0Fixed in Version2.28.0 
Summary0034928: Date conversion fails using a non-US date format in VersionUpdateCommand.php
Description

Hello everyone in the community.
Despite the reports in 0031836 0022558 0022704 0033597, the error continues when editing a version within the project. I noticed that VersionUpdateCommand.php still uses strtotime, although the other files have already been changed in previous releases.
Sorry, I'm a newbie, and I don't know how to proceed to send it in compliance.

In my installation, I replaced the line $t_timestamp = strtotime( $t_timestamp ); by $t_timestamp = date_strtotime ( $t_timestamp ); and resolved it.

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

TagsNo tags attached.

Relationships

related to 0031836 closeddregad Date conversion fails when editing a project version using a non-US date format 
related to 0033597 new Datetime picker breaks when setting normal_date_format 

Activities

dregad

dregad

2024-11-01 12:01

developer   ~0069420

Last edited: 2024-11-04 11:55

Thanks for the report. I guess VersionUpdateCommand was forgotten in the fix for 0031836. I'll have a look.

EDIT: actually VersionUpdateCommand was added in 0030415 (2.26.0), after 0031836 was fixed (2.25.6).

dregad

dregad

2024-11-03 06:12

developer   ~0069421

Hello @filipesantos

I have tried to reproduce the problem, but couldn't. As far as I can tell it is working as expected.

Can you please confirm that you have configured $g_datetime_picker_format as appropriate to match $g_normal_date_format, as explained in the admin guide ?

If not, please clarify the steps to reproduce, including your values for $g_datetime_picker_format and $g_normal_date_format, as well as the date(s) you entered and the actual error you got including stack trace (temporarily set $g_show_detailed_errors = ON; )

filipesantos

filipesantos

2024-11-03 09:06

reporter   ~0069422

Hello @dregad
Thanks for the answer, I'll send the information:

$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';

With these settings representing the Brazilian date format, where first is the day, month and year; When creating a new version everything happens fine.
When editing a version, even without any edits to the form, the date is incorrectly changed. Example:

I created a version at this moment, that is, its date is 03/11/2024 11:00, if I click on change the date is loaded correctly in Picker, but when saving it is inverted to 11/03/2024 11:00, in other words, he changed the day to the month.
If I edit the date to a day pattern greater than 12, the conversion gives an error and the value 1 is set in the database, and then the field is empty. Example: 25/10/2024 11:00.

When analyzing the VersionUpdateCommand.php file, I noticed that when converting date to timestamp it still uses strtotime, which only accepts dates in the US standard.

Sorry for my bad English.

dregad

dregad

2024-11-04 07:34

developer   ~0069423

Thanks for the feedback, and don't worry about your English, it is perfectly fine.

I was actually testing with my own local date format, which uses period . as delimiter, and the system works as expected in that case. With / delimiter the behavior is indeed different, as strtoime() defaults to US format (m/d/y). So the problem is reproducible for me now.

As a workaround pending a fix in MantisBT code, you could use . or - as date delimiter.

I believe your proposition to update VersionUpdateCommand is not appropriate, as it was decided not to allow custom date formats from REST API (see discussion in PR https://github.com/mantisbt/mantisbt/pull/1864#discussion_r1065202271, leading to removal of date_strtotime() from the related Commands in MantisBT master-2.25 f6c250af )

I think the change should go in manage_proj_ver_update.php, I'll analyze in more details later.

dregad

dregad

2024-11-10 11:57

developer   ~0069440

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

dregad

dregad

2024-11-10 11:58

developer   ~0069441

@filipesantos it would be great if you could test the proposed fix and provide feedback, either here or on the GitHub pull request.

dregad

dregad

2025-02-26 18:52

developer   ~0069930

Changing target version to 2.28.0 as the change is not so trivial anymore and could potentially introduce regressions.

Related Changesets

MantisBT: master c5fba7f4

2024-11-04 12:35

dregad


Details Diff
Update Version date conversion with non-US format

VersionAddCommand and VersionUpdateCommand now accept a Unix timestamp
as payload for timestamp (date_order).

manage_proj_ver_update.php calls date_strtotime() on the $f_timestamp
parameter to build the VersionUpdateCommand payload.

Fixes 0034928
Affected Issues
0034928
mod - core/commands/VersionAddCommand.php Diff File
mod - core/commands/VersionUpdateCommand.php Diff File
mod - manage_proj_ver_update.php Diff File

MantisBT: master b155dbfb

2025-02-26 18:43

dregad


Details Diff
New API functions for date conversions

As requested in PR review, it is no longer possible to provide timestamp
(version date order) as an integer to REST API /projects/{{id}}/versions
endpoints.

It is worth noting that a Unix timestamp can technically still be given,
using the `@{integer}` syntax, since that is a valid format for the
DateTimeImmutable constructor. This could change in the future, if we
decide to only allow ISO-8601 format.

The datetime parsing and generation logic has been standardized in 2 new
date API functions:
- date_string_to_timestamp()
- date_timestamp_to_iso8601()

Use the new functions in:
- date_strtotime()
- ApiObjectFactory: methods datetime() and datetimeString();
add new dateStringToTimestamp() method.
- VersionAddCommand
- VersionUpdateCommand

Fixes 0034928
Affected Issues
0034928
mod - api/soap/mc_api.php Diff File
mod - core/commands/VersionAddCommand.php Diff File
mod - core/commands/VersionUpdateCommand.php Diff File
mod - core/date_api.php Diff File
mod - manage_proj_ver_update.php Diff File