Advertisement
DeaD_EyE

next_sunday without dateutil

Feb 2nd, 2022
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. from datetime import date, timedelta
  2.  
  3.  
  4. def next_sunday(today: date | None = None) -> date:
  5.     if today is None:
  6.         today = date.today()
  7.  
  8.     one_day = timedelta(days=1)
  9.  
  10.     if today.weekday() == 6:
  11.         today += one_day
  12.  
  13.     while today.weekday() != 6:
  14.         today += one_day
  15.  
  16.     return today
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement