-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty.py
52 lines (34 loc) · 1.29 KB
/
pretty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from datetime import datetime
def pretty_temp(f):
return "{0:.0f}°".format(f)
def pretty_length(inches):
if inches == 0:
return None
return '{0:0.2f}"'.format(inches)
def pretty_date_str(dt):
return dt.strftime('%m/%d/%Y %I:%M:%S %p')
def pretty_date_only_str(dt):
return dt.strftime('%m/%d/%Y')
def pretty_time_str(dt):
return dt.strftime(f'%I:%M:%S %p')
def pretty_time_str_short(dt):
return dt.strftime(f'%I %p')
def pretty_weekday(dt):
return ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][dt.weekday()]
def pretty_time_of_day(dt, is_today=False):
hour = dt.hour
if hour < 6:
return 'early this morning' if is_today else 'early morning'
elif hour < 12:
return 'this morning' if is_today else 'morning'
elif hour < 18:
return 'this afternoon' if is_today else 'afternoon'
elif hour < 21:
return 'this evening' if is_today else 'evening'
else:
return 'tonight' if is_today else 'night'
def pretty_relative_datetime(dt):
day_str = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][dt.weekday()]
if dt.weekday() == datetime.now().weekday():
return pretty_time_of_day(dt, True)
return f'{day_str} {pretty_time_of_day(dt)}'