Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: O365Toolkit - send_event - fixed timezone error #25876

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions libs/community/langchain_community/tools/office365/send_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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
Expand Down Expand Up @@ -73,12 +74,22 @@ def _run(

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)
Expand Down
Loading