Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Owner's local time in AI prompt dates, export filenames, exported text and Word downloads (#412, Df); export filename tests pin the default timezone

Murtaza Nasir64b6e3d6393c
diff --git a/src/api/recordings.py b/src/api/recordings.py
index 6b45cb62..84b7cc7f 100644
--- a/src/api/recordings.py
+++ b/src/api/recordings.py
@@ -407,9 +407,10 @@ def download_summary_word(recording_id):
return p
# Add metadata
- add_unicode_paragraph(doc, f'Uploaded: {recording.created_at.strftime("%Y-%m-%d %H:%M")}')
+ from src.utils.timezones import to_user_local # owner's local time (#412)
+ add_unicode_paragraph(doc, f'Uploaded: {to_user_local(recording.created_at, recording.owner).strftime("%Y-%m-%d %H:%M")}')
if recording.meeting_date:
- add_unicode_paragraph(doc, f'Recording Date: {recording.meeting_date.strftime("%Y-%m-%d")}')
+ add_unicode_paragraph(doc, f'Recording Date: {to_user_local(recording.meeting_date, recording.owner).strftime("%Y-%m-%d")}')
if recording.participants:
add_unicode_paragraph(doc, f'Participants: {recording.participants}')
visible_tags = recording.get_visible_tags(current_user)
@@ -524,8 +525,9 @@ def download_chat_word(recording_id):
return p
# Add metadata
- add_unicode_paragraph(doc, f'Recording Date: {recording.created_at.strftime("%Y-%m-%d %H:%M")}')
- add_unicode_paragraph(doc, f'Chat Export Date: {datetime.utcnow().strftime("%Y-%m-%d %H:%M")}')
+ from src.utils.timezones import to_user_local, now_local, user_timezone # owner's local time (#412)
+ add_unicode_paragraph(doc, f'Recording Date: {to_user_local(recording.meeting_date or recording.created_at, recording.owner).strftime("%Y-%m-%d %H:%M")}')
+ add_unicode_paragraph(doc, f'Chat Export Date: {now_local(user_timezone(current_user)).strftime("%Y-%m-%d %H:%M")}')
doc.add_paragraph('') # Empty line
# Add chat messages
@@ -658,9 +660,10 @@ def download_notes_word(recording_id):
return p
# Add metadata
- add_unicode_paragraph(doc, f'Uploaded: {recording.created_at.strftime("%Y-%m-%d %H:%M")}')
+ from src.utils.timezones import to_user_local # owner's local time (#412)
+ add_unicode_paragraph(doc, f'Uploaded: {to_user_local(recording.created_at, recording.owner).strftime("%Y-%m-%d %H:%M")}')
if recording.meeting_date:
- add_unicode_paragraph(doc, f'Recording Date: {recording.meeting_date.strftime("%Y-%m-%d")}')
+ add_unicode_paragraph(doc, f'Recording Date: {to_user_local(recording.meeting_date, recording.owner).strftime("%Y-%m-%d")}')
if recording.participants:
add_unicode_paragraph(doc, f'Participants: {recording.participants}')
visible_tags = recording.get_visible_tags(current_user)
diff --git a/src/file_exporter.py b/src/file_exporter.py
index 5c8cd4ca..da56278d 100644
--- a/src/file_exporter.py
+++ b/src/file_exporter.py
@@ -181,7 +181,9 @@ def render_export_filename(recording, user):
if not template:
template = DEFAULT_EXPORT_FILENAME_TEMPLATE
- dt = recording.meeting_date or recording.created_at
+ # Dates in export filenames are the owner's local time (#412).
+ from src.utils.timezones import to_user_local
+ dt = to_user_local(recording.meeting_date or recording.created_at, user)
filename_stem = os.path.splitext(recording.original_filename)[0] if recording.original_filename else ''
variables = {
@@ -582,12 +584,16 @@ def generate_from_template(recording, user, template_str, labels, user_language,
Rendered markdown string
"""
from src.utils.localization import format_date_localized, format_datetime_localized
+ # Dates in exported text are the owner's local time (#412).
+ from src.utils.timezones import to_user_local
+ def _local(dt):
+ return to_user_local(dt, recording.owner)
# Build context with all available variables
context = {
'title': recording.title or f"Recording {recording.id}",
- 'meeting_date': format_date_localized(recording.meeting_date, user_language) if recording.meeting_date else '',
- 'created_at': format_datetime_localized(recording.created_at, user_language) if recording.created_at else '',
+ 'meeting_date': format_date_localized(_local(recording.meeting_date), user_language) if recording.meeting_date else '',
+ 'created_at': format_datetime_localized(_local(recording.created_at), user_language) if recording.created_at else '',
'original_filename': recording.original_filename or '',
'file_size': format_file_size(recording.file_size) if recording.file_size else '',
'participants': recording.participants or '',
@@ -630,6 +636,10 @@ def generate_default_markdown(recording, user, labels, user_language,
Rendered markdown string
"""
from src.utils.localization import format_date_localized, format_datetime_localized
+ # Dates in exported text are the owner's local time (#412).
+ from src.utils.timezones import to_user_local
+ def _local(dt):
+ return to_user_local(dt, recording.owner)
lines = []
@@ -643,11 +653,11 @@ def generate_default_markdown(recording, user, labels, user_language,
lines.append("")
if recording.meeting_date:
- date_str = format_date_localized(recording.meeting_date, user_language)
+ date_str = format_date_localized(_local(recording.meeting_date), user_language)
lines.append(f"- **{labels.get('date', 'Date')}:** {date_str}")
if recording.created_at:
- created_str = format_datetime_localized(recording.created_at, user_language)
+ created_str = format_datetime_localized(_local(recording.created_at), user_language)
lines.append(f"- **{labels.get('created', 'Created')}:** {created_str}")
if recording.original_filename:
diff --git a/src/tasks/processing.py b/src/tasks/processing.py
index 1d16c522..d1c8e81d 100644
--- a/src/tasks/processing.py
+++ b/src/tasks/processing.py
@@ -807,14 +807,16 @@ def generate_summary_only_task(app_context, recording_id, custom_prompt_override
summarization_instructions, prompt_variables
)
- # Build context information
- current_date = datetime.now().strftime("%B %d, %Y")
+ # Build context information. Dates are in the owner's local time (#412).
+ from src.utils.timezones import now_local, to_local, user_timezone
+ _zone = user_timezone(recording.owner)
+ current_date = now_local(_zone).strftime("%B %d, %Y")
context_parts = []
context_parts.append(f"Current date: {current_date}")
# Add recording metadata to context
if recording.meeting_date:
- context_parts.append(f"Recording date: {recording.meeting_date.strftime('%B %d, %Y')}")
+ context_parts.append(f"Recording date: {to_local(recording.meeting_date, _zone).strftime('%B %d, %Y')}")
if recording.title:
context_parts.append(f"Recording title: {recording.title}")
@@ -983,8 +985,14 @@ def extract_events_from_transcript(recording_id, transcript_text, summary_text):
body = transcript_text if limit == -1 else transcript_text[:limit]
events_source = f"Transcript:\n{body}"
- # Build comprehensive context information
- current_date = datetime.now()
+ # Build comprehensive context information. All dates are the owner's
+ # local calendar (#412): relative dates such as "tomorrow" are counted
+ # from the local day, and the event times returned are local wall-clock.
+ from src.utils.timezones import now_local, to_local, user_timezone
+ _zone = user_timezone(recording.owner)
+ current_date = now_local(_zone)
+ local_meeting = to_local(recording.meeting_date, _zone)
+ local_created = to_local(recording.created_at, _zone)
context_parts = []
# CRITICAL: Determine the reference date for relative date calculations
@@ -993,25 +1001,25 @@ def extract_events_from_transcript(recording_id, transcript_text, summary_text):
if recording.meeting_date:
# Prefer meeting date if available
- reference_date = recording.meeting_date
+ reference_date = local_meeting
reference_date_source = "Meeting Date"
- context_parts.append(f"**MEETING DATE (use this for relative date calculations): {recording.meeting_date.strftime('%A, %B %d, %Y')}**")
+ context_parts.append(f"**MEETING DATE (use this for relative date calculations): {local_meeting.strftime('%A, %B %d, %Y')}**")
elif recording.created_at:
# Fall back to upload date
- reference_date = recording.created_at.date()
+ reference_date = local_created.date()
reference_date_source = "Upload Date (no meeting date available)"
- context_parts.append(f"**REFERENCE DATE (use this for relative date calculations): {recording.created_at.strftime('%A, %B %d, %Y')}**")
+ context_parts.append(f"**REFERENCE DATE (use this for relative date calculations): {local_created.strftime('%A, %B %d, %Y')}**")
context_parts.append(f"Today's actual date: {current_date.strftime('%A, %B %d, %Y')}")
context_parts.append(f"Current time: {current_date.strftime('%I:%M %p')}")
# Add additional recording context
if recording.created_at:
- context_parts.append(f"Recording uploaded on: {recording.created_at.strftime('%B %d, %Y at %I:%M %p')}")
+ context_parts.append(f"Recording uploaded on: {local_created.strftime('%B %d, %Y at %I:%M %p')}")
if recording.meeting_date and reference_date_source == "Meeting Date":
# Calculate days between meeting and today for context
# Ensure both sides are date objects (meeting_date might be datetime or date)
- meeting_date_obj = recording.meeting_date.date() if isinstance(recording.meeting_date, datetime) else recording.meeting_date
+ meeting_date_obj = local_meeting.date() if isinstance(local_meeting, datetime) else local_meeting
days_since = (current_date.date() - meeting_date_obj).days
if days_since == 0:
context_parts.append("This meeting happened today")
diff --git a/tests/test_export_filename_template.py b/tests/test_export_filename_template.py
index 26063c6d..13bf374d 100644
--- a/tests/test_export_filename_template.py
+++ b/tests/test_export_filename_template.py
@@ -17,6 +17,7 @@ SHARED-DB: every assertion is scoped to the user/recordings the test created.
"""
import os
+import pytest
import shutil
import sys
import tempfile
@@ -123,6 +124,15 @@ def test_custom_template_renders_variables():
)
[email protected](autouse=True)
+def _utc_default_timezone():
+ """Export dates use the owner's zone, else the admin default (#412). Pin
+ the default to UTC so these tests do not depend on the instance setting."""
+ from unittest.mock import patch
+ with patch("src.utils.timezones.deployment_timezone", return_value="UTC"):
+ yield
+
+
def test_date_variables_fall_back_to_created_at():
with app.app_context():
user = _mk_user(template="{{year}}-{{month}}-{{day}} {{time}}")
diff --git a/tests/test_local_dates_in_text.py b/tests/test_local_dates_in_text.py
new file mode 100644
index 00000000..d7efef80
--- /dev/null
+++ b/tests/test_local_dates_in_text.py
@@ -0,0 +1,87 @@
+"""Dates the server writes into text use the owner's local time (#412, Df).
+
+Export filenames, exported text and the dates given to the LLM in the summary
+and event prompts were written in UTC. For an owner in Tokyo, a meeting at
+2026-03-04 23:30 UTC happened on 5 March.
+
+SHARED-DB: the user and recording are removed afterwards.
+"""
+
+import os
+import sys
+import uuid
+from datetime import datetime
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+from src.app import app, db
+from src.models import Recording, User
+import src.tasks.processing as proc
+from src.file_exporter import render_export_filename
+
+
+def rec():
+ with app.app_context():
+ s = uuid.uuid4().hex[:8]
+ u = User(username=f"loc_{s}", email=f"loc_{s}@local.test", password="x",
+ timezone="Asia/Tokyo", timezone_mode="fixed", extract_events=True,
+ export_filename_template="{{date}} {{title}}")
+ db.session.add(u)
+ db.session.commit()
+ r = Recording(user_id=u.id, title="Standup", original_filename="s.wav", status="PROCESSING",
+ transcription="Speaker 1: " + "We meet again tomorrow at ten. " * 5,
+ meeting_date=datetime(2026, 3, 4, 23, 30), created_at=datetime(2026, 3, 4, 23, 40))
+ db.session.add(r)
+ db.session.commit()
+ ids = (u.id, r.id)
+ yield ids
+ with app.app_context():
+ for model, oid in ((Recording, ids[1]), (User, ids[0])):
+ obj = db.session.get(model, oid)
+ if obj is not None:
+ db.session.delete(obj)
+ db.session.commit()
+
+
+def _capture():
+ seen = []
+
+ def fake(messages, **kwargs):
+ seen.append("\n".join(m["content"] for m in messages))
+ msg = MagicMock(content='{"events": []}', reasoning=None)
+ return MagicMock(choices=[MagicMock(message=msg)])
+ return seen, fake
+
+
+def test_export_filename_date_is_local(rec):
+ uid, rid = rec
+ with app.app_context():
+ name = render_export_filename(db.session.get(Recording, rid), db.session.get(User, uid))
+ assert "2026-03-05" in name and "2026-03-04" not in name
+
+
+def test_summary_prompt_recording_date_is_local(rec):
+ uid, rid = rec
+ seen, fake = _capture()
+ with app.app_context(), patch.object(proc, "client", MagicMock()), \
+ patch.object(proc, "call_llm_completion", side_effect=fake), \
+ patch.object(proc, "extract_events_from_transcript"), \
+ patch.object(proc, "apply_team_tag_auto_shares"), patch.object(proc, "export_recording"), \
+ patch.object(proc, "process_recording_chunks"):
+ proc.generate_summary_only_task(app.app_context(), rid)
+ assert any("Recording date: March 05, 2026" in p for p in seen)
+
+
+def test_event_prompt_reference_dates_are_local(rec):
+ uid, rid = rec
+ seen, fake = _capture()
+ with app.app_context(), patch.object(proc, "call_llm_completion", side_effect=fake), \
+ patch.object(proc, "client", MagicMock()):
+ proc.extract_events_from_transcript(rid, "We meet again tomorrow at ten.", "")
+ prompt = seen[0]
+ assert "MEETING DATE (use this for relative date calculations): Thursday, March 05, 2026" in prompt
+ assert "Recording uploaded on: March 05, 2026 at 08:40 AM" in prompt