def format_time(hour_tuple):
"""
Convert to a 12hour time
"""
hour = hour_tuple[0]
duration = hour_tuple[1]
if hour is None:
return ''
elif isinstance(hour, datetime.time):
time = _parse_time_to_string(hour)
if duration:
end_hour = _add_minutes(hour, duration)
end_time = _parse_time_to_string(end_hour)
time = '%s - %s' % (time, end_time)
return time
else:
try:
if hour < 12:
return "%s AM" % str(hour)
elif hour == 12:
return "%s PM" % str(hour)
else:
return "%s PM" % str(hour - 12)
except ValueError:
return hour
评论列表
文章目录