Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,37 +30,30 @@ def calculate_time_lag(timezone1:str, timezone2:int)-> str: #it's import to spec
|
|
30 |
# 시간 차이 (timezone1 기준에서 얼마나 차이 나는지)
|
31 |
time_diff = tz1_local - tz2_local
|
32 |
|
33 |
-
#
|
34 |
diff_hours = time_diff.total_seconds() // 3600
|
35 |
diff_minutes = (time_diff.total_seconds() % 3600) // 60
|
36 |
|
37 |
-
#
|
38 |
abs_hours = abs(diff_hours)
|
39 |
abs_minutes = abs(diff_minutes)
|
40 |
|
|
|
41 |
if time_diff.total_seconds() == 0:
|
42 |
-
|
43 |
-
return (f"현재 {timezone1}와(과) {timezone2}는 시차가 없습니다. "
|
44 |
-
f"(동일한 시각)")
|
45 |
elif time_diff.total_seconds() > 0:
|
46 |
-
|
47 |
-
if abs_minutes == 0:
|
48 |
-
return (f"{timezone2}는 {timezone1} 기준으로 "
|
49 |
-
f"{int(abs_hours)}시간 늦습니다.")
|
50 |
-
else:
|
51 |
-
return (f"{timezone2}는 {timezone1} 기준으로 "
|
52 |
-
f"{int(abs_hours)}시간 {int(abs_minutes)}분 늦습니다.")
|
53 |
else:
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
return (f"{timezone2}는 {timezone1} 기준으로 "
|
60 |
-
f"{int(abs_hours)}시간 {int(abs_minutes)}분 빠릅니다.")
|
61 |
except Exception as e:
|
62 |
return f"Error calculating time difference: {str(e)}"
|
63 |
|
|
|
|
|
64 |
@tool
|
65 |
def get_current_time_in_timezone(timezone: str) -> str:
|
66 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
30 |
# 시간 차이 (timezone1 기준에서 얼마나 차이 나는지)
|
31 |
time_diff = tz1_local - tz2_local
|
32 |
|
33 |
+
# 시, 분 단위로 변환
|
34 |
diff_hours = time_diff.total_seconds() // 3600
|
35 |
diff_minutes = (time_diff.total_seconds() % 3600) // 60
|
36 |
|
37 |
+
# 절대값을 사용해 양수로 변환, 나중에 양/음 부호를 붙이는 방식
|
38 |
abs_hours = abs(diff_hours)
|
39 |
abs_minutes = abs(diff_minutes)
|
40 |
|
41 |
+
# 앞선 타임존(+)인지 뒤선 타임존(-)인지 결정
|
42 |
if time_diff.total_seconds() == 0:
|
43 |
+
return f"Time difference between {timezone1} and {timezone2} is 0 hours; they have the same current local time!"
|
|
|
|
|
44 |
elif time_diff.total_seconds() > 0:
|
45 |
+
sign = "+"
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
else:
|
47 |
+
sign = "-"
|
48 |
+
|
49 |
+
return (f"Current time in {timezone1} is {tz1_local.strftime('%Y-%m-%d %H:%M:%S')}, "
|
50 |
+
f"and in {timezone2} is {tz2_local.strftime('%Y-%m-%d %H:%M:%S')}. "
|
51 |
+
f"\nTime difference (timezone1 - timezone2) = {sign}{int(abs_hours)} hours {int(abs_minutes)} minutes.")
|
|
|
|
|
52 |
except Exception as e:
|
53 |
return f"Error calculating time difference: {str(e)}"
|
54 |
|
55 |
+
|
56 |
+
|
57 |
@tool
|
58 |
def get_current_time_in_timezone(timezone: str) -> str:
|
59 |
"""A tool that fetches the current local time in a specified timezone.
|