feat: complete timezone support for NFO dateadded fields
- Fix NFO dateadded timestamps to use local timezone instead of UTC - Convert Radarr/Sonarr import dates from UTC to local timezone for NFO files - Update webhook episode processing to use local time for new downloads - Convert file modification time fallbacks to local timezone - Preserve historical dates (aired, premiered) in original UTC format - Replace all placeholder logging functions with centralized timezone-aware logging - Add convert_utc_to_local() utility function for timestamp conversion - Now all logs AND NFO files show consistent local timezone formatting Users with TZ=America/New_York will now see: - Logs: [2025-09-14T09:37:00-04:00] - NFO files: <dateadded>2025-09-14T09:37:00-04:00</dateadded>
This commit is contained in:
+1
-4
@@ -7,10 +7,7 @@ from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, List, Optional, Tuple, Any
|
||||
|
||||
|
||||
def _log(level: str, msg: str):
|
||||
"""Placeholder logging function - replace with your actual logger"""
|
||||
print(f"[{datetime.now().isoformat()}] {level}: {msg}")
|
||||
from core.logging import _log
|
||||
|
||||
|
||||
class NFOGuardDatabase:
|
||||
|
||||
+25
-1
@@ -26,4 +26,28 @@ def _get_local_timezone():
|
||||
def _log(level: str, msg: str):
|
||||
"""Basic logging function that writes to console"""
|
||||
tz = _get_local_timezone()
|
||||
print(f"[{datetime.now(tz).isoformat(timespec='seconds')}] {level}: {msg}")
|
||||
print(f"[{datetime.now(tz).isoformat(timespec='seconds')}] {level}: {msg}")
|
||||
|
||||
def convert_utc_to_local(utc_iso_string: str) -> str:
|
||||
"""Convert UTC ISO timestamp to local timezone timestamp"""
|
||||
if not utc_iso_string:
|
||||
return utc_iso_string
|
||||
|
||||
try:
|
||||
# Parse UTC timestamp
|
||||
if utc_iso_string.endswith('Z'):
|
||||
dt_utc = datetime.fromisoformat(utc_iso_string.replace('Z', '+00:00'))
|
||||
elif '+00:00' in utc_iso_string:
|
||||
dt_utc = datetime.fromisoformat(utc_iso_string)
|
||||
else:
|
||||
# Assume UTC if no timezone info
|
||||
dt_utc = datetime.fromisoformat(utc_iso_string).replace(tzinfo=timezone.utc)
|
||||
|
||||
# Convert to local timezone
|
||||
local_tz = _get_local_timezone()
|
||||
dt_local = dt_utc.astimezone(local_tz)
|
||||
|
||||
return dt_local.isoformat(timespec='seconds')
|
||||
except Exception:
|
||||
# If conversion fails, return original
|
||||
return utc_iso_string
|
||||
+1
-4
@@ -9,10 +9,7 @@ from datetime import datetime, timezone
|
||||
from typing import Optional, Dict, Any
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
def _log(level: str, msg: str):
|
||||
"""Placeholder logging function - replace with your actual logger"""
|
||||
print(f"[{datetime.now().isoformat()}] {level}: {msg}")
|
||||
from core.logging import _log
|
||||
|
||||
|
||||
class NFOManager:
|
||||
|
||||
+1
-4
@@ -9,10 +9,7 @@ from pathlib import Path
|
||||
from datetime import datetime
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
|
||||
def _log(level: str, msg: str):
|
||||
"""Placeholder logging function - replace with your actual logger"""
|
||||
print(f"[{datetime.now().isoformat()}] {level}: {msg}")
|
||||
from core.logging import _log
|
||||
|
||||
|
||||
class PathMapper:
|
||||
|
||||
Reference in New Issue
Block a user