Spaces:
Running
Running
File size: 643 Bytes
b2c1c67 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | """Current date and time tool with timezone support."""
import json
from datetime import datetime, timezone
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
async def run(tz: str = "UTC") -> str:
try:
zone = ZoneInfo(tz) if tz else timezone.utc
except ZoneInfoNotFoundError:
return json.dumps({"error": f"Unknown timezone: {tz}. Use IANA names like Asia/Kolkata."})
now = datetime.now(zone)
return json.dumps(
{
"timezone": str(zone),
"iso": now.isoformat(),
"date": now.strftime("%A, %B %d, %Y"),
"time": now.strftime("%H:%M:%S"),
}
)
|