Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: Use user's timezone for news subscription date placeholder (#1173)

LearningCircuit9fd4e74df5e9
diff --git a/.pre-commit-hooks/check-env-vars.py b/.pre-commit-hooks/check-env-vars.py
index 6df0e3d6f2..c636ea19d5 100755
--- a/.pre-commit-hooks/check-env-vars.py
+++ b/.pre-commit-hooks/check-env-vars.py
@@ -43,6 +43,7 @@ SYSTEM_VARS = {
"PYTHONPATH",
"TMPDIR",
"TEMP",
+ "TZ", # Standard POSIX timezone variable
"DEBUG",
"CI",
"GITHUB_ACTIONS",
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index d6ef4b5a2d..00af2a521f 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -69,6 +69,35 @@
"value": false,
"visible": true
},
+ "app.timezone": {
+ "category": "app_interface",
+ "description": "Timezone for date calculations (e.g., news subscription YYYY-MM-DD placeholder). Use 'UTC' for server time or specify your local timezone.",
+ "editable": true,
+ "env_var": "TZ",
+ "max_value": null,
+ "min_value": null,
+ "name": "Timezone",
+ "options": [
+ "UTC",
+ "US/Eastern",
+ "US/Central",
+ "US/Mountain",
+ "US/Pacific",
+ "Europe/London",
+ "Europe/Paris",
+ "Europe/Berlin",
+ "Asia/Tokyo",
+ "Asia/Shanghai",
+ "Asia/Kolkata",
+ "Australia/Sydney",
+ "Pacific/Auckland"
+ ],
+ "step": null,
+ "type": "APP",
+ "ui_element": "select",
+ "value": "UTC",
+ "visible": true
+ },
"app.max_concurrent_researches": {
"category": "app_interface",
"description": "Maximum number of concurrent research processes allowed per user",
diff --git a/src/local_deep_research/news/core/utils.py b/src/local_deep_research/news/core/utils.py
index f3d2f190a6..690391d3cd 100644
--- a/src/local_deep_research/news/core/utils.py
+++ b/src/local_deep_research/news/core/utils.py
@@ -2,8 +2,58 @@
Core utilities for the news system.
"""
+import os
import uuid
from datetime import datetime, timezone
+from zoneinfo import ZoneInfo
+
+from loguru import logger
+
+
+def get_local_date_string(settings_manager=None) -> str:
+ """
+ Get the current date as a string in the user's configured timezone.
+
+ This is used for replacing the YYYY-MM-DD placeholder in news subscriptions.
+ The timezone can be configured via:
+ 1. The 'app.timezone' setting in the database
+ 2. The TZ environment variable
+ 3. Falls back to UTC if neither is set
+
+ Args:
+ settings_manager: Optional settings manager to read timezone setting from.
+ If not provided, will check TZ env var or default to UTC.
+
+ Returns:
+ str: Current date in ISO format (YYYY-MM-DD) in the configured timezone
+ """
+ tz_name = None
+
+ # Try to get timezone from settings
+ if settings_manager is not None:
+ try:
+ tz_name = settings_manager.get_setting("app.timezone")
+ except Exception as e:
+ logger.debug(f"Could not read timezone from settings: {e}")
+
+ # Fall back to TZ environment variable
+ if not tz_name:
+ tz_name = os.environ.get("TZ")
+
+ # Default to UTC if nothing is configured
+ if not tz_name:
+ tz_name = "UTC"
+
+ try:
+ tz = ZoneInfo(tz_name)
+ local_date = datetime.now(tz).date()
+ logger.debug(f"Using timezone {tz_name}, local date is {local_date}")
+ return local_date.isoformat()
+ except Exception as e:
+ logger.warning(
+ f"Invalid timezone '{tz_name}', falling back to UTC: {e}"
+ )
+ return datetime.now(timezone.utc).date().isoformat()
def generate_card_id() -> str:
diff --git a/src/local_deep_research/news/flask_api.py b/src/local_deep_research/news/flask_api.py
index 2c1e89c7e2..3873a088a1 100644
--- a/src/local_deep_research/news/flask_api.py
+++ b/src/local_deep_research/news/flask_api.py
@@ -514,13 +514,13 @@ def run_subscription_now(subscription_id: str) -> Dict[str, Any]:
return jsonify({"error": "Subscription not found"}), 404
# Use the same simple approach as the news page
- from datetime import datetime, UTC
+ from .core.utils import get_local_date_string
# Get the query and update dates
query = subscription["query"]
- # Update any date placeholders with current date
- current_date = datetime.now(UTC).date().isoformat()
+ # Update any date placeholders with current date in user's timezone
+ current_date = get_local_date_string()
# Replace YYYY-MM-DD placeholder ONLY (not all dates)
query = query.replace("YYYY-MM-DD", current_date)
@@ -998,6 +998,13 @@ def check_overdue_subscriptions():
f"Found {len(overdue_subs)} overdue subscriptions for {username}"
)
+ # Get timezone-aware current date using settings
+ from .core.utils import get_local_date_string
+ from ..settings.manager import SettingsManager
+
+ settings_manager = SettingsManager(db)
+ current_date = get_local_date_string(settings_manager)
+
for sub in overdue_subs:
try:
# Run the subscription using the same pattern as run_subscription_now
@@ -1005,8 +1012,7 @@ def check_overdue_subscriptions():
f"Running overdue subscription: {sub.name or sub.query_or_topic[:30]}"
)
- # Update any date placeholders with current date
- current_date = datetime.now(UTC).date().isoformat()
+ # Update any date placeholders with current date in user's timezone
query = sub.query_or_topic.replace(
"YYYY-MM-DD", current_date
)
diff --git a/src/local_deep_research/news/subscription_manager/scheduler.py b/src/local_deep_research/news/subscription_manager/scheduler.py
index e432e19e45..b62db609da 100644
--- a/src/local_deep_research/news/subscription_manager/scheduler.py
+++ b/src/local_deep_research/news/subscription_manager/scheduler.py
@@ -1056,12 +1056,15 @@ class NewsScheduler:
)
return
- # Prepare query with date replacement
+ # Prepare query with date replacement using user's timezone
query = sub.query_or_topic
if "YYYY-MM-DD" in query:
- query = query.replace(
- "YYYY-MM-DD", datetime.now(UTC).date().isoformat()
- )
+ from ..core.utils import get_local_date_string
+ from ...settings.manager import SettingsManager
+
+ settings_manager = SettingsManager(db)
+ local_date = get_local_date_string(settings_manager)
+ query = query.replace("YYYY-MM-DD", local_date)
# Update last/next refresh times
sub.last_refresh = datetime.now(UTC)
diff --git a/src/local_deep_research/news/subscription_manager/search_subscription.py b/src/local_deep_research/news/subscription_manager/search_subscription.py
index f24e164201..746781e6ff 100644
--- a/src/local_deep_research/news/subscription_manager/search_subscription.py
+++ b/src/local_deep_research/news/subscription_manager/search_subscription.py
@@ -4,7 +4,6 @@ This is the killer feature: turning searches into living news feeds.
"""
from typing import Optional, Dict, Any
-from datetime import datetime, UTC
from loguru import logger
from .base_subscription import BaseSubscription
@@ -84,8 +83,10 @@ class SearchSubscription(BaseSubscription):
Returns:
str: The transformed search query
"""
- # Update any date placeholders with current date
- current_date = datetime.now(UTC).date().isoformat()
+ # Update any date placeholders with current date in user's timezone
+ from ..core.utils import get_local_date_string
+
+ current_date = get_local_date_string()
updated_query = self.current_query
# Replace YYYY-MM-DD placeholder ONLY (not all dates)
diff --git a/src/local_deep_research/news/subscription_manager/topic_subscription.py b/src/local_deep_research/news/subscription_manager/topic_subscription.py
index 226ae35a95..04bd105779 100644
--- a/src/local_deep_research/news/subscription_manager/topic_subscription.py
+++ b/src/local_deep_research/news/subscription_manager/topic_subscription.py
@@ -4,7 +4,6 @@ Topics are extracted from news analysis and can evolve over time.
"""
from typing import Optional, Dict, Any, List
-from datetime import datetime, UTC
from loguru import logger
from .base_subscription import BaseSubscription
@@ -97,8 +96,10 @@ class TopicSubscription(BaseSubscription):
base_query = " OR ".join(f'"{part}"' for part in query_parts)
news_query = f"{base_query} latest news today developments breaking"
- # Update any date placeholders with current date
- current_date = datetime.now(UTC).date().isoformat()
+ # Update any date placeholders with current date in user's timezone
+ from ..core.utils import get_local_date_string
+
+ current_date = get_local_date_string()
# Replace YYYY-MM-DD placeholder ONLY (not all dates)
news_query = news_query.replace("YYYY-MM-DD", current_date)