From 29305cd94861b25cf812f5d1c2bb06cc819a9b69 Mon Sep 17 00:00:00 2001 From: SirSmokeAlot <63344636+SirNotReallySmokeAlot@users.noreply.github.com> Date: Mon, 16 Dec 2024 06:32:28 +0100 Subject: [PATCH] community: O365Toolkit - send_event - fixed timezone error (#25876) **Description**: Fixed formatting start and end time **Issue**: The old formatting resulted everytime in an timezone error **Dependencies**: / **Twitter handle**: / --------- Co-authored-by: Yannick Opitz Co-authored-by: Erick Friis --- .../tools/office365/send_event.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/tools/office365/send_event.py b/libs/community/langchain_community/tools/office365/send_event.py index b6916d9ae14..e7513025ac1 100644 --- a/libs/community/langchain_community/tools/office365/send_event.py +++ b/libs/community/langchain_community/tools/office365/send_event.py @@ -9,6 +9,7 @@ from typing import List, Optional, Type from langchain_core.callbacks import CallbackManagerForToolRun from pydantic import BaseModel, Field +from zoneinfo import ZoneInfo from langchain_community.tools.office365.base import O365BaseTool from langchain_community.tools.office365.utils import UTC_FORMAT @@ -73,12 +74,22 @@ class O365SendEvent(O365BaseTool): # type: ignore[override, override] event.body = body event.subject = subject - event.start = dt.strptime(start_datetime, UTC_FORMAT) - event.end = dt.strptime(end_datetime, UTC_FORMAT) + try: + event.start = dt.fromisoformat(start_datetime).replace( + tzinfo=ZoneInfo("UTC") + ) + except ValueError: + # fallback for backwards compatibility + event.start = dt.strptime(start_datetime, UTC_FORMAT) + try: + event.end = dt.fromisoformat(end_datetime).replace(tzinfo=ZoneInfo("UTC")) + except ValueError: + # fallback for backwards compatibility + event.end = dt.strptime(end_datetime, UTC_FORMAT) + for attendee in attendees: event.attendees.add(attendee) - # TO-DO: Look into PytzUsageWarning event.save() output = "Event sent: " + str(event)