m1969m commited on
Commit
eee392b
·
verified ·
1 Parent(s): 0bc0a05

Update app.py

Browse files

Added new tool called calculate_time_difference that calculates the time difference between two time, either in units of seconds, minutes or hours, as defined by the user.

Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -18,6 +18,36 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def calculate_time_difference(localtime1:str, localtime2:str, timeunit:str)-> str:
23
+ """A tool that calculates the time difference between two times using a given
24
+ timeunit (seconds, minutes, hours)
25
+ Args:
26
+ localtime1: local time in one timezone (format: %Y-%m-%d %H:%M:%S)
27
+ localtime2: local time in another timezone (format: %Y-%m-%d %H:%M:%S)
28
+ timeunit: time units, either seconds, minutes or hours
29
+ """
30
+ try:
31
+ start = datetime.datetime.strptime(localtime1, '%Y-%m-%d %H:%M:%S')
32
+ end = datetime.datetime.strptime(localtime2, '%Y-%m-%d %H:%M:%S')
33
+ difference = end - start
34
+
35
+ match timeunit:
36
+ case "seconds":
37
+ timediff = abs(difference.total_seconds())
38
+
39
+ case "minutes":
40
+ timediff = abs(difference.total_seconds()/60.0)
41
+
42
+ case "hours":
43
+ timediff = abs(difference.total_seconds()/60.0/60.0)
44
+
45
+ output_str = f"The time difference is {timediff} {timeunit}."
46
+
47
+ except Exception as e:
48
+ output_str = f"Error calculating the time difference': {str(e)}"
49
+ return output_str
50
+
51
  @tool
52
  def get_current_time_in_timezone(timezone: str) -> str:
53
  """A tool that fetches the current local time in a specified timezone.