update
This commit is contained in:
@@ -38,13 +38,18 @@ def explicit_relative_period(message: str):
|
||||
patterns={
|
||||
'this_year':r'今年|本年度|本年',
|
||||
'last_year':r'去年|上年度',
|
||||
'next_year':r'明年|下年度',
|
||||
'this_quarter':r'这个季度|本季度|这季度|本季(?!度)',
|
||||
'last_quarter':r'上个季度|上季度|上季(?!度)',
|
||||
'next_quarter':r'下个季度|下季度|下季(?!度)',
|
||||
'this_month':r'这个月|本月|这月',
|
||||
'last_month':r'上个月|上月',
|
||||
'next_month':r'下个月|下月',
|
||||
'last_week':r'(?:上周|上星期|上礼拜)(?![一二三四五六日天]|周[一二三四五六日天])',
|
||||
'next_week':r'(?:下周|下星期|下礼拜)(?![一二三四五六日天]|周[一二三四五六日天])',
|
||||
'this_week':r'(?:本周|这周|本星期)(?![一二三四五六日天]|周[一二三四五六日天])',
|
||||
'today':r'今天|今日', 'yesterday':r'昨天|昨日', 'tomorrow':r'明天|明日',
|
||||
'day_after_tomorrow':r'后天|后日',
|
||||
'recent_7_days':r'(?:最近|近)(?:七|7)天',
|
||||
}
|
||||
matches=[(key,m.group()) for key,pattern in patterns.items() for m in re.finditer(pattern,message)]
|
||||
@@ -63,6 +68,10 @@ def calendar_context(today: date | str) -> dict:
|
||||
quarter_end = date(today.year, quarter_month + 2, monthrange(today.year, quarter_month + 2)[1])
|
||||
last_quarter_end = quarter_start - timedelta(days=1)
|
||||
last_month_end = today.replace(day=1) - timedelta(days=1)
|
||||
next_month_start = today.replace(day=monthrange(today.year, today.month)[1]) + timedelta(days=1)
|
||||
next_quarter_start = quarter_end + timedelta(days=1)
|
||||
next_quarter_end = date(next_quarter_start.year, next_quarter_start.month + 2,
|
||||
monthrange(next_quarter_start.year, next_quarter_start.month + 2)[1])
|
||||
|
||||
def period(first, last):
|
||||
return {"date_from": first.isoformat(), "date_to": last.isoformat()}
|
||||
@@ -70,17 +79,22 @@ def calendar_context(today: date | str) -> dict:
|
||||
return {
|
||||
"today": today.isoformat(), "yesterday": (today - timedelta(days=1)).isoformat(),
|
||||
"tomorrow": (today + timedelta(days=1)).isoformat(),
|
||||
"day_after_tomorrow": (today + timedelta(days=2)).isoformat(),
|
||||
"recent_7_days": period(today - timedelta(days=6), today),
|
||||
"this_week": period(monday, monday + timedelta(days=6)),
|
||||
"this_week_to_date": period(monday, today),
|
||||
"last_week": period(monday - timedelta(days=7), monday - timedelta(days=1)),
|
||||
"next_week": period(monday + timedelta(days=7), monday + timedelta(days=13)),
|
||||
"this_month_to_date": period(today.replace(day=1), today),
|
||||
"this_month": period(today.replace(day=1), today.replace(day=monthrange(today.year,today.month)[1])),
|
||||
"last_month": period(last_month_end.replace(day=1), last_month_end),
|
||||
"next_month": period(next_month_start, next_month_start.replace(day=monthrange(next_month_start.year, next_month_start.month)[1])),
|
||||
"this_quarter": period(quarter_start, quarter_end),
|
||||
"last_quarter": period(date(last_quarter_end.year, (last_quarter_end.month-1)//3*3+1, 1), last_quarter_end),
|
||||
"next_quarter": period(next_quarter_start, next_quarter_end),
|
||||
"this_quarter_to_date": period(quarter_start, today),
|
||||
"this_year": period(today.replace(month=1,day=1), today.replace(month=12,day=31)),
|
||||
"this_year_to_date": period(today.replace(month=1, day=1), today),
|
||||
"last_year": period(date(today.year - 1, 1, 1), date(today.year - 1, 12, 31)),
|
||||
"next_year": period(date(today.year + 1, 1, 1), date(today.year + 1, 12, 31)),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user