Skip to content

Round instead of truncate when formatting a duration from hours - #24776

Open
jtauschl wants to merge 1 commit into
opf:devfrom
jtauschl:fix/duration-formatter-rounds-instead-of-truncates
Open

Round instead of truncate when formatting a duration from hours#24776
jtauschl wants to merge 1 commit into
opf:devfrom
jtauschl:fix/duration-formatter-rounds-instead-of-truncates

Conversation

@jtauschl

@jtauschl jtauschl commented Aug 14, 2026

Copy link
Copy Markdown

Summary

Fixes OP-19969.

format_duration_from_hours passed its computed seconds value straight into Duration.new(seconds: ...), whose hash-based constructor (in the ruby-duration gem) truncates via Float#to_i rather than rounding -- e.g. 5.501 hours (19803.6 seconds) silently serialized as "PT5H30M3S" instead of the correctly rounded "PT5H30M4S", losing up to just under a second of precision on any value with a fractional-second remainder. This affects every caller of this shared formatter (work packages, meetings, time entries), not just time entries.

Change

Round the seconds value explicitly before constructing the Duration.

Test plan

  • Updated the existing spec assertion that encoded the old truncating behavior as expected
  • Verified live against a real 17.7.1 instance, both server-side and through the full REST API: before the fix, format_duration_from_hours(5.501)"PT5H30M3S"; after the fix → "PT5H30M4S", and POST /api/v3/time_entries with hours: "PT5H30M3.6S" correctly returns "hours":"PT5H30M4S"

format_duration_from_hours passed its computed seconds value straight
into Duration.new(seconds: ...), whose hash-based constructor (in the
ruby-duration gem) truncates via Float#to_i rather than rounding --
e.g. 5.501 hours (19803.6 seconds) silently serialized as "PT5H30M3S"
instead of the correctly rounded "PT5H30M4S", losing up to just under
a second of precision on any value with a fractional-second remainder.
This affects every caller of this shared formatter (work packages,
meetings, time entries), not just time entries.

Round the seconds value explicitly before constructing the Duration.
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@jtauschl

Copy link
Copy Markdown
Author

recheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant