25 lines
775 B
Python
25 lines
775 B
Python
"""Shared utilities for Video Library Manager."""
|
|||
|
|
|
||
|
|
from datetime import datetime, timezone
|
||
|
|
|
||
|
|
|
||
|
|
def utc_now() -> datetime:
|
||
|
|
"""Return current UTC time (timezone-aware)."""
|
||
|
|
return datetime.now(timezone.utc)
|
||
|
|
|
||
|
|
|
||
|
|
def ensure_utc(dt: datetime) -> datetime:
|
||
|
|
"""Ensure datetime is timezone-aware UTC (for backward compatibility with naive ISO strings)."""
|
||
|
|
if dt.tzinfo is None:
|
||
|
|
return dt.replace(tzinfo=timezone.utc)
|
||
|
|
return dt.astimezone(timezone.utc)
|
||
|
|
|
||
|
|
|
||
|
|
def format_size(size_bytes: int) -> str:
|
||
|
|
"""Format file size in human-readable format (e.g. 1.5 GB, 234.2 MB)."""
|
||
|
|
for unit in ["B", "KB", "MB", "GB", "TB"]:
|
||
|
|
if size_bytes < 1024.0:
|
||
|
|
return f"{size_bytes:.1f} {unit}"
|
||
|
|
size_bytes /= 1024.0
|
||
|
|
return f"{size_bytes:.1f} PB"
|