-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
24 lines (22 loc) · 927 Bytes
/
utils.py
File metadata and controls
24 lines (22 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from datetime import datetime, timedelta
def parse_period(period):
"""Parse a period string and return the corresponding datetime."""
now = datetime.now()
if period == "today":
return now.replace(hour=0, minute=0, second=0, microsecond=0)
elif period == "yesterday":
yesterday = now - timedelta(days=1)
return yesterday.replace(hour=0, minute=0, second=0, microsecond=0)
elif period == "this week":
# Start of current week (Monday)
days_since_monday = now.weekday()
start_of_week = now - timedelta(days=days_since_monday)
return start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
elif period == "15 days":
return now - timedelta(days=15)
elif period == "a month":
return now - timedelta(days=30)
elif period == "all":
return "all"
else:
raise ValueError(f"Unknown period: {period}")