wanda222 commited on
Commit
9133642
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -18,6 +18,60 @@ 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
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
22
+ @tool
23
+ def calculate_time_lag(timezone1:str, timezone2:int)-> str: #it's import to specify the return type
24
+ """
25
+ A tool that calculates the time lag between two timezones based on their current local times.
26
+ Args:
27
+ timezone1: A string representing the first timezone (e.g., 'Asia/Seoul').
28
+ timezone2: A string representing the second timezone (e.g., 'America/New_York').
29
+ Returns:
30
+ A string describing the time difference in hours and minutes.
31
+ """
32
+ try:
33
+ now_utc = datetime.datetime.now(datetime.timezone.utc)
34
+
35
+ tz1 = pytz.timezone(timezone1)
36
+ tz1_local = now_utc.astimezone(tz1)
37
+
38
+ tz2 = pytz.timezone(timezone2)
39
+ tz2_local = now_utc.astimezone(tz2)
40
+
41
+ # 시간 차이 (timezone1 기준에서 얼마나 차이 나는지)
42
+ time_diff = tz1_local - tz2_local
43
+
44
+ # 시/분 단위로 계산
45
+ diff_hours = time_diff.total_seconds() // 3600
46
+ diff_minutes = (time_diff.total_seconds() % 3600) // 60
47
+
48
+ # 절댓값 계산
49
+ abs_hours = abs(diff_hours)
50
+ abs_minutes = abs(diff_minutes)
51
+
52
+ if time_diff.total_seconds() == 0:
53
+ # 완전히 동일할 수도 있음
54
+ return (f"현재 {timezone1}와(과) {timezone2}는 시차가 없습니다. "
55
+ f"(동일한 시각)")
56
+ elif time_diff.total_seconds() > 0:
57
+ # time_diff > 0 이면 timezone2가 timezone1보다 느림(뒤쳐짐)
58
+ if abs_minutes == 0:
59
+ return (f"{timezone2}는 {timezone1} 기준으로 "
60
+ f"{int(abs_hours)}시간 늦습니다.")
61
+ else:
62
+ return (f"{timezone2}는 {timezone1} 기준으로 "
63
+ f"{int(abs_hours)}시간 {int(abs_minutes)}분 늦습니다.")
64
+ else:
65
+ # time_diff < 0 이면 timezone2가 timezone1보다 빠름
66
+ if abs_minutes == 0:
67
+ return (f"{timezone2}는 {timezone1} 기준으로 "
68
+ f"{int(abs_hours)}시간 빠릅니다.")
69
+ else:
70
+ return (f"{timezone2}는 {timezone1} 기준으로 "
71
+ f"{int(abs_hours)}시간 {int(abs_minutes)}분 빠릅니다.")
72
+ except Exception as e:
73
+ return f"Error calculating time difference: {str(e)}"
74
+
75
  @tool
76
  def get_current_time_in_timezone(timezone: str) -> str:
77
  """A tool that fetches the current local time in a specified timezone.