tiinav commited on
Commit
6faecbd
·
verified ·
1 Parent(s): d7f6383

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -27,7 +27,7 @@ def calculate_time_difference_to_helsinki(local_time:datetime.datetime)-> str: #
27
  return f"Error fetching the time difference to Helsinki: {str(e)}"
28
 
29
  @tool
30
- def get_current_time_in_timezone(timezone: str) -> Union[str, datetime.datetime]:
31
  """A tool that fetches the current local time in a specified timezone.
32
  Args:
33
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
@@ -36,10 +36,24 @@ def get_current_time_in_timezone(timezone: str) -> Union[str, datetime.datetime]
36
  # Create timezone object
37
  tz = pytz.timezone(timezone)
38
  # Get current time in that timezone
39
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
40
- return f"The current local time in {timezone} is: {local_time}", local_time
41
  except Exception as e:
42
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
 
45
  final_answer = FinalAnswerTool()
 
27
  return f"Error fetching the time difference to Helsinki: {str(e)}"
28
 
29
  @tool
30
+ def get_current_time_in_timezone(timezone: str) -> datetime:
31
  """A tool that fetches the current local time in a specified timezone.
32
  Args:
33
  timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
36
  # Create timezone object
37
  tz = pytz.timezone(timezone)
38
  # Get current time in that timezone
39
+ local_time = datetime.datetime.now(tz)
40
+ return local_time
41
  except Exception as e:
42
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
43
+ @tool
44
+ def get_time_zone_string(local_time: datetime, timezone:str) -> str:
45
+ """A tool that converts the datetime obejct to a string format for a response to the user.
46
+ Args:
47
+ local_time: A datetime object of the local time zone
48
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
49
+ """
50
+ try:
51
+ local_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
52
+ return f"Local time in {timezone} is {local_time}
53
+ except Exception as e:
54
+ return f"Error converting '{local_time}' to string: {str(e)}"
55
+
56
+
57
 
58
 
59
  final_answer = FinalAnswerTool()