fork download
  1. from datetime import datetime, timedelta
  2.  
  3. def generate_delivery_interval(min_days=1, max_days=14, skip_weekends=True):
  4. start = datetime.now()
  5.  
  6. # Calculate minimum delivery date (starting tomorrow)
  7. min_date = start + timedelta(days=min_days)
  8.  
  9. # Calculate maximum delivery date
  10. max_date = start
  11. if skip_weekends:
  12. days_added = 0
  13. while days_added < max_days:
  14. max_date += timedelta(days=1)
  15. if max_date.isoweekday() < 6: # Monday=1, Sunday=7
  16. days_added += 1
  17. else:
  18. max_date += timedelta(days=max_days)
  19.  
  20. # Format dates - show day and date
  21. min_formatted = min_date.strftime('%a, %-d') # Thu, 27
  22. max_formatted = max_date.strftime('%a, %b %-d') # Thu, Sep 9
  23.  
  24. return f"Est. delivery {min_formatted} - {max_formatted}"
  25.  
  26. # Test the function
  27. print(generate_delivery_interval())
  28.  
Success #stdin #stdout 0.07s 14036KB
stdin
Standard input is empty
stdout
Est. delivery Wed, 27 - Mon, Sep 15