Project

General

Profile

Actions

Defect #40914

closed

Fix precision issues in TimeEntry#hours calculation by returning Rational instead of Float

Added by Boris Brodski 5 months ago. Updated 3 months ago.

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

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

On the page my/page, if the timelog is displayed, the total is shown at the top of the table. The summing is not correctly implemented, leading to rounding errors.

Reproduction and Example:

  1. Add time entries for one day, one issue:
    - 0:10
    - 0:40
    - 0:10
  2. Navigate to my/page
  3. Add the 'timelog' widget if it is not already present.
  4. The time entries should be shown. The total displayed is 1:01.

Implementation and Easy Fix:

Current implementation (app/views/my/blocks/_timelog.html.erb:45):

html_hours(format_hours(entries_by_day[day].sum(&:hours)))

Summing hours introduces rounding errors. To fix this, convert to minutes first:

html_hours(format_hours(entries_by_day[day].map{|t| (t.hours * 60).to_i}.sum / 60))

Files

clipboard-202406301643-wtqrs.png (69.6 KB) clipboard-202406301643-wtqrs.png Go MAEDA, 2024-06-30 09:43
40914.patch (3.99 KB) 40914.patch Go MAEDA, 2024-07-01 01:41
40914-v2.patch (2.53 KB) 40914-v2.patch Go MAEDA, 2024-07-23 10:31
40914-v3.patch (2.54 KB) 40914-v3.patch Go MAEDA, 2024-07-31 10:17

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