Spaces:
Running
Running
from datetime import datetime | |
def format_time(time: dict) -> str: | |
""" | |
Format time dictionary to string. | |
:param time: Time dictionary with keys 'hours' and 'minutes'. | |
:return: Formatted time string in HH:MM format. | |
""" | |
if time.get("past"): | |
time = time.get("past") | |
hours = int(time["hours"]) | |
minutes = int(time["minutes"]) | |
return f"{hours:02d}:{minutes:02d}" | |
else: | |
hours = int(time["hours"]) | |
minutes = int(time["minutes"]) | |
return f"{hours:02d}:{minutes:02d}" | |
def get_weekday_name(date: datetime) -> tuple: | |
""" | |
Get the name of the weekday from its number. | |
:param weekday: Weekday number (0-6). | |
:return: Name of the weekday. | |
""" | |
vietnam_weekdays = { | |
0: "Thứ hai", | |
1: "Thứ ba", | |
2: "Thứ tư", | |
3: "Thứ năm", | |
4: "Thứ sáu", | |
5: "Thứ bảy", | |
6: "Chủ nhật" | |
} | |
weekday_ids = date.weekday() | |
weekday = vietnam_weekdays.get(weekday_ids) if vietnam_weekdays.get(weekday_ids) else "" | |
return date.strftime("%d-%m-%Y"), weekday |