feat: 定时开始日改为每月5到25号,默认8号
This commit is contained in:
@@ -63,7 +63,7 @@ class Account(Base):
|
||||
proxy_port: Mapped[int | None] = mapped_column(nullable=True)
|
||||
proxy_username: Mapped[str] = mapped_column(String(128), nullable=False, default="", server_default="")
|
||||
proxy_password_cipher: Mapped[str] = mapped_column(Text, nullable=False, default="", server_default="")
|
||||
study_start_day: Mapped[int] = mapped_column(nullable=False, default=1, server_default="1")
|
||||
study_start_day: Mapped[int] = mapped_column(nullable=False, default=8, server_default="8")
|
||||
study_start_hour: Mapped[int] = mapped_column(nullable=False, default=0, server_default="0")
|
||||
study_start_minute: Mapped[int] = mapped_column(nullable=False, default=0, server_default="0")
|
||||
study_start_second: Mapped[int] = mapped_column(nullable=False, default=0, server_default="0")
|
||||
|
||||
@@ -6,6 +6,9 @@ import calendar
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
CN_TZ = timezone(timedelta(hours=8))
|
||||
DAY_MIN = 5
|
||||
DAY_MAX = 25
|
||||
DAY_DEFAULT = 8
|
||||
|
||||
|
||||
class StudyWindowError(ValueError):
|
||||
@@ -14,7 +17,7 @@ class StudyWindowError(ValueError):
|
||||
|
||||
def validate_start(day: object, hour: object, minute: object, second: object) -> tuple[int, int, int, int]:
|
||||
for name, value, low, high in (
|
||||
("日", day, 1, 31),
|
||||
("日", day, DAY_MIN, DAY_MAX),
|
||||
("时", hour, 0, 23),
|
||||
("分", minute, 0, 59),
|
||||
("秒", second, 0, 59),
|
||||
@@ -34,10 +37,22 @@ def _clamp_int(value: object, low: int, high: int, default: int) -> int:
|
||||
return min(high, max(low, number))
|
||||
|
||||
|
||||
def _stored_day(value: object) -> int:
|
||||
if isinstance(value, bool):
|
||||
return DAY_DEFAULT
|
||||
try:
|
||||
number = int(value) # type: ignore[arg-type]
|
||||
except (TypeError, ValueError):
|
||||
return DAY_DEFAULT
|
||||
if DAY_MIN <= number <= DAY_MAX:
|
||||
return number
|
||||
return DAY_DEFAULT
|
||||
|
||||
|
||||
def stored_start(account) -> tuple[int, int, int, int]:
|
||||
"""读取时把非法时刻收进合法范围,避免首页状态接口报错。"""
|
||||
return (
|
||||
_clamp_int(getattr(account, "study_start_day", 1), 1, 31, 1),
|
||||
_stored_day(getattr(account, "study_start_day", DAY_DEFAULT)),
|
||||
_clamp_int(getattr(account, "study_start_hour", 0), 0, 23, 0),
|
||||
_clamp_int(getattr(account, "study_start_minute", 0), 0, 59, 0),
|
||||
_clamp_int(getattr(account, "study_start_second", 0), 0, 59, 0),
|
||||
|
||||
Reference in New Issue
Block a user