Skip to content

fix(theme): round short reset durations instead of truncating - #176

Open
fix2it wants to merge 1 commit into
CodeZeno:mainfrom
fix2it:fix/duration-short-rounding
Open

fix2it wants to merge 1 commit into
CodeZeno:mainfrom
fix2it:fix/duration-short-rounding

Conversation

@fix2it

@fix2it fix2it commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Improves duration_short formatting by replacing truncation with human-intuitive mathematical rounding, half-step (0.5) precision for small values, and seamless transitions between units.

Motivation & Problem

Previously, duration_short used integer truncation (floor behavior):

  • A reset due in 2h 55m was displayed as 2h (giving the user the impression that almost an entire hour had vanished).
  • A reset due in 4d 23h displayed as 4d.
  • Below 1 hour, 59m 40s was indistinguishable from 59m.

Key Changes

  1. Half-Step Precision (< 10):
    • For values $&lt; 10$ hours or $&lt; 10$ days, values are rounded to the nearest 0.5 step with a period separator (e.g., 1.5h, 2.5d, 9.5h).
    • Whole numbers within this range omit the decimal point (e.g., 3h, 6d).
  2. Standard Rounding (>= 10):
    • For values $\ge 10$ hours or $\ge 10$ days, integer mathematical rounding is applied (16h, 10d).
  3. Boundary Transitions & Rollover:
    • Durations $&lt; 1$ hour switch strictly to minutes and are clamped with .min(59) so that the final seconds before 1 hour never show an awkward 60m before flipping to 1h.
    • Durations near 24 hours (e.g., 23h 45m) roll over cleanly to 1d rather than displaying 24h.

Verification & Tests

  • Added comprehensive unit tests in src/theme_engine/tests.rs (duration_short_precision_scale_and_half_steps) verifying:
    • Sub-minute values (45s, "now").
    • Minute bounds (60s -> 1m, 3580s -> 59m).
    • Half-hour and whole-hour steps (1h, 1.5h, 2.5h, 9.5h, 10h, 18h, 85500s -> 1d).
    • Half-day and whole-day steps (1d, 1.5d, 2.5d, 6.5d, 10d).
  • All 101 theme engine tests pass.

duration_short truncated to whole units, so 4d23h read "4d" and 59m40s
could not be told from 59m. It now rounds: half steps below 10 h and
10 d (1.5ч, 2.5д), whole units above, minutes clamped to 59 so the next
step is "1h", and 23h45m rolls over to "1d".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant