Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions bottles/frontend/utils/playtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,7 @@ def format_playtime(total_seconds: int) -> str:
Rules:
- < 60s: "<1m"
- < 3600s: "MMm"
- < 86400s: "Hh MMm"
- >= 86400s: "Dd HHh"
- >= 3600s: "Hh MMm"
Args:
total_seconds: Total accumulated playtime in seconds.
Expand All @@ -460,16 +459,11 @@ def format_playtime(total_seconds: int) -> str:
# Less than an hour: show minutes only
minutes = td.seconds // 60
return f"{minutes}m"
elif total_seconds < 86400:
# Less than a day: show hours and minutes
hours = td.seconds // 3600
minutes = (td.seconds % 3600) // 60
return f"{hours}h {minutes:02d}m"
else:
# A day or more: show days and hours
days = td.days
hours = td.seconds // 3600
return f"{days}d {hours:02d}h"
# One hour or more: show total hours and minutes
hours = total_seconds // 3600
minutes = (total_seconds % 3600) // 60
return f"{hours}h {minutes:02d}m"

@staticmethod
def format_last_played(last_played: Optional[datetime]) -> str:
Expand Down
8 changes: 5 additions & 3 deletions bottles/tests/frontend/test_playtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ def test_format_playtime():
assert PlaytimeService.format_playtime(3600) == "1h 00m"
assert PlaytimeService.format_playtime(3660) == "1h 01m"
assert PlaytimeService.format_playtime(7325) == "2h 02m"
assert PlaytimeService.format_playtime(86400) == "1d 00h"
assert PlaytimeService.format_playtime(90000) == "1d 01h"
assert PlaytimeService.format_playtime(180000) == "2d 02h"
assert PlaytimeService.format_playtime(86400) == "24h 00m"
assert PlaytimeService.format_playtime(90000) == "25h 00m"
assert PlaytimeService.format_playtime(180000) == "50h 00m"
assert PlaytimeService.format_playtime(86461) == "24h 01m"
assert PlaytimeService.format_playtime(180125) == "50h 02m"


def test_format_last_played():
Expand Down
Loading