Fix Pomodoro timer rounding so it rounds up to 0.25, but rounds to closest quarter (up or down) for minutes higher than that, instead of always up to next quarter.

This commit is contained in:
Miguel Jacq 2025-12-23 13:19:26 +11:00
parent d0c6c94e9d
commit b925d2e89e
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
2 changed files with 22 additions and 3 deletions

View file

@ -1,6 +1,7 @@
# 0.7.6 # 0.7.6
* Add .desktop file for Debian * Add .desktop file for Debian
* Fix Pomodoro timer rounding so it rounds up to 0.25, but rounds to closest quarter (up or down) for minutes higher than that, instead of always up to next quarter.
# 0.7.5 # 0.7.5

View file

@ -111,6 +111,25 @@ class PomodoroManager:
self._parent = parent_window self._parent = parent_window
self._active_timer: Optional[PomodoroTimer] = None self._active_timer: Optional[PomodoroTimer] = None
@staticmethod
def _seconds_to_logged_hours(elapsed_seconds: int) -> float:
"""Convert elapsed seconds to decimal hours for logging.
Rules:
- For very short runs (< 15 minutes), always round up to 0.25h (15 minutes).
- Otherwise, round to the closest 0.25h (15-minute) increment.
Halfway cases (e.g., 22.5 minutes) round up.
"""
if elapsed_seconds < 0:
elapsed_seconds = 0
# 15 minutes = 900 seconds
if elapsed_seconds < 900:
return 0.25
quarters = int(math.floor((elapsed_seconds / 900.0) + 0.5))
return quarters * 0.25
def start_timer_for_line(self, line_text: str, date_iso: str): def start_timer_for_line(self, line_text: str, date_iso: str):
""" """
Start a new timer for the given line of text and embed it into the Start a new timer for the given line of text and embed it into the
@ -156,9 +175,8 @@ class PomodoroManager:
def _on_timer_stopped(self, elapsed_seconds: int, task_text: str, date_iso: str): def _on_timer_stopped(self, elapsed_seconds: int, task_text: str, date_iso: str):
"""Handle timer stop - open time log dialog with pre-filled data.""" """Handle timer stop - open time log dialog with pre-filled data."""
# Convert seconds to decimal hours, rounding up to the nearest 0.25 hour (15 minutes) # Convert seconds to decimal hours, and handle rounding up or down
quarter_hours = math.ceil(elapsed_seconds / 900) hours = self._seconds_to_logged_hours(elapsed_seconds)
hours = quarter_hours * 0.25
# Ensure minimum of 0.25 hours # Ensure minimum of 0.25 hours
if hours < 0.25: if hours < 0.25: