updates
This commit is contained in:
39
src/jellycleanarr/utils/formatters.py
Normal file
39
src/jellycleanarr/utils/formatters.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""Formatting utilities for display."""
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
def format_duration(seconds: int) -> str:
|
||||
"""
|
||||
Format duration in seconds to human-readable string.
|
||||
|
||||
Args:
|
||||
seconds: Duration in seconds
|
||||
|
||||
Returns:
|
||||
Formatted string like "5d 12h 30m" or "2h 15m" or "45m"
|
||||
"""
|
||||
td = timedelta(seconds=seconds)
|
||||
days = td.days
|
||||
hours = td.seconds // 3600
|
||||
minutes = (td.seconds % 3600) // 60
|
||||
|
||||
if days > 0:
|
||||
return f"{days}d {hours}h {minutes}m"
|
||||
elif hours > 0:
|
||||
return f"{hours}h {minutes}m"
|
||||
else:
|
||||
return f"{minutes}m"
|
||||
|
||||
|
||||
def format_number(num: int) -> str:
|
||||
"""
|
||||
Format large numbers with thousand separators.
|
||||
|
||||
Args:
|
||||
num: Number to format
|
||||
|
||||
Returns:
|
||||
Formatted string with commas (e.g., "1,234,567")
|
||||
"""
|
||||
return f"{num:,}"
|
||||
Reference in New Issue
Block a user