mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 15:43:54 +00:00
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 <yannick.opitz@gob.de> Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
4f6ccb7080
commit
29305cd948
@ -9,6 +9,7 @@ from typing import List, Optional, Type
|
|||||||
|
|
||||||
from langchain_core.callbacks import CallbackManagerForToolRun
|
from langchain_core.callbacks import CallbackManagerForToolRun
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from langchain_community.tools.office365.base import O365BaseTool
|
from langchain_community.tools.office365.base import O365BaseTool
|
||||||
from langchain_community.tools.office365.utils import UTC_FORMAT
|
from langchain_community.tools.office365.utils import UTC_FORMAT
|
||||||
@ -73,12 +74,22 @@ class O365SendEvent(O365BaseTool): # type: ignore[override, override]
|
|||||||
|
|
||||||
event.body = body
|
event.body = body
|
||||||
event.subject = subject
|
event.subject = subject
|
||||||
|
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)
|
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)
|
event.end = dt.strptime(end_datetime, UTC_FORMAT)
|
||||||
|
|
||||||
for attendee in attendees:
|
for attendee in attendees:
|
||||||
event.attendees.add(attendee)
|
event.attendees.add(attendee)
|
||||||
|
|
||||||
# TO-DO: Look into PytzUsageWarning
|
|
||||||
event.save()
|
event.save()
|
||||||
|
|
||||||
output = "Event sent: " + str(event)
|
output = "Event sent: " + str(event)
|
||||||
|
Loading…
Reference in New Issue
Block a user