""" Date and time utility functions. """ from datetime import datetime, timedelta def get_start_of_week(dt: datetime = None) -> datetime: """ Get the start of the week (Monday) for a given date. Args: dt: The date to get the start of the week for. Defaults to current date. Returns: Datetime representing the start of the week """ dt = dt or datetime.now() return dt - timedelta(days=dt.weekday()) def get_end_of_week(dt: datetime = None) -> datetime: """ Get the end of the week (Sunday) for a given date. Args: dt: The date to get the end of the week for. Defaults to current date. Returns: Datetime representing the end of the week """ dt = dt or datetime.now() return get_start_of_week(dt) + timedelta(days=6) def get_previous_week_range() -> tuple[datetime, datetime]: """ Get the date range for the previous week. Returns: Tuple of (start_date, end_date) for the previous week """ today = datetime.now() # Go back to the previous week previous_week = today - timedelta(days=7) start_date = get_start_of_week(previous_week) end_date = get_end_of_week(previous_week) return start_date, end_date