Project

General

Profile

Actions

Defect #42172

closed

`format_hours` method produces incorrect output for negative time values when `Setting.timespan_format` is "minutes"

Added by Steven Jones 8 days ago. Updated 4 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Time tracking
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Following on from #36897 we've spotted a strange formatting issue with time that is negative.

In our use-case we have some 'contracts' that are assigned a project and say have 40 hours a month.

As we log time against a project, we use-up this time assigned to the support contract. So suppose we have done 25 hours of work, then we want to display the obvious calculation:

Start of month 40:00
Used time 25:00
Balance 15:00

We use the format_hours method to display this.

When we've done more than 40 hours of work however, this causes issues, specifically, assume that we've done 40 hours 15 minutes of work in a month, the calculation with Redmine 6.0.2 (and our custom code) looks like this:

Start of month 40:00
Used time 40:15
Balance -1:45

Which to my eyes looks like we've done 1 hour 45 minutes over the contract.

This is because of the semantics of Ruby modulo arithmetic:

And this is purely because of the formatting of the number.

If we changed the display of Time spans to fractional our table looks like this:

Start of month 40.00
Used time 40.25
Balance -0.25

Which makes more sense to me.

I think the fix is pretty simple, I think that one could add a simple line like this:

# If the timespan is negative, perform the calculation on the positive value.
return "-" + format_hours(-hours) if hours < 0

To the top of the method.

And then my table would look like this:

Start of month 40:00
Used time 40:15
Balance -0:15

Which makes much more sense, I think, for a time span.


Files

42172.patch (1.43 KB) 42172.patch Go MAEDA, 2025-01-29 02:45

Related issues

Related to Redmine - Defect #36897: The minutes part of a time entry is displayed as 60 instead of being carried overClosedGo MAEDA

Actions
Actions

Also available in: Atom PDF