Spaces:
Sleeping
Sleeping
Create agents/time_tool.py
Browse files- agents/time_tool.py +13 -0
agents/time_tool.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytz
|
| 2 |
+
import datetime
|
| 3 |
+
|
| 4 |
+
def get_the_current_time_in_timezone(timezone: str) -> str:
|
| 5 |
+
"""A tool that fetches the current local time in a specified timezone."""
|
| 6 |
+
try:
|
| 7 |
+
# Create timezone object
|
| 8 |
+
tz = pytz.timezone(timezone)
|
| 9 |
+
# Get current time in that timezone
|
| 10 |
+
local_time = datetime.datetime.now(tz).strftime("%I:%M %p") # %I for 12-hour clock, %M for minutes, %p for AM/PM
|
| 11 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|