From 8496c347abc65f48ca5073b987a1cd03f28def4a Mon Sep 17 00:00:00 2001 From: Chris Mullins Date: Mon, 13 Oct 2025 15:59:15 -0700 Subject: [PATCH] Refactor timestamp handling in FileTranscriptStore and update related tests for consistency --- .../hosting/core/storage/transcript_file_store.py | 6 +----- tests/hosting_core/storage/test_file_transcript_storage.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_file_store.py b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_file_store.py index 7f9d37ad..d40bf092 100644 --- a/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_file_store.py +++ b/libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_file_store.py @@ -71,7 +71,7 @@ async def log_activity(self, activity: Activity) -> None: def _write() -> None: # Normalize to a dict to ensure json serializable content. if not activity.timestamp: - activity.timestamp = _utc_iso_now() + activity.timestamp = datetime.now(timezone.utc) with open(file_path, "a", encoding="utf-8", newline="\n") as f: f.write(activity.model_dump_json(exclude_none=True, exclude_unset=True)) @@ -261,7 +261,3 @@ def _to_plain_dict(activity: Activity) -> Dict[str, Any]: "conversation": {"id": conversation_id}, "text": getattr(activity, "text", None), } - - -def _utc_iso_now() -> str: - return datetime.now(timezone.utc).isoformat() diff --git a/tests/hosting_core/storage/test_file_transcript_storage.py b/tests/hosting_core/storage/test_file_transcript_storage.py index 84eb685e..70e4cf4e 100644 --- a/tests/hosting_core/storage/test_file_transcript_storage.py +++ b/tests/hosting_core/storage/test_file_transcript_storage.py @@ -134,8 +134,8 @@ async def test_get_transcript_activities_with_paging(temp_logger: FileTranscript async def test_get_transcript_activities_with_start_date_filter( temp_logger: FileTranscriptStore, ): - old_ts = (datetime.now(timezone.utc) - timedelta(days=2)).isoformat() - new_ts = datetime.now(timezone.utc).isoformat() + old_ts = datetime.now(timezone.utc) - timedelta(days=2) + new_ts = datetime.now(timezone.utc) activity1 = make_activity(conv="filtered", text="old") activity2 = make_activity(conv="filtered", text="new")