05/06 Fix some notable and quality issues
This commit is contained in:
@@ -50,13 +50,20 @@ bp = Blueprint('scheduled_reports', __name__, url_prefix='/scheduled-reports')
|
||||
# ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
def _compute_next_send(frequency: str, from_dt: datetime = None) -> datetime:
|
||||
"""Return the next send datetime for a given frequency."""
|
||||
"""Return the next send datetime for a given frequency.
|
||||
|
||||
Monthly cadence always targets the 1st of the next month at 07:00.
|
||||
The December branch is required because datetime.replace(month=13)
|
||||
raises ValueError — incrementing the month directly is not safe in
|
||||
general, but targeting day=1 avoids the separate last-day-of-month
|
||||
(28/29/30/31) edge case that would affect mid-month scheduling.
|
||||
"""
|
||||
now = from_dt or now_eastern()
|
||||
if frequency == 'daily':
|
||||
return (now + timedelta(days=1)).replace(hour=7, minute=0, second=0, microsecond=0)
|
||||
if frequency == 'weekly':
|
||||
return (now + timedelta(weeks=1)).replace(hour=7, minute=0, second=0, microsecond=0)
|
||||
# monthly: first of next month
|
||||
# monthly: first of next month — December rolls over to Jan of next year.
|
||||
if now.month == 12:
|
||||
return now.replace(year=now.year + 1, month=1, day=1, hour=7, minute=0, second=0, microsecond=0)
|
||||
return now.replace(month=now.month + 1, day=1, hour=7, minute=0, second=0, microsecond=0)
|
||||
|
||||
Reference in New Issue
Block a user