DeaD_EyE

next_sunday with dateutil

Feb 2nd, 2022 (edited)
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. from datetime import date, timedelta
  2.  
  3. from dateutil.rrule import SU, WEEKLY, rrule
  4.  
  5.  
  6. def next_sunday(today: date | None = None) -> date:
  7.     if today is None:
  8.         today = date.today()
  9.  
  10.     if today.weekday() == SU.weekday:
  11.         today += timedelta(days=1)
  12.  
  13.     return rrule(freq=WEEKLY, dtstart=today, byweekday=SU)[0]
  14.  
Add Comment
Please, Sign In to add comment