fix timezone handling and logging fallback robustness
This commit is contained in:
+9
-10
@@ -19,6 +19,13 @@ from vlm.models import SeasonCompleteness, DuplicateGroup, VideoFile, MovieIdent
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _normalize_to_utc(timestamp: datetime) -> datetime:
|
||||
"""Normalize a datetime to a UTC instant."""
|
||||
if timestamp.tzinfo is None:
|
||||
timestamp = timestamp.astimezone()
|
||||
return timestamp.astimezone(timezone.utc)
|
||||
|
||||
|
||||
def generate_inventory_report(
|
||||
files: list[VideoFile],
|
||||
format: str,
|
||||
@@ -87,11 +94,7 @@ def _generate_inventory_csv(
|
||||
# Write each file
|
||||
for video_file in files:
|
||||
# Format timestamp as ISO 8601 in UTC
|
||||
if video_file.modified_timestamp.tzinfo is None:
|
||||
# Assume local time, convert to UTC
|
||||
modified_utc = video_file.modified_timestamp.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
modified_utc = video_file.modified_timestamp.astimezone(timezone.utc)
|
||||
modified_utc = _normalize_to_utc(video_file.modified_timestamp)
|
||||
|
||||
row = {
|
||||
'path': str(video_file.path),
|
||||
@@ -127,11 +130,7 @@ def _generate_inventory_json(
|
||||
# Add each file
|
||||
for video_file in files:
|
||||
# Format timestamp as ISO 8601 in UTC
|
||||
if video_file.modified_timestamp.tzinfo is None:
|
||||
# Assume local time, convert to UTC
|
||||
modified_utc = video_file.modified_timestamp.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
modified_utc = video_file.modified_timestamp.astimezone(timezone.utc)
|
||||
modified_utc = _normalize_to_utc(video_file.modified_timestamp)
|
||||
|
||||
file_data = {
|
||||
'path': str(video_file.path),
|
||||
|
||||
Reference in New Issue
Block a user