gautam1222 commited on
Commit
4231693
·
verified ·
1 Parent(s): d948601

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -38
app.py CHANGED
@@ -72,44 +72,44 @@ def get_current_time_in_timezone(timezone: str) -> str:
72
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
73
 
74
 
75
- @tool
76
- def get_time_difference(time1: str, timezone1: str, time2: str, timezone2: str) -> str:
77
- """A tool that calculates the time difference between two timestamps in different time zones.
78
- Args:
79
- time1: First timestamp in "YYYY-MM-DD HH:MM:SS" format.
80
- timezone1: Time zone of the first timestamp (e.g., "America/New_York").
81
- time2: Second timestamp in "YYYY-MM-DD HH:MM:SS" format.
82
- timezone2: Time zone of the second timestamp (e.g., "Asia/Kolkata").
83
- Returns:
84
- str: Time difference as a human-readable string (e.g., "0 years, 0 months, 3 days, 4 hours, 2 minutes, 15 seconds").
85
- """
86
- try:
87
- # Convert input strings to timezone-aware datetime objects
88
- tz1 = pytz.timezone(timezone1)
89
- tz2 = pytz.timezone(timezone2)
90
-
91
- dt1 = tz1.localize(datetime.datetime.strptime(time1, "%Y-%m-%d %H:%M:%S"))
92
- dt2 = tz2.localize(datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S"))
93
-
94
- # Calculate absolute difference
95
- if dt1 > dt2:
96
- dt1, dt2 = dt2, dt1 # Ensure dt1 is earlier for proper calculations
97
-
98
- diff = relativedelta(dt2, dt1)
99
-
100
- # Convert difference to human-readable format
101
- result = []
102
- if diff.years: result.append(f"{diff.years} years")
103
- if diff.months: result.append(f"{diff.months} months")
104
- if diff.days: result.append(f"{diff.days} days")
105
- if diff.hours: result.append(f"{diff.hours} hours")
106
- if diff.minutes: result.append(f"{diff.minutes} minutes")
107
- if diff.seconds: result.append(f"{diff.seconds} seconds")
108
-
109
- return ", ".join(result) if result else "0 seconds"
110
-
111
- except Exception as e:
112
- return f"Error calculating time difference: {str(e)}"
113
 
114
 
115
 
 
72
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
73
 
74
 
75
+ # @tool
76
+ # def get_time_difference(time1: str, timezone1: str, time2: str, timezone2: str) -> str:
77
+ # """A tool that calculates the time difference between two timestamps in different time zones.
78
+ # Args:
79
+ # time1: First timestamp in "YYYY-MM-DD HH:MM:SS" format.
80
+ # timezone1: Time zone of the first timestamp (e.g., "America/New_York").
81
+ # time2: Second timestamp in "YYYY-MM-DD HH:MM:SS" format.
82
+ # timezone2: Time zone of the second timestamp (e.g., "Asia/Kolkata").
83
+ # Returns:
84
+ # str: Time difference as a human-readable string (e.g., "0 years, 0 months, 3 days, 4 hours, 2 minutes, 15 seconds").
85
+ # """
86
+ # try:
87
+ # # Convert input strings to timezone-aware datetime objects
88
+ # tz1 = pytz.timezone(timezone1)
89
+ # tz2 = pytz.timezone(timezone2)
90
+
91
+ # dt1 = tz1.localize(datetime.datetime.strptime(time1, "%Y-%m-%d %H:%M:%S"))
92
+ # dt2 = tz2.localize(datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S"))
93
+
94
+ # # Calculate absolute difference
95
+ # if dt1 > dt2:
96
+ # dt1, dt2 = dt2, dt1 # Ensure dt1 is earlier for proper calculations
97
+
98
+ # diff = relativedelta(dt2, dt1)
99
+
100
+ # # Convert difference to human-readable format
101
+ # result = []
102
+ # if diff.years: result.append(f"{diff.years} years")
103
+ # if diff.months: result.append(f"{diff.months} months")
104
+ # if diff.days: result.append(f"{diff.days} days")
105
+ # if diff.hours: result.append(f"{diff.hours} hours")
106
+ # if diff.minutes: result.append(f"{diff.minutes} minutes")
107
+ # if diff.seconds: result.append(f"{diff.seconds} seconds")
108
+
109
+ # return ", ".join(result) if result else "0 seconds"
110
+
111
+ # except Exception as e:
112
+ # return f"Error calculating time difference: {str(e)}"
113
 
114
 
115