import datetime
from dateutil.relativedelta import relativedelta
from asgiref.sync import sync_to_async
from api.models import TradingDate


def latest_week(date):
    return date - relativedelta(date)


async def last_tradingday_of_last_week(date: datetime.date):
    """上周最后一个交易日"""
    weekday = date.weekday()
    l_friday = date - relativedelta(days=weekday + 3)
    last = await sync_to_async(TradingDate.objects.filter(date__lte=
        l_friday).last)()
    return last.date


async def first_tradingday_of_this_week(date: datetime.date):
    """本周第一个交易日"""
    weekday = date.weekday()
    l_sunday = date - relativedelta(days=weekday + 1)
    first = await sync_to_async(TradingDate.objects.filter(date__gte=
        l_sunday).first)()
    return first.date

d81d99707bd5b32eb5efe05d6244a7c4b1ab4e71
<mask token>

<mask token>


def latest_week(date):
    return date - relativedelta(date)


<mask token>

<mask token>


def latest_week(date):
    return date - relativedelta(date)


async def last_tradingday_of_last_week(date: datetime.date):
    """上周最后一个交易日"""
    weekday = date.weekday()
    l_friday = date - relativedelta(days=weekday + 3)
    last = await sync_to_async(TradingDate.objects.filter(date__lte=
        l_friday).last)()
    return last.date


async def first_tradingday_of_this_week(date: datetime.date):
    """本周第一个交易日"""
    weekday = date.weekday()
    l_sunday = date - relativedelta(days=weekday + 1)
    first = await sync_to_async(TradingDate.objects.filter(date__gte=
        l_sunday).first)()
    return first.date

import datetime
from dateutil.relativedelta import relativedelta
from asgiref.sync import sync_to_async
from api.models import TradingDate


def latest_week(date):
    return date - relativedelta(date)


async def last_tradingday_of_last_week(date: datetime.date):
    """上周最后一个交易日"""
    weekday = date.weekday()
    l_friday = date - relativedelta(days=weekday + 3)
    last = await sync_to_async(TradingDate.objects.filter(date__lte=
        l_friday).last)()
    return last.date


async def first_tradingday_of_this_week(date: datetime.date):
    """本周第一个交易日"""
    weekday = date.weekday()
    l_sunday = date - relativedelta(days=weekday + 1)
    first = await sync_to_async(TradingDate.objects.filter(date__gte=
        l_sunday).first)()
    return first.date
