File size: 964 Bytes
6d113c1
 
 
 
 
 
 
 
 
922f087
 
6d113c1
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from smolagents import Tool
from datetime import datetime
import pytz

class TimeZoneConversionTool(Tool):
    name = "timezone_converter"
    description = "Converts time between two time zones."
    inputs = {
        "time": {"type": "string", "description": "Time in 'YYYY-MM-DD HH:MM' format"},
        "from_timezone": {"type": "string", "description": "Original time zone (e.g., 'Africa/Kinshasa', 'Europe/Zurich')"},
        "to_timezone": {"type": "string", "description": "Target time zone (e.g., 'UTC', 'America/New_York')"}
    }
    output_type = "string"

    def forward(self, time: str, from_timezone: str, to_timezone: str):
        from_zone = pytz.timezone(from_timezone)
        to_zone = pytz.timezone(to_timezone)
        naive_time = datetime.strptime(time, "%Y-%m-%d %H:%M")
        local_time = from_zone.localize(naive_time)
        converted_time = local_time.astimezone(to_zone)
        return converted_time.strftime("%Y-%m-%d %H:%M")