-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.py
36 lines (25 loc) · 906 Bytes
/
utils.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
import time
from datetime import datetime, timedelta
from sys import platform
def non_zero_padded_prefix():
"""Returns the platform specific prefix for the non-zero-padded numbers."""
prefix = "-"
if platform.startswith("win32"):
prefix = "#"
return prefix
def get_last_month():
now = datetime.now()
last_month = now - timedelta(weeks=4)
return last_month.strftime(f"%{non_zero_padded_prefix()}m %Y")
def get_last_day():
now = datetime.now()
last_day = now - timedelta(days=1)
return last_day.strftime(f"%d/%{non_zero_padded_prefix()}m/%Y")
def get_readable_month(unix_t):
t = time.localtime(unix_t)
# Format: '9, 2021'
return time.strftime(f"%{non_zero_padded_prefix()}m %Y", t)
def get_readable_day(unix_t):
t = time.localtime(unix_t)
# Format: '03/12/2021'
return time.strftime(f"%d/%{non_zero_padded_prefix()}m/%Y", t)